一、脚本对象可视化编辑(把数据以.asset文件的形式保存,可视化编辑方便形象。
UnityEditor相关功能
图片例子:

	/// <summary>
	/// 数据类
	/// </summary>
	[Serializable]
	public class ChildItem
	 {
   	 public string Name;

  	  public int ID;
  	  
	 //私有函数显示
   	 [SerializeField]
   	 private GameObject Role;
	}

	/// <summary>
	/// 继承ScriptableObject 可自定义资源配置文件
	/// </summary>
	public class Item : ScriptableObject
	{
    	public List<ChildItem> ItemList;
	}

	/// <summary>
	/// 创建.asset文件
	/// </summary>
    public static void CreatAssetItem()
    {
        Item items = ScriptableObject.CreateInstance<Item>();
        string path = "Assets/XML/Item.asset";
        AssetDatabase.CreateAsset(items, path);
        AssetDatabase.SaveAssets();
    }

二、自定义编辑窗口

/// <summary>
/// 窗口类
/// </summary>
public class MyWindowEditor : EditorWindow
{
    private static MyWindowEditor myWindowEditor;

    [MenuItem("GameObject/MyWindowEditor")]
    private static void CreateWindow()
    {
        //方法一  固定窗口大小,不可缩放
        //myWindowEditor = GetWindowWithRect<MyWindowEditor>(new Rect(0, 0, 200, 400), false, "我的窗口", true);

        //方法二  限制窗口最大最小值,可缩放
        myWindowEditor = GetWindow(typeof(MyWindowEditor), false, "我的窗口") as MyWindowEditor;
        myWindowEditor.minSize = new Vector2(200, 400);
        myWindowEditor.maxSize = new Vector2(400, 800);

        myWindowEditor.Show();
    }
}

void OnGUI()
{
	//OnGUI中编辑你的窗口内容
}

(注:设置打开窗口快捷键例:[MenuItem(“GameObject/MyWindowEditor %R”)],在窗口名后空格加快捷键方式。
%–Ctrl / CMD
#–Shift
&–Alt)

相关文章:

  • 2021-11-30
  • 2021-12-29
  • 2021-10-02
  • 2021-07-01
  • 2021-11-11
  • 2022-12-23
  • 2021-04-08
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2021-05-18
  • 2021-09-01
  • 2021-10-07
  • 2021-11-20
相关资源
相似解决方案