Beispiel #1
0
    private void Load()
    {
        if (File.Exists(Path))
        {
#if USING_XML
            XmlSerializer ser = new XmlSerializer(typeof(ZConfig));
            using (Stream stream = File.OpenRead(Path))
            {
                ZConfig config = ser.Deserialize(stream) as ZConfig;
                _groups     = config.groups;
                _selections = config.selections;
            }
#else
            string json      = File.ReadAllText(Path);
            string groupJson = File.ReadAllText(GroupInfoPath);
            _groups     = JsonMapper.ToObject <List <GroupConfig> >(json);
            _selections = JsonMapper.ToObject <List <GroupSelection> >(groupJson);
#endif
        }

        if (_groups == null)
        {
            _groups = new List <GroupConfig>();
            GroupConfig group = new GroupConfig();
            group.Initialize();
            _groups.Add(group);
        }
        if (_selections == null)
        {
            _selections = new List <GroupSelection>();
            GroupSelection sel = new GroupSelection {
                name = "Default", desc = "Default group"
            };
            _selections.Add(sel);
        }
    }
Beispiel #2
0
    private void DrawContent()
    {
        float keyWidth  = (position.width - 85) / 6;
        float pathWidth = (position.width - 85) / 6 * 4;
        float objWidth  = (position.width - 85) / 6;

        _pos = EditorGUILayout.BeginScrollView(_pos);
        {
            EditorGUILayout.BeginVertical();
            {
                for (int i = 0; i < _groups.Count; i++)
                {
                    GroupConfig config = _groups[i];
                    config.foldout = EditorGUILayout.Foldout(config.foldout, GetGroupInfo(config.id));
                    {
                        if (config.foldout)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(25)))                                 //Add group
                                {
                                    GroupConfig group = new GroupConfig();
                                    group.Initialize();
                                    _groups.Insert(i + 1, group);
                                    return;
                                }
                                if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(25)))                                 //remove group
                                {
                                    if (_groups.Count <= 1)
                                    {
                                        return;
                                    }
                                    _groups.RemoveAt(i);
                                    return;
                                }
                                config.id = EditorGUILayout.Popup(config.id, _selections.Select(s => s.name).ToArray(),
                                                                  GUILayout.Width(100));
                            }
                            EditorGUILayout.EndHorizontal();

                            for (int j = 0; j < config.resources.Count; j++)
                            {
                                EditorResourceConfig resource = new EditorResourceConfig(config.resources[j]);
                                bool legal = CheckKey(config.resources[j]);
                                _nameLegal = _nameLegal && legal;

                                EditorGUILayout.BeginHorizontal();
                                {
                                    resource.key = EditorGUILayout.TextField(resource.key, legal ? EditorStyles.textField : _errorStyle,
                                                                             GUILayout.Width(keyWidth));
                                    resource.path = EditorGUILayout.TextField(resource.path, GUILayout.Width(pathWidth));

                                    if (!string.IsNullOrEmpty(resource.path))
                                    {
                                        resource.obj = AssetDatabase.LoadAssetAtPath(resource.path, typeof(Object));
                                    }

                                    resource.obj = EditorGUILayout.ObjectField(resource.obj, typeof(Object), false, GUILayout.Width(objWidth));

                                    if (resource.obj != null)
                                    {
                                        resource.path = AssetDatabase.GetAssetPath(resource.obj);
                                    }
                                    else if (!string.IsNullOrEmpty(resource.path))
                                    {
                                        resource.obj = AssetDatabase.LoadAssetAtPath(resource.path, typeof(Object));
                                    }

                                    if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(25)))                                     //add resource
                                    {
                                        ResourceConfig res = new ResourceConfig();
                                        res.Initialize();
                                        config.resources.Insert(j + 1, res);
                                        return;
                                    }
                                    if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(25)))                                     //remove resource
                                    {
                                        if (config.resources.Count <= 1)
                                        {
                                            return;
                                        }
                                        config.resources.RemoveAt(j);
                                        return;
                                    }

                                    config.resources[j] = resource.ToResourceConfig();
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndScrollView();
    }