Esempio n. 1
0
        public void DrawNewProject()
        {
            var hasErrors = false;

            var darkLabel = ME.Utilities.CacheStyle("FlowEditor.DataSelection.Styles", "DarkLabel", (name) => {
                var style       = new GUIStyle(FlowSystemEditorWindow.defaultSkin.FindStyle(name));
                style.alignment = TextAnchor.MiddleLeft;
                return(style);
            });

            GUILayout.Label("1. Select the project folder:", darkLabel);
            EditorGUILayout.HelpBox("It is strongly recommended to create new project in Resources folder!", MessageType.Warning);
            GUILayout.BeginHorizontal(GUILayout.Height(30f));
            {
                this.projectFolder = EditorGUILayout.TextField(this.projectFolder, this.skin.textField).UppercaseWords();
                if (GUILayout.Button("...", this.skin.button, GUILayout.Width(35f)) == true)
                {
                    var path = EditorUtility.SaveFolderPanel("Select Empty Project Folder", "Assets/", "").Trim();
                    if (string.IsNullOrEmpty(path) == false)
                    {
                        var splitted = path.Split(new string[] { Application.dataPath }, StringSplitOptions.None);
                        if (splitted.Length > 1)
                        {
                            path = "Assets" + splitted[1];
                        }

                        this.projectFolder = path;
                    }
                }
            }
            GUILayout.EndHorizontal();

            // Test it
            if (Directory.Exists(this.projectFolder) == true &&
                (Directory.GetFiles(this.projectFolder).Count() > 0 ||
                 Directory.GetDirectories(this.projectFolder).Count() > 0))
            {
                EditorGUILayout.HelpBox("Directory should not exists or must be empty.", MessageType.Error);
                hasErrors = true;
            }

            if (this.projectNamespaceAuto == true || string.IsNullOrEmpty(this.projectNamespace) == true)
            {
                this.projectNamespace = this.projectFolder.Split('/').Last().Trim() + ".UI";
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("2. Project namespace:", darkLabel);
                GUILayout.FlexibleSpace();
                this.projectNamespaceAuto = GUILayout.Toggle(this.projectNamespaceAuto, "Automatic");
            }
            GUILayout.EndHorizontal();

            var oldState = GUI.enabled;

            GUILayout.BeginHorizontal(GUILayout.Height(30f));
            {
                GUI.enabled           = oldState && !this.projectNamespaceAuto;
                this.projectNamespace = EditorGUILayout.TextField(this.projectNamespace, this.skin.textField);
                GUI.enabled           = oldState;
            }
            GUILayout.EndHorizontal();

            // Test it
            //var type = Type.GetType("Assembly-CSharp", throwOnError: true, ignoreCase: true);
            string assemblyName = "Assembly-CSharp";

            var asm = AppDomain.CurrentDomain.GetAssemblies().Where((item) => {
                var name = item.FullName.ToLower().Trim();
                return(name.StartsWith(assemblyName.ToLower() + ","));
            }).FirstOrDefault();

            if (asm != null)
            {
                var contains = asm.GetTypes().Any((type) => {
                    return(type.Namespace != null && type.Namespace.ToLower().Trim() == this.projectNamespace.ToLower().Trim());
                });

                if (contains == true)
                {
                    EditorGUILayout.HelpBox("Namespace already exists.", MessageType.Error);
                    hasErrors = true;
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Assembly was not found. Try to re-open Unity.", MessageType.Error);
                hasErrors = true;
            }

            var pattern = @"^([A-Za-z]+[\.a-zA-Z0-9_]*)$";
            var ns      = this.projectNamespace;
            var rgx     = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var isMatch = rgx.IsMatch(ns);

            if (isMatch == false)
            {
                EditorGUILayout.HelpBox("Namespace can contains `.`, `_`, A-Z and 0-9. First symbol must be a char.", MessageType.Error);
                hasErrors = true;
            }

            GUILayout.FlexibleSpace();

            CustomGUI.Splitter();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Cancel", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(100f), GUILayout.Height(40f)) == true)
                {
                    this.state = State.ProjectSelector;
                }

                GUILayout.FlexibleSpace();

                oldState    = GUI.enabled;
                GUI.enabled = oldState && !hasErrors;
                if (GUILayout.Button("Create & Open", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true)
                {
                    this.state = State.ProjectSelector;
                    var data = this.CreateProject(this.projectFolder, this.projectNamespace);
                    this.editor.OpenFlowData(data);

                    EditorUtilities.ResetCache <FlowData>();
                }
                GUI.enabled = oldState;
            }
            GUILayout.EndHorizontal();
        }
Esempio n. 2
0
        public void DrawProjectSelector()
        {
            var darkLabel = ME.Utilities.CacheStyle("FlowEditor.DataSelection.Styles", "DarkLabel", (name) => {
                var style       = new GUIStyle(FlowSystemEditorWindow.defaultSkin.FindStyle(name));
                style.alignment = TextAnchor.MiddleLeft;
                return(style);
            });

            var headerStyle = new GUIStyle("LODLevelNotifyText");

            headerStyle.normal.textColor = EditorGUIUtility.isProSkin == true ? Color.white : Color.black;
            headerStyle.fontSize         = 18;
            headerStyle.alignment        = TextAnchor.MiddleCenter;

            GUILayoutExt.LabelWithShadow(string.Format("UI.Windows Flow Extension v{0}", VersionInfo.BUNDLE_VERSION), headerStyle);

            GUILayout.Space(10f);

            GUILayout.Label("Open one of your projects:", darkLabel);

            var backStyle = new GUIStyle("sv_iconselector_labelselection");

            var skin = GUI.skin;

            GUI.skin = FlowSystemEditorWindow.defaultSkin;
            this.dataSelectionScroll = GUILayout.BeginScrollView(this.dataSelectionScroll, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, backStyle);
            {
                GUI.skin = skin;

                this.scannedData = EditorUtilities.GetAssetsOfType <FlowData>(useCache: true);

                if (this.scannedData.Length == 0)
                {
                    var center = new GUIStyle(darkLabel);
                    center.fixedWidth    = 0f;
                    center.fixedHeight   = 0f;
                    center.stretchWidth  = true;
                    center.stretchHeight = true;
                    center.alignment     = TextAnchor.MiddleCenter;
                    center.wordWrap      = true;

                    GUILayout.Label("No projects were found. Create a new one by Right-Click on any folder in Project View and choose `Create->UI.Windows->Flow->Graph` option.", center);
                }
                else
                {
                    var buttonStyle = new GUIStyle("flow node 1 on");
                    buttonStyle.alignment        = TextAnchor.MiddleLeft;
                    buttonStyle.padding          = new RectOffset(15, 15, 15, 15);
                    buttonStyle.margin           = new RectOffset(2, 2, 2, 2);
                    buttonStyle.overflow         = new RectOffset();
                    buttonStyle.contentOffset    = Vector2.zero;
                    buttonStyle.fixedWidth       = 0f;
                    buttonStyle.fixedHeight      = 0f;
                    buttonStyle.stretchWidth     = true;
                    buttonStyle.stretchHeight    = false;
                    buttonStyle.normal.textColor = Color.white;
                    buttonStyle.fontSize         = 12;
                    buttonStyle.richText         = true;

                    var buttonStyleSelected = new GUIStyle(buttonStyle);
                    buttonStyle.normal.background = null;
                    buttonStyle.normal.textColor  = Color.black;

                    this.scannedData = this.scannedData.OrderByDescending((data) => (data != null ? data.lastModifiedUnix : 0)).ToArray();

                    foreach (var data in this.scannedData)
                    {
                        if (data == null)
                        {
                            continue;
                        }

                        var isSelected = (this.cachedData == data);

                        var title = data.name + "\n";
                        title += string.Format("<color={1}><size=10>Modified: {0}</size></color>\n", data.lastModified, isSelected == true ? "#ccc" : "#999");
                        title += string.Format("<color={1}><size=10>Version: {0}</size></color>", data.version, isSelected == true ? "#ccc" : "#999");

                        if (GUILayout.Button(title, isSelected ? buttonStyleSelected : buttonStyle) == true)
                        {
                            this.cachedData = data;
                        }
                    }
                }

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndScrollView();

            GUILayout.Space(10f);

            GUILayout.Label("Or select the project file:", darkLabel);

            this.cachedData = GUILayoutExt.ObjectField <FlowData>(this.cachedData, false, FlowSystemEditorWindow.defaultSkin.FindStyle("ObjectField"));

            CustomGUI.Splitter();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Create Project...", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true)
                {
                    this.state = State.NewProject;
                }

                GUILayout.FlexibleSpace();

                var oldState = GUI.enabled;
                GUI.enabled = oldState && this.cachedData != null;

                if (this.cachedData != null && this.cachedData.version < VersionInfo.BUNDLE_VERSION)
                {
                    // Need to upgrade

                    if (GUILayout.Button("Upgrade to " + VersionInfo.BUNDLE_VERSION, FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true)
                    {
                        FlowUpdater.Run(this.cachedData);
                    }
                }
                else if (this.cachedData != null && this.cachedData.version > VersionInfo.BUNDLE_VERSION)
                {
                    var info = string.Format(
                        "Selected Project has `{0}` version while UI.Windows System has `{1}` version number. Click here to download a new version.",
                        this.cachedData.version,
                        VersionInfo.BUNDLE_VERSION
                        );

                    if (GUILayout.Button(new GUIContent(info, new GUIStyle("CN EntryWarn").normal.background), EditorStyles.helpBox, GUILayout.Height(40f)) == true)
                    {
                        Application.OpenURL(VersionInfo.DOWNLOAD_LINK);
                    }
                }
                else
                {
                    if (GUILayout.Button("Open", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(100f), GUILayout.Height(40f)) == true)
                    {
                        FlowSystem.SetData(this.cachedData);
                    }
                }

                GUI.enabled = oldState;
            }
            GUILayout.EndHorizontal();
        }
Esempio n. 3
0
        protected override void OnInspectorGUI(UnityEngine.UI.Windows.Plugins.Heatmap.Core.HeatmapSettings settings, AnalyticsServiceItem item, System.Action onReset, GUISkin skin)
        {
            var wasChanged = GUI.changed;

            GUI.changed = false;

            GUI.changed = item.userFilter.OnGUI(skin) || GUI.changed;

            CustomGUI.Splitter();

            if (GUI.changed == true)
            {
                item.isChanged = true;
            }

            UnityEditor.EditorGUI.BeginDisabledGroup(!item.isChanged);
            if (GUILayout.Button("Apply", skin.button) == true)
            {
                item.isChanged = false;
                GUI.changed    = true;

                if (onReset != null)
                {
                    onReset.Invoke();
                }
            }
            UnityEditor.EditorGUI.EndDisabledGroup();

            UnityEditor.EditorGUI.BeginDisabledGroup(item.processing);
            {
                var newState = UnityEditor.EditorGUILayout.ToggleLeft(string.Format("Show {0}", (item.processing == true ? "(Processing...)" : string.Empty)), item.show);
                if (newState != item.show && item.processing == false)
                {
                    item.processing = true;

                    if (newState == true)
                    {
                        if (onReset != null)
                        {
                            onReset.Invoke();
                        }

                        // Connecting
                        this.OnEditorAuth(this.GetAuthKey(item), (result) => {
                            UnityEditor.EditorApplication.delayCall += () => {
                                Debug.Log("Stat Editor Connected!");
                                item.show       = result;
                                item.processing = false;
                            };
                        });
                        UnityEditor.EditorApplication.delayCall += () => this.Update();
                    }
                    else
                    {
                        // Disconnecting
                        this.OnEditorDisconnect((result) => {
                            item.show       = false;
                            item.processing = false;
                            if (onReset != null)
                            {
                                onReset.Invoke();
                            }
                        });
                        UnityEditor.EditorApplication.delayCall += () => this.Update();
                    }
                }
            }
            UnityEditor.EditorGUI.EndDisabledGroup();

            if (GUI.changed == true)
            {
                UnityEditor.EditorUtility.SetDirty(settings);
            }

            GUI.changed = wasChanged;
        }