示例#1
0
        public void DrawGraph(ConfigAssetGroup groupAsset, ConfigAsset asset)
        {
            GUILayoutExtension.HorizontalGroup(() => {
                EditorGUILayout.LabelField(asset.name, GUILayout.Width(150));

                if (GUILayout.Button("打开", GUILayout.Width(50)))
                {
                    ConfigAssetWindow.Open(asset);
                }

                if (GUILayout.Button("删除", GUILayout.Width(50)))
                {
                    groupAsset.RemoveAsset(asset);
                }

                if (GUILayout.Button("重命名", GUILayout.Width(50)))
                {
                    MiscHelper.Input($"输入配置名:", (string name) =>
                    {
                        asset.name = name;
                        EditorUtility.SetDirty(asset);
                        EditorUtility.SetDirty(target);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    });
                }
            });
        }
示例#2
0
        /// <summary>
        /// 获得配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static List <T> GetConfigAssets <T>() where T : IConfig
        {
            List <T> assets = new List <T>();

            string[] tileAssetPath = new string[] { Setting.ConfigSearchPath };
            string[] guids         = AssetDatabase.FindAssets("t:ScriptableObject", tileAssetPath);
            foreach (var guid in guids)
            {
                string           path   = AssetDatabase.GUIDToAssetPath(guid);
                ConfigAssetGroup config = AssetDatabase.LoadAssetAtPath <ConfigAssetGroup>(path);
                if (string.IsNullOrEmpty(config.configTypeName))
                {
                    Debug.LogError($"p配置导出失败,没有对应配置类》》》{config.name}");
                    continue;
                }
                if (config.configTypeFullName == typeof(T).FullName)
                {
                    foreach (var item in config.GetAllAsset())
                    {
                        List <IConfig> datas = item.Load();
                        if (datas != null)
                        {
                            for (int i = 0; i < datas.Count; i++)
                            {
                                assets.Add((T)datas[i]);
                            }
                        }
                    }
                }
            }
            return(assets);
        }
示例#3
0
 public static void Create()
 {
     MiscHelper.Input("输入配置名", (string x) =>
     {
         ConfigAssetGroup config = CreateInstance <ConfigAssetGroup>();
         config.name             = x;
         AssetDatabase.CreateAsset(config, ConfigSetting.Setting.ConfigSearchPath + x + ".asset");
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
         Selection.activeObject = config;
     });
 }
示例#4
0
        public static void Export()
        {
            string[] tileAssetPath = new string[] { Setting.ConfigSearchPath };
            string[] guids         = AssetDatabase.FindAssets("t:ScriptableObject", tileAssetPath);

            Dictionary <string, List <IConfig> > configDict = new Dictionary <string, List <IConfig> >();

            foreach (var guid in guids)
            {
                string           path   = AssetDatabase.GUIDToAssetPath(guid);
                ConfigAssetGroup config = AssetDatabase.LoadAssetAtPath <ConfigAssetGroup>(path);
                if (string.IsNullOrEmpty(config.configTypeName))
                {
                    Debug.LogError($"p配置导出失败,没有对应配置类》》》{config.name}");
                    return;
                }
                List <IConfig> configs = new List <IConfig>();
                if (config != null)
                {
                    foreach (var item in config.GetAllAsset())
                    {
                        List <IConfig> datas = item.Load();
                        if (datas != null)
                        {
                            configs.AddRange(datas);
                        }
                    }
                }
                if (configDict.ContainsKey(config.configTypeName))
                {
                    configDict[config.configTypeName].AddRange(configs);
                }
                else
                {
                    configDict.Add(config.configTypeName, configs);
                }
            }

            foreach (var item in configDict)
            {
                string filePath = Setting.ConfigExportPath + ConfigDef.GetCnfName(item.Key);
                IOHelper.WriteText(JsonMapper.ToJson(item.Value), filePath);
            }
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
        }
示例#5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (!ContextDataCache.TryGetContextData <GUIStyle>("BigLabel", out var bigLabel))
            {
                bigLabel.value              = new GUIStyle(GUI.skin.label);
                bigLabel.value.fontSize     = 18;
                bigLabel.value.fontStyle    = FontStyle.Bold;
                bigLabel.value.alignment    = TextAnchor.MiddleLeft;
                bigLabel.value.stretchWidth = true;
            }

            ConfigAssetGroup groupAsset = target as ConfigAssetGroup;

            GUILayoutExtension.VerticalGroup(() =>
            {
                GUILayout.Label($"Config:{groupAsset.name}", bigLabel.value);
            });

            GUILayoutExtension.VerticalGroup(() =>
            {
                List <Type> cnfTypes   = new List <Type>();
                List <string> cnfNames = new List <string>();
                foreach (var item in ReflectionHelper.GetChildTypes <IConfig>())
                {
                    string displayName = item.Name;
                    if (AttributeHelper.TryGetTypeAttribute(item, out ConfigAttribute attr))
                    {
                        displayName = attr.DisplayName;
                    }
                    cnfNames.Add(displayName);
                    cnfTypes.Add(item);
                }
                if (groupAsset.configTypeFullName == null)
                {
                    EditorGUILayout.HelpBox("没有选择配置类!!!", MessageType.Error);
                    MiscHelper.Dropdown($"选择的配置类", cnfNames, (int a) => {
                        groupAsset.configTypeFullName = cnfTypes[a].FullName;
                        groupAsset.configTypeName     = cnfTypes[a].Name;
                    }, 300);
                }
                else
                {
                    MiscHelper.Dropdown(groupAsset.configTypeFullName, cnfNames, (int a) => {
                        groupAsset.configTypeFullName = cnfTypes[a].FullName;
                        groupAsset.configTypeName     = cnfTypes[a].Name;
                    }, 300);
                }
            });

            GUILayoutExtension.VerticalGroup(() => {
                List <ConfigAsset> assets = groupAsset.GetAllAsset();
                for (int i = 0; i < assets.Count; i++)
                {
                    DrawGraph(groupAsset, assets[i]);
                }
            });

            GUILayoutExtension.VerticalGroup(() =>
            {
                if (GUILayout.Button($"创建配置", GUILayout.Height(50)))
                {
                    MiscHelper.Input($"输入配置名:", (string name) =>
                    {
                        groupAsset.CreateAsset(name);
                    });
                }
            });
        }