public override void OnInspectorGUI() { m_script = target as ClientDataBaseConfig; GUILayout.Space(15); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Check", EditorStyles.boldLabel); m_script.gameTableCheck = DrawNormalField("Game Table Check", m_script.gameTableCheck); EditorGUILayout.EndVertical(); GUILayout.Space(15); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Path", EditorStyles.boldLabel); m_script.root = DrawNormalField("ROOT", m_script.root); m_script.pathScriptTemplates = DrawPathField("Script Templates Path", m_script.pathScriptTemplates); m_script.pathGameTable = DrawPathField("Game Table Path", m_script.pathGameTable); m_script.pathTableClass = DrawPathField("Table Class Path", m_script.pathTableClass); m_script.pathScriptableAsset = DrawPathField("Scriptable Asset Path", m_script.pathScriptableAsset); m_script.pathScriptableScripts = DrawPathField("Scriptable Scripts Path", m_script.pathScriptableScripts); m_script.pathScriptableEditor = DrawPathField("Scriptable Editor Path", m_script.pathScriptableEditor); EditorGUILayout.EndVertical(); GUILayout.Space(15); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Name", EditorStyles.boldLabel); m_script.nameClassPrefix = DrawNameField("Class Name Prefix", "Preview: " + m_script.nameClassPrefix + "[FileName]", m_script.nameClassPrefix); m_script.nameScriptableAssetSuffix = DrawNameField("Scriptable Asset Suffix", "Preview: " + m_script.nameClassPrefix + "[FileName]" + m_script.nameScriptableAssetSuffix, m_script.nameScriptableAssetSuffix); m_script.nameScriptableScriptSuffix = DrawNameField("Scriptable Script Suffix", "Preview: " + m_script.nameClassPrefix + "[FileName]" + m_script.nameScriptableScriptSuffix, m_script.nameScriptableScriptSuffix); m_script.nameScriptableEditorSuffix = DrawNameField("Scriptable Editor Suffix", "Preview: " + m_script.nameClassPrefix + "[FileName]" + m_script.nameScriptableEditorSuffix, m_script.nameScriptableEditorSuffix); EditorGUILayout.EndVertical(); EditorUtility.SetDirty(m_script); }
/// <summary> /// 建立 Scriptable Asset /// </summary> /// <returns>是否成功建立</returns> public bool CreateScriptableAssets(string scriptableScriptName, string scriptableAssetName) { m_config = ClientDataBaseManager.Instance.Config; MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(m_config.GetScriptableScriptsPath() + scriptableScriptName); if (script == null || script.GetClass() == null) { Debug.LogError(string.Format("Scriptable Script is Null. [Path:{0}]", m_config.GetScriptableScriptsPath() + scriptableScriptName)); return(false); } string path = m_config.GetScriptableAssetPath() + scriptableAssetName; ScriptableObjectBase scriptableObjectBase = AssetDatabase.LoadAssetAtPath <ScriptableObjectBase>(path); if (scriptableObjectBase == null) { UtilityEditor.CreateFolder(m_config.GetScriptableAssetPath()); scriptableObjectBase = ScriptableObject.CreateInstance(script.GetClass()) as ScriptableObjectBase; AssetDatabase.CreateAsset(scriptableObjectBase, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); } Debug.Log(string.Format("[Scriptable Asset] is Create.\nFile:[{0}] Path:[{1}]", scriptableAssetName, m_config.GetScriptableAssetPath())); return(scriptableObjectBase.LoadGameTable()); }
/// <summary> /// 讀取GameTable(.txt) /// </summary> public bool LoadGameTable(Object obj) { m_config = ClientDataBaseManager.Instance.Config; m_tableName = obj.name; string strTemp; string path = AssetDatabase.GetAssetPath(obj); string content = File.ReadAllText(path); TextReader reader = null; string[] _Export = null; string[] _Summary = null; string[] _Variable = null; string[] _Type = null; int index = 0; if (content == null) { Debug.LogError("GameTable is null."); return(false); } if (content == string.Empty) { Debug.LogError("GameTable is empty."); return(false); } reader = new StringReader(content); if (reader != null) { while ((strTemp = reader.ReadLine()) != null) { if (index == 0) { _Export = strTemp.Split("\t"[0]); index++; continue; } if (index == 1) { _Summary = strTemp.Split("\t"[0]); index++; continue; } if (index == 2) { _Variable = strTemp.Split("\t"[0]); index++; continue; } if (index == 3) { _Type = strTemp.Split("\t"[0]); index++; continue; } if (index == 4) { //1.判斷是否是 GameTable(txt),檔案的開始字串是否包含 識別字 if (_Export[0].IndexOf(m_config.gameTableCheck) < 0) { Debug.LogError("GameTable is not a table. Please Check txt file start string is [" + m_config.gameTableCheck + "]"); break; } //2.判斷欄位數量是否一致 int count = _Summary.Length; if (count != _Variable.Length || count != _Type.Length) { Debug.LogError("GameTable column not same."); break; } if (CreateTableScript(_Export, _Summary, _Variable, _Type) == false) { return(false); } if (CreateScriptableScript(_Export, _Variable, _Type) == false) { return(false); } if (CreateScriptableScriptEditor() == false) { return(false); } break; } } reader.Close(); } return(true); }