private void DrawScreenChooser(float width)
        {
            var screens = new string[this.screens.Count + 1];

            screens[0] = "None";
            for (int i = 1; i < screens.Length; ++i)
            {
                screens[i] = this.screens[i - 1].name.Replace("Screen", string.Empty);
            }

            GUILayout.Label("Use existing screen:");

            var index = this.screenPrefab == null ? 0 : (System.Array.IndexOf(screens, this.screenPrefab.name.Replace("Screen", string.Empty)));

            index = EditorGUILayout.Popup(index, screens);
            if (index > 0)
            {
                this.screenPrefab = this.screens[index - 1];
            }

            this.screenPrefab = EditorGUILayout.ObjectField(this.screenPrefab, typeof(WindowBase), false) as WindowBase;
            if (GUILayout.Button("Load") == true)
            {
                this.LoadScreen(this.screenPrefab);
            }

            GUILayout.Label("Or create the new one:");

            if (GUILayout.Button("Create Screen...", GUILayout.Height(30f)) == true)
            {
                this.showScreenWindow = true;
            }

            if (Event.current.type == EventType.Repaint && this.showScreenWindow == true)
            {
                this.showScreenWindow = false;

                var commentStyle = new GUIStyle(EditorStyles.miniLabel);
                commentStyle.wordWrap = true;

                var rect = GUILayoutUtility.GetLastRect();
                rect.x += this.mainRect.x + this.currentView.position.x - this.scrollPosition.x + this.lastRect.x;
                rect.y += this.mainRect.y + this.currentView.position.y + rect.height - this.scrollPosition.y + this.lastRect.y + 15f;
                FlowDropDownFilterWindow.Show <FlowLayoutWindowTypeTemplate>(rect, (screen) => {
                    this.screenPrefab = FlowDatabase.GenerateScreen(this.window, screen);
                    this.ReloadScreens();
                    this.LoadScreen(this.screenPrefab);

                    this.isScreenDirty = true;
                }, (screen) => {
                    GUILayout.Label(screen.comment, commentStyle);
                }, strongType: true);

                Event.current.Use();
            }
        }
Esempio n. 2
0
        public static void CreateScreen(Object activeObject, string namespaceName, string localPath = "", System.Action callback = null)
        {
            var obj  = activeObject;
            var path = AssetDatabase.GetAssetPath(obj.GetInstanceID()) + localPath;

            FlowChooserFilterWindow.Show <FlowLayoutWindowTypeTemplate>(null, (element) => {
                // on select
                var splitted = path.Split('/');
                var _path    = string.Join("/", splitted, 0, splitted.Length - 1).Trim('/');

                var className = string.Empty;
                var files     = AssetDatabase.FindAssets("t:MonoScript", new string[] { _path });

                foreach (var file in files)
                {
                    var data = AssetDatabase.GUIDToAssetPath(file);
                    var sp   = data.Split('/');
                    var last = sp[sp.Length - 1];
                    if (last.EndsWith("Base.cs") == true)
                    {
                        className = last.Replace("Base.cs", string.Empty);
                    }
                }

                if (string.IsNullOrEmpty(className) == false)
                {
                    var name = className;
                    // Create an instance
                    var layoutPrefab = FlowDatabase.GenerateScreen(path + "/" + name + ".prefab", className, namespaceName, element);

                    Selection.activeObject = layoutPrefab;
                }

                if (callback != null)
                {
                    callback();
                }
            }, (element) => {
                // on gui

                var style      = new GUIStyle(GUI.skin.label);
                style.wordWrap = true;

                GUILayout.Label(element.comment, style);
            }, strongType: true);
        }