34 lines
980 B
C#
34 lines
980 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using MonKey;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit.GameEditor
|
|
{
|
|
public class QuickFixFloatModel
|
|
{
|
|
[Command(nameof(FixedSelectedFloat), "Fixed Selected Model Position", QuickName = "ins"), MenuItem("Tools/Scenes/Fix Float Model Position")]
|
|
public static void FixedSelectedFloat()
|
|
{
|
|
var transforms = UnityEditor.Selection.transforms;
|
|
if (transforms is null or {Length:0}) return;
|
|
|
|
var reportBuilder = new StringBuilder();
|
|
reportBuilder.AppendLine($"已选择{transforms.Length}个物体:");
|
|
foreach (var x in transforms)
|
|
{
|
|
if (UnityEngine.Physics.Raycast(x.position, Vector3.down, out var hit, 1000) is false) continue;
|
|
x.position = hit.point;
|
|
EditorUtility.SetDirty(x);
|
|
reportBuilder.AppendLine($"已修复{x.name}的位置于{hit.point}");
|
|
}
|
|
Undo.RecordObjects(transforms,"修复浮动");
|
|
|
|
Debug.Log(reportBuilder);
|
|
}
|
|
}
|
|
|
|
}
|