private RegisterToLuaObjectArr OnDrawRegisterLuaObjectArr(object obj, Type t) { if (obj == null) { obj = new RegisterToLuaObjectArr(); } RegisterToLuaObjectArr luaObjArr = obj as RegisterToLuaObjectArr; EditorGUILayout.BeginVertical(); { luaObjArr.name = EditorGUILayout.TextField("Name:", luaObjArr.name); if (string.IsNullOrEmpty(luaObjArr.name)) { EditorGUILayout.HelpBox("注册Object名称不能为空", MessageType.Error); } if (!string.IsNullOrEmpty(luaObjArr.name) && !Regex.IsMatch(luaObjArr.name, nameReg)) { EditorGUILayout.HelpBox("注册Object名称只能以小写字母开关,只能包括A-Z,a-z,0-9的字符", MessageType.Error); } List <RegisterToLuaObject> childs = new List <RegisterToLuaObject>(); if (luaObjArr.luaObjects != null && luaObjArr.luaObjects.Length > 0) { childs.AddRange(luaObjArr.luaObjects); } GTEditorGUI.DrawObjectListEditor <RegisterToLuaObject>("Register Lua Object:", childs, ref luaObjArr.isFoldout, OnDrawRegisterLuaObjectInArr, Color.green); luaObjArr.luaObjects = childs.ToArray(); if (!string.IsNullOrEmpty(luaObjArr.name)) { bool isNameRepeat = false; foreach (RegisterToLuaObjectArr rtloa in luaObjArrList) { if (rtloa != null && rtloa != luaObjArr && rtloa.name == luaObjArr.name && !string.IsNullOrEmpty(luaObjArr.name)) { isNameRepeat = true; } } if (isNameRepeat) { EditorGUILayout.HelpBox("注册luaObjectArr名称重复", MessageType.Error); } } } EditorGUILayout.EndVertical(); return(luaObjArr); }
public override void OnInspectorGUI() { EditorGUI.BeginDisabledGroup(true); { EditorGUILayout.ObjectField("Script:", monoScript, typeof(MonoScript), false); } EditorGUI.EndDisabledGroup(); TextAsset luaScriptText = null; if (!string.IsNullOrEmpty(scriptAssetPath)) { luaScriptText = (TextAsset)AssetDatabase.LoadAssetAtPath(scriptAssetPath, typeof(TextAsset)); if (luaScriptText == null) { scriptAssetPath = ""; } } TextAsset ta = (TextAsset)EditorGUILayout.ObjectField("Lua Script:", luaScriptText, typeof(TextAsset), false); if (ta == null) { if (!string.IsNullOrEmpty(behaviour.scriptShortPath)) { behaviour.scriptShortPath = ""; behaviour.scriptName = ""; } scriptAssetPath = ""; } else { string taPath = AssetDatabase.GetAssetPath(ta.GetInstanceID()).Replace("\\", "/"); if (taPath != scriptAssetPath && taPath.IndexOf(LuaScriptPathDir) >= 0) { scriptAssetPath = taPath; behaviour.scriptShortPath = scriptAssetPath.Replace(LuaScriptPathDir, ""); behaviour.scriptName = Path.GetFileNameWithoutExtension(scriptAssetPath); } } GTEditorGUI.DrawObjectListEditor <RegisterToLuaObject>("Register Lua Object:", luaObjList, ref isLuaObjFoldout, OnDrawRegisterLuaObject, Color.red); EditorGUILayout.Space(); GTEditorGUI.DrawObjectListEditor <RegisterToLuaObjectArr>("Register Lua Object Arr:", luaObjArrList, ref isLuaObjArrFoldout, OnDrawRegisterLuaObjectArr, Color.red); EditorGUILayout.Space(); GTEditorGUI.DrawObjectListEditor <RegisterToLuaBehaviour>("Register Lua Behaviour:", luaBehList, ref isLuaBehFoldout, OnDrawRegisterLuaBehaviour, Color.red); EditorGUILayout.Space(); GTEditorGUI.DrawObjectListEditor <RegisterToLuaBehaviourArr>("Register Lua Behaviour Arr:", luaBehArrList, ref isLuaBehArrFoldout, OnDrawRegisterLuaBehaviourArr, Color.red); if (GUI.changed) { behaviour.regLuaObject = luaObjList.ToArray(); behaviour.regLuaObjectArr = luaObjArrList.ToArray(); behaviour.regLuaBehaviour = luaBehList.ToArray(); behaviour.regLuaBehaviourArr = luaBehArrList.ToArray(); } }