unity Editor

发布时间 2023-08-03 08:58:40作者: Allenx1
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using WT_LZY;

[CustomEditor(typeof(ProcedureBase))]
[CanEditMultipleObjects]
public class ProcedureBaseEditor : Editor
{
    SerializedProperty mProcedureBase;
    //private SerializedObject obj;
    void OnEnable()
    {
        mProcedureBase = serializedObject.FindProperty("ProcedureBase");
    }
   
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        serializedObject.Update();
       
        EditorGUI.BeginChangeCheck();
        ProcedureBase pobj=target as ProcedureBase;
       
        if (GUILayout.Button("更新stepID"))
        {
            StepBase[] stepBases= pobj.GetComponentsInChildren<StepBase>();
            foreach (StepBase _stepBase in stepBases)
            {
                _stepBase.StepId = _stepBase.transform.GetSiblingIndex();
                string[] strs= _stepBase.gameObject.name.Split('.');
                _stepBase.gameObject.name= _stepBase.StepId.ToString() + "." + strs[1];
            }
            Debug.Log("It's alive: " + target.name);
        }
        if(EditorGUI.EndChangeCheck() && !EditorUtility.IsDirty(target))
            EditorUtility.SetDirty(target);
         
    }
}