Unity重写Inspector简化分组配置文件
- 重写Inspector创建分组管理配置文件
- 创建
- 修改参数
- 参数对应类
- 工程在我的资源中名为CreateConfig,免费下载
重写Inspector创建分组管理配置文件
创建
修改参数
参数对应类
using UnityEngine;public class GameConfig : ScriptableObject {/// <summary>/// float参数/// </summary>public float test_float = 10f;/// <summary>/// vector3参数/// </summary>public Vector3 test_vector3 = Vector3.zero;/// <summary>/// bool参数/// </summary>public bool test_bool = false;/// <summary>/// int参数/// </summary>public int test_int = 1;/// <summary>/// slider参数/// </summary>public float test_slider = 0.1f;/// <summary>/// text参数/// </summary>public string test_text = "";/// <summary>/// toggle参数/// </summary>public bool test_toggle = false;
}
using System;
using UnityEditor;
using UnityEngine;[CustomEditor(typeof(GameConfig))]
public class GameConfigInspector : HKBaseEditor {/// <summary>/// 配置表/// </summary>private GameConfig config;private string[] MenuItems = new string[] { "Save" };/// <summary>/// 绘制/// </summary>public override void OnInspectorGUI(){//base.OnInspectorGUI(); //如果需要分组配置需将其注释config = (GameConfig)target;AddToolBar(MenuItems, OnEventSave);HKContentBlock.DrawContent("配置测试1", () =>{//配置1HKEditorHelper.DrawFloatFieldLayout("float参数", ref config.test_float);HKEditorHelper.DrawVector3Layout("float参数", ref config.test_vector3);HKEditorHelper.DrawSliderLayout("slider参数", ref config.test_slider);HKEditorHelper.DrawToggleLayout("toggle参数", ref config.test_toggle);});HKContentBlock.DrawContent("配置测试2", () =>{config.test_bool = HKEditorHelper.DrawBoolLayout("bool参数", config.test_bool);config.test_int = HKEditorHelper.DrawIntFieldLayout("int参数", config.test_int);config.test_text = HKEditorHelper.DrawTextFiledLayout("text参数", config.test_text);});}/// <summary>/// 保存/// </summary>private void OnEventSave(){EditorUtility.SetDirty(config);AssetDatabase.SaveAssets();}[MenuItem("ETools/CreateGameConfig")]public static void Create(){CreateAsset<GameConfig>("Assets/Resources/GameConfig.asset");}
}