예제 #1
0
        public override bool LoadGameTable(bool bSaveToAsset)
        {
            ClientDataBaseConfig clientDataBaseConfig = ClientDataBaseManager.Instance.m_config;
            string path = clientDataBaseConfig.GetGameTablePathName(GetTableName());

            TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(path);

            if (data == null)
            {
                Debug.LogError(string.Format("Can't found GameTable txt file in [Path:{0}]", path));
                return(false);
            }

            if (!LoadGameTable(data.text))
            {
                return(false);
            }

            if (bSaveToAsset)
            {
                EditorUtility.SetDirty(this);
                AssetDatabase.SaveAssets();
                Debug.Log(string.Format("[{0}] GameTable Asset is Update. Source:[{1}]", this.name, path));
            }



            return(true);
        }
예제 #2
0
        /// <summary>
        /// 建立 Scriptable Asset
        /// </summary>
        /// <returns>是否成功建立</returns>
        public bool CreateScriptableAssets(string scriptableScriptName, string scriptableAssetName)
        {
            _config = ClientDataBaseManager.Instance.m_config;
            MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(_config.GetScriptableScriptsPath() + scriptableScriptName);

            if (script == null || script.GetClass() == null)
            {
                Debug.LogError(string.Format("Scriptable Script is Null. [Path:{0}]", _config.GetScriptableScriptsPath() + scriptableScriptName));
                return(false);
            }

            string path = _config.GetScriptableAssetPath() + scriptableAssetName;

            UtilityEditor.CreateFolder(_config.GetScriptableAssetPath());

            Object _Object = ScriptableObject.CreateInstance(script.GetClass());

            AssetDatabase.CreateAsset(_Object, path);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            Debug.Log(string.Format("[Scriptable Asset] is Create.\nFile:[{0}] Path:[{1}]", scriptableAssetName, _config.GetScriptableAssetPath()));

            //資料讀取
            ScriptableObjectBase scriptableObjectBase = AssetDatabase.LoadAssetAtPath <ScriptableObjectBase>(path);

            return(scriptableObjectBase.LoadGameTable(true));
        }
        public override void OnInspectorGUI()
        {
            _script = target as ClientDataBaseConfig;

            GUILayout.Space(15);
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("Check", EditorStyles.boldLabel);
            _script.m_gameTableCheck = DrawNormalField("Game Table Check", _script.m_gameTableCheck);
            EditorGUILayout.EndVertical();


            GUILayout.Space(15);
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("Path", EditorStyles.boldLabel);

            _script.m_root                  = DrawNormalField("ROOT", _script.m_root);
            _script.m_pathGameTable         = DrawNormalField("Game Table Path", _script.m_pathGameTable);
            _script.m_pathScriptTemplates   = DrawPathField("Script Templates Path", _script.m_pathScriptTemplates);
            _script.m_pathTableClass        = DrawPathField("Table Class Path", _script.m_pathTableClass);
            _script.m_pathScriptableAsset   = DrawNormalField("Scriptable Asset Path", _script.m_pathScriptableAsset);
            _script.m_pathScriptableScripts = DrawPathField("Scriptable Scripts Path", _script.m_pathScriptableScripts);
            _script.m_pathScriptableEditor  = DrawPathField("Scriptable Editor Path", _script.m_pathScriptableEditor);
            EditorGUILayout.EndVertical();


            GUILayout.Space(15);
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("Name", EditorStyles.boldLabel);
            _script.m_nameClassPrefix            = DrawNameField("Class Name Prefix", "Preview: " + _script.m_nameClassPrefix + "[FileName]", _script.m_nameClassPrefix);
            _script.m_nameScriptableAssetSuffix  = DrawNameField("Scriptable Asset Suffix", "Preview: " + _script.m_nameClassPrefix + "[FileName]" + _script.m_nameScriptableAssetSuffix, _script.m_nameScriptableAssetSuffix);
            _script.m_nameScriptableScriptSuffix = DrawNameField("Scriptable Script Suffix", "Preview: " + _script.m_nameClassPrefix + "[FileName]" + _script.m_nameScriptableScriptSuffix, _script.m_nameScriptableScriptSuffix);
            _script.m_nameScriptableEditorSuffix = DrawNameField("Scriptable Editor Suffix", "Preview: " + _script.m_nameClassPrefix + "[FileName]" + _script.m_nameScriptableEditorSuffix, _script.m_nameScriptableEditorSuffix);
            EditorGUILayout.EndVertical();

            EditorUtility.SetDirty(_script);
        }
예제 #4
0
        /// <summary>
        /// 讀取GameTable(.txt)
        /// </summary>
        public bool LoadGameTable(Object obj, bool exportCSharp, bool exportServer, bool exportLua)
        {
            _config    = ClientDataBaseManager.Instance.m_config;
            _tableName = obj.name;

            //-string strTemp;
            TextAsset  data   = (TextAsset)obj;
            TextReader reader = null;

            string[] _Summary        = null;
            string[] _Variable       = null;
            string[] _ErlangVariable = null;
            string[] _LuaVariable    = null;
            string[] _Type           = null;
            int      index           = 0;


            if (data == null)
            {
                Debug.LogError("GameTable is null.");
                return(false);
            }

            if (data.text == string.Empty)
            {
                Debug.LogError("GameTable is empty.");
                return(false);
            }

            reader = new StringReader(data.text);
            if (reader != null)
            {
                int keyCol = -1;
                //while ((strTemp = reader.ReadLine()) != null)
                CsvReader csvReader = new CsvReader(reader, false);
                foreach (string[] splitStr in csvReader)
                {
                    if (index == 0)
                    {
                        _Type    = splitStr.Select(a => a.Trim()).ToArray();
                        _Summary = _Type.ToArray();

                        // convert to real type
                        for (var i = 0; i < _Type.Length; i++)
                        {
                            //检查多个主键
                            if (CsvConfigReader.IsKeyType(_Type[i]))
                            {
                                if (keyCol >= 0)
                                {
                                    Debug.LogError(string.Format("Duplicate key type conflict in table:[{0}]  col:[{1}] with col[{2}]", _tableName, keyCol, index));
                                    return(false);
                                }
                                keyCol = i;
                            }

                            _Type[i] = ConvertCsvTypeToCsType(_Type[i]);
                        }

                        index++;
                        continue;
                    }

                    if (index == 1)
                    {
                        _Variable = splitStr.Select(a => a.Trim()).ToArray();

                        _ErlangVariable = splitStr.ToArray();

                        // 解决字段有空格的问题
                        for (int i = 0; i < _Variable.Length; i++)
                        {
                            _ErlangVariable[i] = Utility.TypeRelate.CorrectFieldName(_ErlangVariable[i], "_").ToLower();
                            _Variable[i]       = Utility.TypeRelate.CorrectFieldName(_Variable[i], "");
                        }
                        _LuaVariable = _Variable.Select(FirstCharToUpper).ToArray();


                        //1.判斷是否是 GameTable(txt),檔案的開始字串是否包含 識別字
                        if (!string.IsNullOrEmpty(_config.m_gameTableCheck) && _Summary[0].IndexOf(_config.m_gameTableCheck) < 0)
                        {
                            Debug.LogError("GameTable is not a table. Please Check txt file start string is [" + _config.m_gameTableCheck + "]");
                            return(false);
                        }

                        //2.判斷欄位數量是否一致
                        int count = _Summary.Length;
                        if (count != _Variable.Length || count != _Type.Length)
                        {
                            Debug.LogError("GameTable column not same.");
                            return(false);
                        }

                        if (!exportCSharp)
                        {
                            break;
                        }

                        Dictionary <string, TableData> datamap = CreateTableScript(_Summary, _Variable, _Type);
                        if (datamap == null)
                        {
                            return(false);
                        }

                        if (CreateScriptableScript(_Variable, datamap, keyCol) == false)
                        {
                            return(false);
                        }

                        if (CreateScriptableScriptEditor() == false)
                        {
                            return(false);
                        }

                        break;
                    }
                }
                reader.Close();
            }

            if (exportServer)
            {
                ExportServerConfig(_Summary, _ErlangVariable, _Type, data.text);
            }

            if (exportLua)
            {
                ExportLuaConfig(_Summary, _LuaVariable, _Type, data.text);
            }

            return(true);
        }