예제 #1
0
        /// <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());
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
        }