unity Editor

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);
         
    }
}
 
 
 
1.特点:
  1.针对某个类型inspector 面板Gui 扩展
  2. 获取当前脚本对象
    1.使用serializedObject
    2.target 强制转换

__EOF__

本文作者leader755
本文链接https://www.cnblogs.com/AllXzp/p/17602352.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   Allenx1  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示