Ejemplo n.º 1
0
        public virtual void DrawSettings(AppConfigSettings settings, float width)
        {
            SerializedObject   serializedObject = new SerializedObject(settings);
            SerializedProperty prop             = serializedObject.GetIterator();

            while (prop.NextVisible(true))
            {
                if (prop.name == "m_Script" || prop.hasVisibleChildren)
                {
                    continue;
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PropertyField(prop, false, GUILayout.Width(width));
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 2
0
        private void DrawAppConfigSettings(AppConfig appConfig, float currentViewWidth)
        {
            appConfig.ShowInherited = EditorGUILayout.Toggle("Show Inherited", appConfig.ShowInherited);

            List <Type> settingsToAdd = new List <Type>();

            foreach (var settingsType in BuildSettingsTypes)
            {
                bool isInherited = false;

                AppConfigSettings settings = appConfig.GetSettings(settingsType, out isInherited);

                if (settings == null)
                {
                    settingsToAdd.Add(settingsType);
                }
                else
                {
                    // Checking if we should skip this
                    if (isInherited && appConfig.ShowInherited == false)
                    {
                        continue;
                    }

                    bool didDeleteSettings = false;
                    this.DrawAppConfigSettings(appConfig, settings, isInherited, out didDeleteSettings);

                    if (didDeleteSettings)
                    {
                        break;
                    }
                }
            }

            int buttonWidth = (int)(currentViewWidth / 2.0f);

            for (int i = 0; i < settingsToAdd.Count; i += 2)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    for (int j = 0; j < 2; j++)
                    {
                        int index = i + j;

                        if (index >= settingsToAdd.Count)
                        {
                            break;
                        }

                        var settingsType = settingsToAdd[index];

                        string buttonName = settingsType.Name;

                        if (buttonName.EndsWith("Settings"))
                        {
                            buttonName = buttonName.Replace("Settings", string.Empty);
                        }

                        if (GUILayout.Button(buttonName, GUILayout.Width(buttonWidth)))
                        {
                            var newSettings = ScriptableObject.CreateInstance(settingsType) as AppConfigSettings;
                            newSettings.name = newSettings.DisplayName;

                            appConfig.Settings.Add(newSettings);

                            string path = appConfig.GetPath();
                            AssetDatabase.AddObjectToAsset(newSettings, path);
                            AssetDatabase.ImportAsset(path);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void DrawAppConfigSettings(AppConfig appConfig, AppConfigSettings settings, bool isInherited, out bool didDeleteSettings)
        {
            didDeleteSettings = false;

            float currentViewWidth = EditorGUIUtility.currentViewWidth - 20;
            bool  foldoutVisible   = true;
            Rect  boxRect          = new Rect();

            var verticleHelper = settings.IsInline ?
                                 (IDisposable) new EditorGUILayout.HorizontalScope("box") :
                                 (IDisposable) new FoldoutScope(settings.DisplayName.GetHashCode(), settings.DisplayName, out foldoutVisible, out boxRect, false);

            using (verticleHelper)
            {
                float y = settings.IsInline ? (verticleHelper as EditorGUILayout.HorizontalScope).rect.y : boxRect.y;

                // Drawing the button
                float buttonSize   = 14;
                float rightPadding = 7;
                float topPadding   = 1;

                Rect buttonRect = new Rect(new Vector2(currentViewWidth - rightPadding, y + topPadding), new Vector2(buttonSize, buttonSize));

                if (isInherited)
                {
                    if (ButtonUtil.DrawAddButton(buttonRect))
                    {
                        var newSettings = UnityEngine.Object.Instantiate(settings) as AppConfigSettings;
                        appConfig.Settings.Add(newSettings);

                        string path = appConfig.GetPath();
                        AssetDatabase.AddObjectToAsset(newSettings, path);
                        AssetDatabase.ImportAsset(path);
                    }
                }
                else
                {
                    if (ButtonUtil.DrawDeleteButton(buttonRect))
                    {
                        appConfig.Settings.Remove(settings);
                        GameObject.DestroyImmediate(settings, true);
                        AssetDatabase.ImportAsset(appConfig.GetPath());
                        didDeleteSettings = true;
                        return;
                    }
                }

                // Breaking out if we're not suppose to show the foldout
                if (foldoutVisible == false)
                {
                    return;
                }

                // Iterating and displaying all properties
                using (new EditorGUI.DisabledGroupScope(isInherited))
                {
                    float width = currentViewWidth - (settings.IsInline ? 34 : 15);
                    settings.DrawSettings(settings, width);
                }
            }
        }