Untiy开发脚本

1、Inspector面板用代码控制Lock

1 Type t = typeof( UnityEditor.EditorWindow ).Assembly.GetType("UnityEditor.InspectorWindow");
2 var window = UnityEditor.EditorWindow.GetWindow(t);
3 var log = (bool)t.GetProperty("isLocked").GetValue(window);
4 if (!log)
5   {
6        t.GetProperty("isLocked").SetValue(window, true);
7        Debug.Log(YTools.ColorText("为方便添加路径点,Inspector面板已锁定"));
8   }

2、Inspector打开属性面板

[CustomEditor(typeof( UTweenPath3D ))]
public class UTweenPath3DEditor : OdinEditor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("打开面板"))
        {
            EditorUtility.OpenPropertyEditor(target);
        }
    }
}

3、在编辑器不运行模式下调试动画(使用协程)

#if UNITY_EDITOR
  [Button("测试动画")]
    void TestPath()
    {
        Unity.EditorCoroutines.Editor.EditorCoroutineUtility.StartCoroutineOwnerless(PathAnim());
    }

    IEnumerator PathAnim()
    {
        float timer = 0;
        int dur = 3;
        Vector3 startPos = transform.position;
        while (timer <= dur)
        {
            float t = timer / dur;
            transform.position = Vector3.Lerp(startPos, pos, t);
            yield return null;
            timer += Time.deltaTime;
        }
    }
#endif

 

posted on 2023-06-30 11:24  yungs  阅读(35)  评论(0编辑  收藏  举报