Ejemplo n.º 1
0
        public static T Create(string _name)
        {
#if UNITY_EDITOR
            Settings.Setting.SettingConfig settingConfig = Settings.Setting.Instance.EditorGetBuildTargetConfig(UnityEditor.EditorUserBuildSettings.activeBuildTarget);
#else
            Settings.Setting.SettingConfig settingConfig = Settings.Setting.Instance.Config;
#endif
            return(Create(settingConfig.SaveSystemType.GetSaveSystemType <T>(), _name, settingConfig.SaveSystemConfig));
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            Setting settingTarget = (Setting)target;

            // Populate build target list if necessary
            if (buildTargets == null)
            {
                buildTargets = ((BuildTarget[])Enum.GetValues(typeof(BuildTarget))).ToList();
                buildTargets.RemoveAll(target => IsObsolete(target));
                buildTargets.Remove(BuildTarget.NoTarget);
                List <string> b_buildTargetNames = new List <string>();
                foreach (BuildTarget iBuildTarget in buildTargets)
                {
                    b_buildTargetNames.Add(iBuildTarget.ToString());
                }
                buildTargetNames = b_buildTargetNames.ToArray();
            }

            Event eventCurrent = Event.current;

            GUILayout.BeginVertical();

            DrawSpace(10);

            // Toolbar
            GUILayout.BeginHorizontal();
            for (int i = 0; i < settingTarget.EditorConfigs.Count; ++i)
            {
                // Set style
                GUIStyle buttonStyle = EditorStyles.miniButtonMid;
                if (i == 0)
                {
                    buttonStyle = EditorStyles.miniButtonLeft;
                }

                // Set variables
                Setting.SettingConfig iSettingConfig = settingTarget.EditorConfigs[i];
                bool   selected     = i == selectedConfigIndex;
                string displayLabel = iSettingConfig.Name;

                Rect rectButton = GUILayoutUtility.GetRect(GUIContent.none, buttonStyle);

                switch (eventCurrent.type)
                {
                case EventType.MouseDown:
                    if (rectButton.Contains(eventCurrent.mousePosition))
                    {
                        selectedConfigIndex        = i;
                        GUIUtility.keyboardControl = 0;
                        GUIUtility.hotControl      = iSettingConfig.GetHashCode();
                        eventCurrent.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == iSettingConfig.GetHashCode())
                    {
                        GUIUtility.hotControl = 0;
                        eventCurrent.Use();
                    }
                    break;

                case EventType.Repaint:
                    buttonStyle.Draw(rectButton, displayLabel, false, false, selected, false);
                    break;
                }
            }

            // Add button
            if (GUI.Button(GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.miniButtonRight), Content.kIconAdd, (settingTarget.EditorConfigs.Count > 0) ? EditorStyles.miniButtonRight : EditorStyles.miniButton))
            {
                Undo.RecordObject(settingTarget, "Add new config");
                Setting.SettingConfig b_config = new Setting.SettingConfig();
                settingTarget.EditorConfigs.Add(b_config);
                selectedConfigIndex = settingTarget.EditorConfigs.Count - 1;
                EditorUtility.SetDirty(settingTarget);
            }
            GUILayout.EndHorizontal();

            DrawSpace(10);

            // Display config settings
            GUILayout.BeginVertical();
            if (selectedConfigIndex >= 0 && selectedConfigIndex < settingTarget.EditorConfigs.Count)
            {
                // Name
                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                string b_name = EditorGUI.TextField(GUILayoutUtility.GetRect(GUIContent.none, Styles.kDefaultToggle), "Name", settingTarget.EditorConfigs[selectedConfigIndex].Name);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(settingTarget, "Rename config");
                    settingTarget.EditorConfigs[selectedConfigIndex].Name = b_name;
                    EditorUtility.SetDirty(settingTarget);
                }
                GUILayout.EndHorizontal();

                DrawSpace(5);

                // Display a list of the build target
                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                buildTargetMask = ListToMask(buildTargets, settingTarget.EditorConfigs[selectedConfigIndex].EditorBuildTargets);
                buildTargetMask = EditorGUI.MaskField(GUILayoutUtility.GetRect(GUIContent.none, Styles.kDefaultToggle), "Used for platform", buildTargetMask, buildTargetNames);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(settingTarget, "Used platform changed");
                    settingTarget.EditorConfigs[selectedConfigIndex].EditorBuildTargets = MaskToList(buildTargets, buildTargetMask);
                    EditorUtility.SetDirty(settingTarget);
                }
                GUILayout.EndHorizontal();

                //string resumeBuildTarget = "";
                //foreach (BuildTarget iBuildTarget in settingTarget.EditorConfigs[selectedConfigIndex].EditorBuildTargets)
                //    resumeBuildTarget += ", " + iBuildTarget.ToString();
                //resumeBuildTarget = resumeBuildTarget.Substring(2, resumeBuildTarget.Length - 2);
                //EditorGUI.LabelField(GUILayoutUtility.GetRect(GUIContent.none, Styles.kDefaultToggle), resumeBuildTarget);

                DrawSpace(5);

                // Delete button
                GUILayout.BeginHorizontal();
                if (GUI.Button(GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.miniButtonRight), Content.kDeleteConfig, EditorStyles.miniButton))
                {
                    if (EditorUtility.DisplayDialog(
                            "Delete " + settingTarget.EditorConfigs[selectedConfigIndex].Name + " Config?",
                            "Are you sure you want to delete " + settingTarget.EditorConfigs[selectedConfigIndex].Name + " config?", "Yes", "No"))
                    {
                        Undo.RecordObject(settingTarget, "Delete " + settingTarget.EditorConfigs[selectedConfigIndex].Name + " Config");
                        settingTarget.EditorConfigs.Remove(settingTarget.EditorConfigs[selectedConfigIndex]);
                        selectedConfigIndex--;
                        if (selectedConfigIndex < 0)
                        {
                            selectedConfigIndex = 0;
                        }
                        EditorUtility.SetDirty(settingTarget);
                    }
                }
                GUILayout.EndHorizontal();

                DrawLine(1, 10, 10);

                // Save sytem selection
                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                SaveSystems.Types b_saveSystemType = (SaveSystems.Types)EditorGUILayout.EnumPopup("Save System", settingTarget.EditorConfigs[selectedConfigIndex].SaveSystemType);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(settingTarget, "Change save system");
                    settingTarget.EditorConfigs[selectedConfigIndex].SaveSystemType = b_saveSystemType;
                    EditorUtility.SetDirty(settingTarget);
                }
                GUILayout.EndHorizontal();

                // Display the good inspector for edit the config
                switch (settingTarget.EditorConfigs[selectedConfigIndex].SaveSystemType)
                {
                case SaveSystems.Types.PersistentDataPathFile:
                    Config.EditorPersistentDataPathFileInspector(ref settingTarget, selectedConfigIndex);
                    break;
                }
            }
            GUILayout.EndVertical();

            GUILayout.EndVertical();
        }