/// <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> /// 建立 Scriptable Script Editor /// </summary> /// <returns>是否成功建立</returns> bool CreateScriptableScriptEditor() { string templateScriptable = GetTemplate("ScriptableEditor"); if (string.IsNullOrEmpty(templateScriptable)) { return(false); } templateScriptable = templateScriptable.Replace("$ScriptableEditorName", m_config.GetScriptableScriptEditorName(m_tableName)); templateScriptable = templateScriptable.Replace("$ScriptableName", m_config.GetScriptableScriptName(m_tableName)); UtilityEditor.CreateFolder(m_config.GetScriptableEditorPath()); using (var writer = new StreamWriter(m_config.GetScriptableEditorPath() + m_config.GetScriptableScriptEditorName(m_tableName, true))) { writer.Write(templateScriptable); writer.Close(); } AssetDatabase.Refresh(); Debug.Log(string.Format("[Scriptable Script Editor] is Create.\nFile:[{0}] Path:[{1}]", m_config.GetScriptableScriptEditorName(m_tableName, true), m_config.GetScriptableEditorPath())); return(true); }
public static void UpdateAll() { ClientDataBaseEditorWindow window = EditorWindow.GetWindow <ClientDataBaseEditorWindow>(); window.m_objList = UtilityEditor.LoadAllAssetsAtPath(ClientDataBaseManager.Instance.Config.GetGameTablePath()).ToList(); if (window.m_objList.Count == 0) { Debug.Log("No GameTable file (.txt)"); window.Close(); return; } window.m_updateAll = true; window.m_startCreate = true; window.m_isExecuteButtonClick = true; }
void OnGUI() { m_btnStyle = new GUIStyle(GUI.skin.button); m_btnStyle.fontSize = 16; m_btnStyle.alignment = TextAnchor.MiddleLeft; //遮罩 if (m_startCreate) { GUI.enabled = false; } m_tabIndex = UtilityEditor.Tabs(m_types, m_tabIndex); GUILayout.Space(10); //還沒開始時才需要抓物件 if (m_startCreate == false && m_updateAll == false) { m_objList = Selection.objects.ToList(); } //排除 for (int i = m_objList.Count - 1; i >= 0; i--) { if (GetFiltered(m_objList[i])) { m_objList.Remove(m_objList[i]); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Choose GameTable Asset", EditorStyles.boldLabel, GUILayout.Width(200)); EditorGUILayout.LabelField("Count : " + m_objList.Count, EditorStyles.boldLabel, GUILayout.Width(100)); if (GUILayout.Button("Update All")) { UpdateAll(); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (m_objList.Count == 0) { EditorGUILayout.HelpBox(GetHelpString(), MessageType.Warning); return; } //字母排序 m_objList.Sort(delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); }); EditorGUILayout.BeginVertical(); m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, false, false); EditorGUILayout.Space(); foreach (Object go in m_objList) { if (GUILayout.Button(go.name, m_btnStyle)) { EditorGUIUtility.PingObject(go); } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); if (UtilityEditor.GetCommonButton(m_types[m_tabIndex])) { if (EditorApplication.isCompiling) { Debug.LogError("After wait application compiling then try again."); return; } m_startCreate = true; m_isExecuteButtonClick = true; } if (m_startCreate) { GUI.enabled = true; UtilityEditor.ShowLoading(); } }
/// <summary> /// 建立 Scriptable Script /// </summary> /// <returns>是否成功建立</returns> bool CreateScriptableScript(string[] export, string[] variable, string[] type) { string template = GetTemplate("Scriptable"); if (string.IsNullOrEmpty(template)) { return(false); } template = template.Replace("$ScriptableName", m_config.GetScriptableScriptName(m_tableName)); template = template.Replace("$GameTableName", m_tableName); template = template.Replace("$ClassName", m_config.GetTableClassScriptName(m_tableName)); template = template.Replace("$GameTablePath", "Config.GameTablePath + GameTableName + Config.FILE_EXTENSION_TXT"); Dictionary <string, string> variableMap = new Dictionary <string, string>(); for (int i = m_startRow; i < variable.Length; i++) { if (export[i] == "0") { continue; } string resultStr = string.Empty; //透過字元 '[' ']' 判斷是否是Array bool isArray = variable[i].EndsWith("[]"); bool isArrayInLine = variable[i].EndsWith("{}"); string fieldName = string.Empty; //如果是Array,去除括號 if (isArray) { fieldName = variable[i].Replace("[]", ""); } else if (isArrayInLine) { fieldName = variable[i].Replace("{}", ""); } else { fieldName = variable[i]; } resultStr = GetDataClassDetial(i, fieldName, type[i], isArray, isArrayInLine); //如果名稱一樣(只會發生在複數Array) if (variableMap.ContainsKey(fieldName)) { string oldStr = variableMap[fieldName]; string element = Regex.Match(oldStr, "\\{[^\\}]*\\}").ToString().Trim(new char[] { '{', '}', ' ' }); string newStr = element + ", " + GetTypeDataClass(i.ToString(), type[i], "splitStr"); variableMap.Remove(fieldName); try { variableMap.Add(fieldName, oldStr.Replace(element, newStr)); } catch (ArgumentException e) { Debug.LogError(string.Format("Duplicate variable name and is not Array, table:[{0}], variable name:[{1}].", m_tableName, fieldName)); return(false); } } else { variableMap.Add(fieldName, resultStr); } } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> item in variableMap) { sb.Append(item.Value); } template = template.Replace("$DataLoad", sb.ToString()); UtilityEditor.CreateFolder(m_config.GetScriptableScriptsPath()); using (var writer = new StreamWriter(m_config.GetScriptableScriptsPath() + m_config.GetScriptableScriptName(m_tableName, true))) { writer.Write(template); writer.Close(); } AssetDatabase.Refresh(); Debug.Log(string.Format("[Scriptable Script] is Create.\nFile:[{0}] Path:[{1}]", m_config.GetScriptableScriptName(m_tableName, true), m_config.GetScriptableScriptsPath())); return(true); }
/// <summary> /// 建立 Table Class /// </summary> /// <returns>是否成功建立</returns> bool CreateTableScript(string[] export, string[] summary, string[] variable, string[] type) { Dictionary <string, TableData> dataMap = new Dictionary <string, TableData>(); string templateDataClass = GetTemplate("TableClass"); if (string.IsNullOrEmpty(templateDataClass)) { return(false); } templateDataClass = templateDataClass.Replace("$ClassName", m_config.GetTableClassScriptName(m_tableName)); StringBuilder field = new StringBuilder(); for (int i = m_startRow; i < variable.Length; i++) { if (export[i] == "0") { continue; } //透過字元 '[' ']' 判斷是否是Array bool isArray = variable[i].EndsWith("[]"); bool isArrayInLine = variable[i].EndsWith("{}"); bool isEnd = i == variable.Length - 1; string fieldName = string.Empty; //如果是Array,去除括號 if (isArray) { fieldName = variable[i].Replace("[]", ""); } else if (isArrayInLine) { fieldName = variable[i].Replace("{}", ""); } else { fieldName = variable[i]; } if (dataMap.ContainsKey(fieldName)) { dataMap[fieldName].summary += ", " + summary[i]; } else { dataMap.Add(fieldName, new TableData(summary[i], fieldName, type[i], isArray, isArrayInLine, isEnd)); } } foreach (KeyValuePair <string, TableData> item in dataMap) { field.Append(GetProperty(item.Value.summary, item.Value.name, item.Value.type, item.Value.isArray || item.Value.isArrayInLine, item.Value.isEnd)); } templateDataClass = templateDataClass.Replace("$MemberFields", field.ToString()); UtilityEditor.CreateFolder(m_config.GetTableClassPath()); using (var writer = new StreamWriter(m_config.GetTableClassPath() + m_config.GetTableClassScriptName(m_tableName, true))) { writer.Write(templateDataClass); writer.Close(); } AssetDatabase.Refresh(); Debug.Log(string.Format("[TableClass] is Create.\nFile:[{0}] Path:[{1}]", m_config.GetTableClassScriptName(m_tableName, true), m_config.GetTableClassPath())); return(true); }