コード例 #1
0
        public static void CreateLayout()
        {
            LayoutWindowType layoutScreen = null;

            var name = string.Empty;

            var obj  = Selection.activeObject;
            var path = AssetDatabase.GetAssetPath(obj.GetInstanceID());

            if (path.Length > 0 && Directory.Exists(path) == true)
            {
            }
            else if (Selection.activeGameObject != null)
            {
                var screen = Selection.activeGameObject.GetComponent <WindowBase>();
                if (screen != null)
                {
                    var splitted = path.Split('/');
                    path = string.Join("/", splitted, 0, splitted.Length - 2).Trim('/');

                    path = path + "/Layouts";
                    if (Directory.Exists(path) == true)
                    {
                        layoutScreen = screen as LayoutWindowType;
                        name         = layoutScreen.name.Replace("Screen", "Layout");
                    }
                }
            }

            FlowChooserFilterWindow.Show <FlowWindowLayoutTemplate>(null, (element) => {
                // on select

                if (string.IsNullOrEmpty(name) == true)
                {
                    name = element.name + "Layout";
                }

                // Create an instance
                var layoutPrefab = FlowDatabase.GenerateLayout(path + "/" + name + ".prefab", element);

                if (layoutScreen != null)
                {
                    layoutScreen.layout.layout = layoutPrefab;
                    layoutScreen.OnValidate();
                    EditorUtility.SetDirty(layoutScreen);
                }

                Selection.activeObject = layoutPrefab;
            }, (element) => {
                // on gui

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

                GUILayout.Label(element.comment, style);
            }, strongType: true);
        }
コード例 #2
0
        private void DrawLayoutChooser(float width)
        {
            if (this.screenInstance == null)
            {
                return;
            }

            var layouts = new string[this.layouts.Count + 1];

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

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

            var index = this.layoutPrefab == null ? 0 : (System.Array.IndexOf(layouts, this.layoutPrefab.name.Replace("Layout", string.Empty)));

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

            this.layoutPrefab = EditorGUILayout.ObjectField(this.layoutPrefab, typeof(WindowLayout), false) as WindowLayout;
            if (GUILayout.Button("Load") == true)
            {
                this.LoadLayout(this.layoutPrefab);
            }

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

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

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

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

                FlowChooserFilterWindow.Show <FlowWindowLayoutTemplate>(this.rootWindow, (layout) => {
                    this.layoutPrefab = FlowDatabase.GenerateLayout(this.window, layout);
                    this.ReloadLayouts();
                    this.LoadLayout(this.layoutPrefab);

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