public void OnEnable()
        {
            SceneView.onSceneGUIDelegate -= this.OnSceneView;
            SceneView.onSceneGUIDelegate += this.OnSceneView;

            this._target = this.target as WindowLayoutElement;
            if (this._target == null)
            {
                return;
            }

            this.layout = this._target.GetComponentInParent <WindowLayout>();

            if (this._target != null)
            {
                this.lastPivot = (this._target.transform as RectTransform).pivot;
            }
        }
Ejemplo n.º 2
0
        public void Add(int tag, WindowLayout windowLayout)
        {
            for (int i = 0; i < this.components.Length; ++i)
            {
                if (this.components[i].tag == tag && this.components[i].windowLayout == windowLayout)
                {
                    return;
                }
            }

            var list = this.components.ToList();

            list.Add(new LayoutComponentItem()
            {
                component         = new Resource(),
                componentInstance = null,
                tag          = tag,
                localTag     = ++this.localTag,
                windowLayout = windowLayout,
            });
            this.components = list.ToArray();
        }
        private void LoadLayout(WindowLayout layoutPrefab)
        {
            if (layoutPrefab != null)
            {
                if (this.layoutInstance != null)
                {
                    GameObject.DestroyImmediate(this.layoutInstance.gameObject);
                }

                // Loading layout
                this.layoutInstance = FlowDatabase.LoadLayout(layoutPrefab);
                this.layoutInstance.transform.position   = Vector3.zero;
                this.layoutInstance.transform.rotation   = Quaternion.identity;
                this.layoutInstance.transform.localScale = Vector3.zero;

                if ((this.screenInstance as LayoutWindowType) != null)
                {
                    var layoutScreen = this.screenInstance as LayoutWindowType;
                    layoutScreen.layout.layout = layoutPrefab;
                    this.isScreenDirty         = true;
                }
            }
        }
Ejemplo n.º 4
0
        void SetupLayout(SerializedObject tutorial)
        {
            // Ensure tutorial window is not open
            foreach (var window in Resources.FindObjectsOfTypeAll <TutorialWindow>())
            {
                window.Close();
            }

            Assert.That(Resources.FindObjectsOfTypeAll <TestWindow1>(), Is.Empty, "TestWindow1 is present");

            // Save current layout and use it as the tutorial layout
            m_TutorialLayoutPath = m_TempFolderPath + "/TutorialLayout.dwlt";
            WindowLayout.SaveWindowLayout(m_TutorialLayoutPath);
            AssetDatabase.Refresh();
            var tutorialLayout       = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(m_TutorialLayoutPath);
            var windowLayoutProperty = tutorial.FindProperty("m_WindowLayout");

            windowLayoutProperty.objectReferenceValue = tutorialLayout;

            // Open TestWindow1
            EditorWindow.GetWindow <TestWindow1>();

            Assert.That(Resources.FindObjectsOfTypeAll <TestWindow1>(), Is.Not.Empty, "TestWindow1 is not present");
        }
Ejemplo n.º 5
0
        public void Create(WindowBase window, Transform root, float depth, int raycastPriority, int orderInLayer)
        {
            var instance = this.layout.Spawn();

            instance.transform.SetParent(root);
            instance.transform.localPosition = Vector3.zero;
            instance.transform.localRotation = Quaternion.identity;
            instance.transform.localScale    = Vector3.one;

            var rect = instance.transform as RectTransform;

            rect.sizeDelta        = (this.layout.transform as RectTransform).sizeDelta;
            rect.anchoredPosition = (this.layout.transform as RectTransform).anchoredPosition;

            instance.Setup(window);
            instance.Init(depth, raycastPriority, orderInLayer, this.scaleMode);

            this.instance = instance;

            foreach (var component in this.components)
            {
                component.Create(window, instance.GetRootByTag(component.tag));
            }
        }
        internal void Update_EDITOR(LayoutWindowType layoutWindow)
        {
            if (this.layout == null)
            {
                return;
            }

            this.layout.GetTags(this.tags);

            foreach (var tag in this.tags)
            {
                this.AddComponentLink(tag);
            }

            this.components = this.components.Distinct(new ComponentComparer()).ToArray();

            // Used
            for (int i = 0; i < this.components.Length; ++i)
            {
                this.components[i].OnValidate();

                this.components[i].UpdateDescription(layoutWindow);

                var index = this.tags.IndexOf(this.components[i].tag);
                if (index == -1)
                {
                    this.RemoveComponentLink(this.components[i].tag);
                    continue;
                }
                this.tags.RemoveAt(index);
            }

            this.layoutResource.tempObject = this.layout;
            this.layoutResource.Validate();
            this.layoutNoResource = (this.layoutResource.IsLoadable() == true ? null : this.layout);
        }
Ejemplo n.º 7
0
 public static void ReloadWindowLayoutMenu()
 {
     WindowLayout.ReloadWindowLayoutMenu();
 }
Ejemplo n.º 8
0
 public static WindowLayout LoadLayout(WindowLayout prefab)
 {
     return(UnityEditor.PrefabUtility.InstantiatePrefab(prefab) as WindowLayout);
 }
Ejemplo n.º 9
0
        public static IntPtr StartProgram(string workingDirectory, DemoAppLauncherSelection app, BrokerAppType subApp, WindowLayout wp)
        {
            var startInfo = new ProcessStartInfo("dotnet");

            startInfo.Arguments        = $"run --no-build {app.ToString()} {subApp.ToString()}";
            startInfo.UseShellExecute  = true;
            startInfo.WorkingDirectory = workingDirectory;

            var process = new Process();

            process.StartInfo = startInfo;
            process.Start();
            Thread.Sleep(500);
            var handle = process.MainWindowHandle;

            if (!MoveWindow((IntPtr)handle, wp.StartX, wp.StartY, wp.Width, wp.Height, true))
            {
                throw new Win32Exception();
            }

            return((IntPtr)handle);
        }
Ejemplo n.º 10
0
 public static void LoadDefaultLayout()
 {
     WindowLayout.LoadDefaultLayout();
 }
        public void Create(WindowBase window, Transform root, float depth, int raycastPriority, int orderInLayer, System.Action callback, bool async)
        {
            if (this.stopped == true)
            {
                return;
            }

            this.window = window;

            System.Action <WindowLayout> onLoaded = (layout) => {
                if (this.stopped == true)
                {
                    return;
                }

                var instance = layout.Spawn(activeByDefault: false);
                instance.transform.SetParent(root);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = Quaternion.identity;
                instance.transform.localScale    = Vector3.one;

                var rect = instance.transform as RectTransform;
                rect.sizeDelta        = (layout.transform as RectTransform).sizeDelta;
                rect.anchoredPosition = (layout.transform as RectTransform).anchoredPosition;

                var layoutPreferences = this.layoutPreferences;
                if (this.allowCustomLayoutPreferences == true)
                {
                    layoutPreferences = WindowSystem.GetCustomLayoutPreferences() ?? this.layoutPreferences;
                }

                instance.Setup(window);
                instance.Init(depth, raycastPriority, orderInLayer);
                instance.SetLayoutPreferences(this.scaleMode, this.fixedScaleResolution, layoutPreferences);

                this.instance = instance;

                ME.Utilities.CallInSequence(() => {
                    if (this.stopped == true)
                    {
                        return;
                    }

                    instance.gameObject.SetActive(true);
                    callback.Invoke();
                }, this.components, (component, c) => {
                    component.Create(window, instance.GetRootByTag(component.tag), (comp) => c.Invoke(), async);
                }, waitPrevious: true);
            };

            WindowLayout loadedComponent = null;

            if (this.layoutResource.IsLoadable() == true)
            {
                WindowSystemResources.LoadRefCounter <WindowLayout>(this, (layout) => {
                    loadedComponent = layout;
                    onLoaded.Invoke(loadedComponent);

                    WindowSystemResources.Unload(this, this.GetResource(), resetController: false);
                }, () => {
                                        #if UNITY_EDITOR
                    Debug.LogWarningFormat("[ Layout ] Resource request failed {0} [{1}].", UnityEditor.AssetDatabase.GetAssetPath(this.layout.GetInstanceID()), window.name);
                                        #endif
                }, async);
                return;
            }
            else
            {
                loadedComponent = this.layoutNoResource;
                                #if UNITY_EDITOR
                if (loadedComponent != null)
                {
                    Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", loadedComponent.name, UnityEditor.AssetDatabase.GetAssetPath(loadedComponent.GetInstanceID()), window.name);
                }
                                #endif
            }

            onLoaded.Invoke(loadedComponent);
        }
 public static void SaveWindowLayout(string path)
 {
     WindowLayout.SaveWindowLayout(path);
 }
Ejemplo n.º 13
0
        private IEnumerator InitLayoutInstance(LayoutWindowType windowInstance, WindowObject root, WindowLayout windowLayout, HashSet <WindowLayout> used, System.Action onComplete, bool isInner = false)
        {
            if (((ILayoutInstance)root).windowLayoutInstance != null)
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
                yield break;
            }

            if (windowLayout.createPool == true)
            {
                WindowSystem.GetPools().CreatePool(windowLayout);
            }
            var windowLayoutInstance = WindowSystem.GetPools().Spawn(windowLayout, root.transform);

            windowLayoutInstance.isRootLayout = (isInner == false);

            if (isInner == true)
            {
                windowLayoutInstance.canvasScaler.enabled = false;
            }

            windowLayoutInstance.Setup(windowInstance);
            windowLayoutInstance.SetCanvasOrder(0);
            root.RegisterSubObject(windowLayoutInstance);
            ((ILayoutInstance)root).windowLayoutInstance = windowLayoutInstance;
            this.ApplyLayoutPreferences(this.layoutPreferences);

            windowLayoutInstance.SetTransformFullRect();

            used.Add(this.windowLayout);
            var arr = this.components;

            for (int i = 0; i < arr.Length; ++i)
            {
                var layoutComponent = arr[i];
                if (layoutComponent.windowLayout != windowLayout)
                {
                    continue;
                }

                var layoutElement = windowLayoutInstance.GetLayoutElementByTagId(layoutComponent.tag);
                if (layoutComponent.componentInstance == null)
                {
                    layoutElement.Setup(windowInstance);

                    if (layoutComponent.component.IsEmpty() == false)
                    {
                        var index     = i;
                        var resources = WindowSystem.GetResources();
                        var loaded    = false;
                        yield return(resources.LoadAsync <WindowComponent>(windowInstance, layoutComponent.component, (asset) => {
                            if (asset == null)
                            {
                                Debug.LogWarning("Component is null while component resource not empty. Skipped.");
                                return;
                            }

                            var instance = layoutElement.Load(asset);
                            instance.SetInvisible();
                            layoutComponent.componentInstance = instance;
                            arr[index] = layoutComponent;

                            instance.DoLoadScreenAsync(() => { loaded = true; });
                        }));

                        while (loaded == false)
                        {
                            yield return(null);
                        }
                    }

                    arr[i] = layoutComponent;
                }

                if (layoutElement.innerLayout != null)
                {
                    if (used.Contains(layoutElement.innerLayout) == false)
                    {
                        yield return(this.InitLayoutInstance(windowInstance, layoutElement, layoutElement.innerLayout, used, null, isInner: true));
                    }
                    else
                    {
                        Debug.LogWarning("Ignoring inner layout because of a cycle");
                    }
                }
            }

            if (onComplete != null)
            {
                onComplete.Invoke();
            }
        }
Ejemplo n.º 14
0
        public bool SaveWindowLayout(WindowLayout newWindowLayout)
        {
            var newInstance = new Config(this.Instance.Locations, this.Instance.Services, newWindowLayout, this.Instance.RouterSettings, this.Instance.MainLayout, this.Instance.PositionSettings);

            return(SaveInternal(newInstance, false));
        }
Ejemplo n.º 15
0
 public static void ReloadWindowLayoutMenu()
 {
     WindowLayout.ReloadWindowLayoutMenu();
     EditorUtility.Internal_UpdateAllMenus();
 }
Ejemplo n.º 16
0
        public bool OnPreviewGUI(Rect rect, GUIStyle buttonStyle, GUIStyle background, bool drawInfo, bool selectable, System.Action onCreateScreen, System.Action onCreateLayout)
        {
            WindowLayoutElement.waitForComponentConnectionTemp = false;

            var screenInfo = this.GetScreen();

            if (screenInfo != null && screenInfo.IsEmpty() == false && screenInfo.IsType <LayoutWindowType>() == false)
            {
                UnityEditor.EditorGUI.HelpBox(rect, "This window doesn't have `LayoutWindowType` inheritance.", UnityEditor.MessageType.Info);
            }
            else
            {
                if (screenInfo != null && screenInfo.IsEmpty() == false && screenInfo.Load <LayoutWindowType>().GetCurrentLayout().layout != null)
                {
                    var screen = screenInfo.Load <LayoutWindowType>();
                    var layout = screen.GetCurrentLayout().layout;
                    if (layout != null)
                    {
                        if (this.editorCacheScreen != screen || this.editorCacheLayout != layout)
                        {
                            this.editorCache = null;
                        }
                        this.editorCacheScreen = screen;
                        this.editorCacheLayout = layout;

                        if (this.editorCache == null)
                        {
                            this.editorCache = UnityEditor.Editor.CreateEditor(layout) as IPreviewEditor;
                        }
                        if (this.editorCache != null)
                        {
                            this.editorCache.OnPreviewGUI(Color.white, rect, background, drawInfo, selectable);
                        }

                        if (WindowLayoutElement.waitForComponentConnectionTemp == true)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    this.editorCache = null;

                    GUI.Box(rect, string.Empty, background);
                    if (this.compiled == false)
                    {
                        UnityEditor.EditorGUI.HelpBox(rect, "You need to compile window to start using layout functions.", UnityEditor.MessageType.Warning);
                    }
                    else
                    {
                        if (screenInfo != null && screenInfo.IsEmpty() == false)
                        {
                            var layout = screenInfo.Load <LayoutWindowType>().GetCurrentLayout().layout;
                            if (layout == null)
                            {
                                GUI.BeginGroup(rect);
                                {
                                    var width  = rect.width * 0.7f;
                                    var height = 50f;
                                    if (GUI.Button(new Rect(rect.width * 0.5f - width * 0.5f, rect.height * 0.5f - height * 0.5f, width, height), "Create Layout", buttonStyle) == true)
                                    {
                                        onCreateLayout();
                                    }
                                }
                                GUI.EndGroup();
                            }
                        }
                        else
                        {
                            GUI.BeginGroup(rect);
                            {
                                var width  = rect.width * 0.7f;
                                var height = 50f;
                                if (GUI.Button(new Rect(rect.width * 0.5f - width * 0.5f, rect.height * 0.5f - height * 0.5f, width, height), "Create Screen", buttonStyle) == true)
                                {
                                    onCreateScreen();
                                }
                            }
                            GUI.EndGroup();
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 17
0
 public static void RevertFactoryLayoutSettings(bool quitOnCancel)
 {
     WindowLayout.RevertFactorySettings(quitOnCancel);
 }
Ejemplo n.º 18
0
        public static void DrawLayout(int selectedIndexAspect, int selectedIndexInner, int selectedType, System.Action <int, int, int> onSet, ref Vector2 tabsScrollPosition, WindowLayout windowLayout, Rect r, UnityEngine.UI.Windows.WindowTypes.LayoutWindowType drawComponents)
        {
            var offset = 20f;
            var aspect = 4f / 3f;

            DeviceInfo.OrientationData orienData  = default;
            DeviceInfo.ScreenData      screenData = default;
            if (Selection.objects.Length == 1)
            {
                if (WindowLayoutUtilities.loadedDevices.Count == 0)
                {
                    var devices             = new List <DeviceInfo>();
                    var deviceDirectoryPath = System.IO.Path.GetFullPath(System.IO.Path.Combine("Packages", "com.unity.device-simulator", ".DeviceDefinitions"));
                    if (UnityEngine.Windows.Directory.Exists(deviceDirectoryPath) == true)
                    {
                        var deviceDirectory   = new System.IO.DirectoryInfo(deviceDirectoryPath);
                        var deviceDefinitions = deviceDirectory.GetFiles("*.device.json");
                        foreach (var deviceDefinition in deviceDefinitions)
                        {
                            string deviceFileText;
                            using (System.IO.StreamReader sr = deviceDefinition.OpenText()) {
                                deviceFileText = sr.ReadToEnd();
                            }

                            var deviceInfo = JsonUtility.FromJson <DeviceInfo>(deviceFileText);
                            devices.Add(deviceInfo);
                        }
                    }

                    WindowLayoutUtilities.loadedDevices = devices;
                }

                GUILayout.BeginHorizontal();

                var selectedName = "Default Aspects";
                if (selectedType == 1)
                {
                    var dInfo = WindowLayoutUtilities.loadedDevices[selectedIndexAspect];
                    selectedName = dInfo.friendlyName;
                }

                if (WindowLayoutUtilities.loadedDevices.Count > 0)
                {
                    if (GUILayout.Button(selectedName, EditorStyles.toolbarDropDown) == true)
                    {
                        var popup = new Popup(title: "Devices", size: new Vector2(200f, 250f));
                        popup.autoClose  = true;
                        popup.autoHeight = false;
                        popup.Item("Default Aspects", () => { onSet.Invoke(0, 0, 0); }, order: -1);

                        for (var i = 0; i < WindowLayoutUtilities.loadedDevices.Count; ++i)
                        {
                            var idx        = i;
                            var deviceInfo = WindowLayoutUtilities.loadedDevices[i];
                            var screens    = deviceInfo.Screens ?? deviceInfo.screens;
                            if (screens != null)
                            {
                                popup.Item(deviceInfo.friendlyName, () => { onSet.Invoke(1, idx, 0); }, order: idx);
                            }
                        }

                        popup.Show();
                    }
                }

                if (selectedType == 0)
                {
                    var items = new Item[] {
                        new Item()
                        {
                            name = "4:3", value = 4f / 3f
                        },
                        new Item()
                        {
                            name = "16:9", value = 16f / 9f
                        },
                        new Item()
                        {
                            name = "16:10", value = 16f / 10f
                        },
                        new Item()
                        {
                            name = "5:4", value = 5f / 4f
                        },
                        new Item()
                        {
                            name = "2:1", value = 2f / 1f
                        },

                        new Item()
                        {
                            name = "3:4", value = 3f / 4f
                        },
                        new Item()
                        {
                            name = "9:16", value = 9f / 16f
                        },
                        new Item()
                        {
                            name = "10:16", value = 10f / 16f
                        },
                        new Item()
                        {
                            name = "4:5", value = 4f / 5f
                        },
                        new Item()
                        {
                            name = "1:2", value = 1f / 2f
                        },
                    };

                    var tabs = items.Select(x => new GUITab(x.name, null)).ToArray();
                    selectedIndexAspect = GUILayoutExt.DrawTabs(selectedIndexAspect, ref tabsScrollPosition, tabs);
                    aspect = items[selectedIndexAspect].value;
                }
                else if (selectedType == 1)
                {
                    var deviceInfo = WindowLayoutUtilities.loadedDevices[selectedIndexAspect];
                    var screens    = deviceInfo.Screens ?? deviceInfo.screens;
                    var items      = new Item[4];
                    for (int i = 0; i < screens.Length; ++i)
                    {
                        var oris = screens[i].orientations;
                        for (int j = 0; j < oris.Length; ++j)
                        {
                            if (oris[j].orientation == ScreenOrientation.LandscapeRight)
                            {
                                var hData = screens[i];
                                var w     = hData.width;
                                hData.width  = hData.height;
                                hData.height = w;

                                items[0] = new Item()
                                {
                                    name       = "Landscape Right",
                                    value      = hData.width / (float)hData.height,
                                    data       = oris[j],
                                    screenData = hData
                                };
                            }
                            else if (oris[j].orientation == ScreenOrientation.Landscape ||
                                     oris[j].orientation == ScreenOrientation.LandscapeLeft)
                            {
                                var hData = screens[i];
                                var w     = hData.width;
                                hData.width  = hData.height;
                                hData.height = w;

                                items[1] = new Item()
                                {
                                    name       = "Landscape Left",
                                    value      = hData.width / (float)hData.height,
                                    data       = oris[j],
                                    screenData = hData
                                };
                            }
                            else if (oris[j].orientation == ScreenOrientation.Portrait)
                            {
                                items[2] = new Item()
                                {
                                    name       = "Portrait Up",
                                    value      = screens[i].width / (float)screens[i].height,
                                    data       = oris[j],
                                    screenData = screens[i]
                                };
                            }
                            else if (oris[j].orientation == ScreenOrientation.PortraitUpsideDown)
                            {
                                items[3] = new Item()
                                {
                                    name       = "Portrait Down",
                                    value      = screens[i].width / (float)screens[i].height,
                                    data       = oris[j],
                                    screenData = screens[i]
                                };
                            }
                        }
                    }

                    var tabs = items.Select(x => new GUITab(x.name, null)).ToArray();
                    selectedIndexInner = GUILayoutExt.DrawTabs(selectedIndexInner, ref tabsScrollPosition, tabs);
                    aspect             = items[selectedIndexInner].value;
                    orienData          = items[selectedIndexInner].data;
                    screenData         = items[selectedIndexInner].screenData;
                }

                GUILayout.EndHorizontal();
            }
            else
            {
                offset = 0f;
            }

            var used = new HashSet <WindowLayout>();

            WindowLayoutUtilities.DrawLayout(aspect, windowLayout, r, offset, used, screenData, orienData, drawComponents);

            onSet.Invoke(selectedType, selectedIndexAspect, selectedIndexInner);
        }
        private void DrawLayoutItem(WindowBase screen, WindowLayout layout, UnityEngine.UI.Windows.Types.Layout.Component component, float width)
        {
            if (layout == null)
            {
                return;
            }

            var tempComponent = layout.elements.FirstOrDefault((e) => e != null && e.tag == component.tag);
            var selected      = (Selection.activeGameObject == tempComponent.gameObject);
            var oldColor      = GUI.color;

            var boxStyle = new GUIStyle(EditorStyles.toolbar);

            boxStyle.fixedHeight   = 0f;
            boxStyle.stretchHeight = true;
            boxStyle.padding.right = -20;
            boxStyle.margin.right  = -20;

            var titleStyle = EditorStyles.whiteMiniLabel;

            EditorGUILayout.Separator();

            GUI.color = selected == true ? new Color(0.7f, 1f, 0.7f, 1f) : Color.white;
            EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(width));

            if (GUILayout.Button(component.tag.ToString() + " (" + component.description + ")", titleStyle, GUILayout.Width(width)) == true)
            {
                Selection.activeGameObject = tempComponent.gameObject;
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Order:", GUILayout.Width(50f));
            var newOrder = EditorGUILayout.IntField(component.sortingOrder, EditorStyles.miniTextField, GUILayout.Width(50f));

            if (newOrder != component.sortingOrder)
            {
                component.sortingOrder = newOrder;
                this.isScreenDirty     = true;
            }

            if (component.sortingOrder == 0)
            {
                GUILayout.Label("(Auto)", EditorStyles.miniLabel);
            }
            else
            {
                if (GUILayout.Button("Set Auto", EditorStyles.miniButton) == true)
                {
                    component.sortingOrder = 0;
                    this.isScreenDirty     = true;
                }
            }

            EditorGUILayout.EndHorizontal();

            var newComponent = EditorGUILayout.ObjectField(component.component, typeof(WindowComponent), false, GUILayout.Width(width)) as WindowComponent;

            if (newComponent != component.component)
            {
                component.component = newComponent;
                this.isScreenDirty  = true;
            }

            tempComponent.tempEditorComponent = component.component;

            EditorGUILayout.EndVertical();
            var rect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) == true)
            {
                Selection.activeGameObject = tempComponent.gameObject;
            }

            GUI.color = oldColor;
        }
Ejemplo n.º 20
0
        public static bool DrawLayout(float aspect, WindowLayout windowLayout, Rect r, float offset = 20f, HashSet <WindowLayout> used = null, DeviceInfo.ScreenData screenData = default, DeviceInfo.OrientationData orientationData = default, UnityEngine.UI.Windows.WindowTypes.LayoutWindowType drawComponents = null)
        {
            if (used.Contains(windowLayout) == true)
            {
                return(false);
            }
            used.Add(windowLayout);

            var rSource = r;

            var rectOffset = r;

            if (offset > 0f)
            {
                rectOffset.x      += offset;
                rectOffset.y      += offset;
                rectOffset.height -= offset * 2f;
                rectOffset.width  -= offset * 2f;

                var tWidth = rectOffset.height * aspect;
                if (tWidth > rectOffset.width)
                {
                    rectOffset.y     += rectOffset.height * 0.5f;
                    rectOffset.height = rectOffset.width / aspect;
                    rectOffset.y     -= rectOffset.height * 0.5f;
                }
                else
                {
                    rectOffset.x    += rectOffset.width * 0.5f;
                    rectOffset.width = rectOffset.height * aspect;
                    rectOffset.x    -= rectOffset.width * 0.5f;
                }
            }
            else
            {
                GUILayoutExt.DrawRect(rectOffset, new Color(0f, 0f, 0f, 0.4f));
            }

            GUILayoutExt.DrawRect(rectOffset, new Color(0f, 0f, 0f, 0.2f));
            GUILayoutExt.DrawBoxNotFilled(rectOffset, 1f, new Color(0.7f, 0.7f, 0.3f, 0.5f));

            GUI.BeginClip(r);

            var resolution = windowLayout.canvasScaler.referenceResolution;

            /*windowLayout.rectTransform.anchoredPosition = new Vector2(r.x, r.y);
             * windowLayout.rectTransform.sizeDelta = new Vector2(r.width, r.height);
             * windowLayout.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
             * windowLayout.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
             * windowLayout.rectTransform.pivot = new Vector2(0.5f, 0.5f);
             * windowLayout.rectTransform.localRotation = Quaternion.identity;
             * windowLayout.rectTransform.localScale = Vector3.one;*/

            r = rectOffset;

            {
                if (r.width > 0f && r.height > 0f)
                {
                    Vector2 screenSize = new Vector2(r.width, r.height);

                    var   sizeDelta   = Vector2.zero;
                    float scaleFactor = 0;
                    switch (windowLayout.canvasScaler.screenMatchMode)
                    {
                    case UnityEngine.UI.CanvasScaler.ScreenMatchMode.MatchWidthOrHeight: {
                        const float kLogBase = 2;
                        // We take the log of the relative width and height before taking the average.
                        // Then we transform it back in the original space.
                        // the reason to transform in and out of logarithmic space is to have better behavior.
                        // If one axis has twice resolution and the other has half, it should even out if widthOrHeight value is at 0.5.
                        // In normal space the average would be (0.5 + 2) / 2 = 1.25
                        // In logarithmic space the average is (-1 + 1) / 2 = 0
                        float logWidth           = Mathf.Log(screenSize.x / windowLayout.canvasScaler.referenceResolution.x, kLogBase);
                        float logHeight          = Mathf.Log(screenSize.y / windowLayout.canvasScaler.referenceResolution.y, kLogBase);
                        float logWeightedAverage = Mathf.Lerp(logWidth, logHeight, windowLayout.canvasScaler.matchWidthOrHeight);
                        scaleFactor = Mathf.Pow(kLogBase, logWeightedAverage);
                        break;
                    }

                    case UnityEngine.UI.CanvasScaler.ScreenMatchMode.Expand: {
                        scaleFactor = Mathf.Min(screenSize.x / windowLayout.canvasScaler.referenceResolution.x, screenSize.y / windowLayout.canvasScaler.referenceResolution.y);
                        break;
                    }

                    case UnityEngine.UI.CanvasScaler.ScreenMatchMode.Shrink: {
                        scaleFactor = Mathf.Max(screenSize.x / windowLayout.canvasScaler.referenceResolution.x, screenSize.y / windowLayout.canvasScaler.referenceResolution.y);
                        break;
                    }
                    }

                    if (scaleFactor > 0f)
                    {
                        sizeDelta = new Vector2(screenSize.x / scaleFactor, screenSize.y / scaleFactor);
                        windowLayout.rectTransform.sizeDelta  = sizeDelta;
                        windowLayout.rectTransform.pivot      = new Vector2(0.5f, 0.5f);
                        windowLayout.rectTransform.localScale = Vector3.one;
                        resolution = windowLayout.rectTransform.sizeDelta;
                    }
                }
            }

            var labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.alignment = TextAnchor.LowerLeft;

            var isHighlighted    = false;
            var highlightedIndex = -1;
            var highlightedRect  = Rect.zero;

            for (int i = 0; i < windowLayout.layoutElements.Length; ++i)
            {
                var element = windowLayout.layoutElements[i];
                if (element == null)
                {
                    windowLayout.ValidateEditor();
                    return(false);
                }

                var rect = WindowLayoutUtilities.GetRect(windowLayout.rectTransform, element.rectTransform, r, resolution, offset > 0f);
                if (rect.Contains(Event.current.mousePosition) == true)
                {
                    if (highlightedIndex >= 0 && highlightedRect.width * highlightedRect.height < rect.width * rect.height)
                    {
                        continue;
                    }

                    highlightedIndex = i;
                    highlightedRect  = rect;
                    isHighlighted    = true;
                }
            }

            var hasInnerHighlight = false;

            for (int i = 0; i < windowLayout.layoutElements.Length; ++i)
            {
                var element = windowLayout.layoutElements[i];
                var rect    = WindowLayoutUtilities.GetRect(windowLayout.rectTransform, element.rectTransform, r, resolution, offset > 0f);

                using (new GUILayoutExt.GUIColorUsing(highlightedIndex < 0 || i == highlightedIndex ? Color.white : new Color(1f, 1f, 1f, 0.6f))) {
                    if (drawComponents != null)
                    {
                        drawComponents.layouts.GetActive().GetLayoutComponentItemByTagId(element.tagId, windowLayout, out var componentItem);
                        var comp = componentItem.component.GetEditorRef <WindowComponent>();
                        if (comp != null)
                        {
                            WindowLayoutUtilities.DrawComponent(rect, comp, componentItem.localTag);
                        }

                        WindowSystemSidePropertyDrawer.DrawLayoutMode(rect, element.rectTransform);
                    }
                    else
                    {
                        WindowSystemSidePropertyDrawer.DrawLayoutMode(rect, element.rectTransform);
                    }
                }

                if (element.innerLayout != null)
                {
                    hasInnerHighlight = WindowLayoutUtilities.DrawLayout(aspect, element.innerLayout, rect, offset: 0f, used: used, drawComponents: drawComponents);
                    //WindowLayoutUtilities.DrawLayoutElements(highlightedIndex, rect, resolution, element.innerLayout, used);
                }
            }

            if (highlightedIndex >= 0 && hasInnerHighlight == false)
            {
                var element = windowLayout.layoutElements[highlightedIndex];
                var rect    = highlightedRect;

                var padding = 6f;
                var color   = new Color(1f, 1f, 0f, 0.5f);
                var content = new GUIContent(element.name);
                GUI.Label(new Rect(padding, 0f, rSource.width, rSource.height - padding), content, labelStyle);
                var labelWidth = labelStyle.CalcSize(content).x + 10f;
                GUILayoutExt.DrawRect(new Rect(padding, rSource.height - 1f - padding, labelWidth, 1f), color);
                var p1 = new Vector3(labelWidth + padding, rSource.height - 1f - padding);
                var p2 = new Vector3(rect.x, rect.y);
                Handles.color = color;
                Handles.DrawLine(p1, p2);

                GUILayoutExt.DrawBoxNotFilled(rect, 1f, new Color(1f, 1f, 1f, 0.2f));
            }

            GUI.EndClip();

            if (offset > 0f)
            {
                if (orientationData.cutouts != null)
                {
                    var safeArea = new Rect(orientationData.safeArea);
                    safeArea = WindowLayoutUtilities.GetRectYSwapScaled(safeArea, new Vector2(screenData.width, screenData.height), r, rectOffset);
                    GUILayoutExt.DrawBoxNotFilled(safeArea, 1f, Color.magenta);

                    foreach (var rSafe in orientationData.cutouts)
                    {
                        var rSafeRect = WindowLayoutUtilities.GetRectYSwapScaled(rSafe, new Vector2(screenData.width, screenData.height), r, rectOffset);
                        GUI.BeginClip(rSafeRect);

                        if (rSafeRect.width < rSafeRect.height)
                        {
                            for (float step = -rSafeRect.height; step < rSafeRect.height; step += 5f)
                            {
                                var v1 = new Vector3(0f, step);
                                var v2 = new Vector3(rSafeRect.width, step + rSafeRect.width);
                                Handles.color = Color.yellow;
                                Handles.DrawAAPolyLine(2f, v1, v2);
                            }
                        }
                        else
                        {
                            for (float step = -rSafeRect.width; step < rSafeRect.width; step += 5f)
                            {
                                var v1 = new Vector3(step, 0f);
                                var v2 = new Vector3(step + rSafeRect.height, rSafeRect.height);
                                Handles.color = Color.yellow;
                                Handles.DrawAAPolyLine(2f, v1, v2);
                            }
                        }

                        GUI.EndClip();
                        GUILayoutExt.DrawBoxNotFilled(rSafeRect, 1f, Color.yellow);
                    }
                }
            }

            return(isHighlighted);
        }
 public static void ShowGameView()
 {
     WindowLayout.ShowAppropriateViewOnEnterExitPlaymode(true);
 }
Ejemplo n.º 22
0
        private IEnumerator InitLayoutInstance(LayoutWindowType windowInstance, WindowObject root, WindowLayout windowLayout, HashSet <WindowLayout> used, System.Action onComplete, bool isInner = false)
        {
            if (((ILayoutInstance)root).windowLayoutInstance != null)
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
                yield break;
            }

            if (windowLayout.createPool == true)
            {
                WindowSystem.GetPools().CreatePool(windowLayout);
            }
            var windowLayoutInstance = WindowSystem.GetPools().Spawn(windowLayout, root.transform);

            windowLayoutInstance.isRootLayout = (isInner == false);

            if (isInner == true)
            {
                windowLayoutInstance.canvasScaler.enabled = false;
            }

            windowLayoutInstance.Setup(windowInstance);
            windowLayoutInstance.SetCanvasOrder(0);
            root.RegisterSubObject(windowLayoutInstance);
            ((ILayoutInstance)root).windowLayoutInstance = windowLayoutInstance;
            this.ApplyLayoutPreferences(this.layoutPreferences);

            windowLayoutInstance.SetTransformFullRect();

            used.Add(this.windowLayout);

            this.loadingCount = 0;
            var arr = this.components;

            for (int i = 0; i < arr.Length; ++i)
            {
                var layoutComponent = arr[i];
                if (layoutComponent.windowLayout != windowLayout)
                {
                    continue;
                }

                var layoutElement = windowLayoutInstance.GetLayoutElementByTagId(layoutComponent.tag);
                layoutComponent.componentInstance = windowLayoutInstance.GetLoadedComponent(layoutComponent.tag);
                layoutElement.Setup(windowInstance);
                arr[i] = layoutComponent;

                if (layoutComponent.componentInstance == null)
                {
                    if (layoutComponent.component.IsEmpty() == false)
                    {
                        var resources = WindowSystem.GetResources();
                        var data      = new LoadingClosure()
                        {
                            index   = i,
                            element = layoutElement,
                            windowLayoutInstance = windowLayoutInstance,
                            layoutComponentItems = arr,
                            instance             = this,
                        };
                        ++this.loadingCount;
                        yield return(resources.LoadAsync <WindowComponent, LoadingClosure>(windowInstance, data, layoutComponent.component, (asset, closure) => {
                            if (asset == null)
                            {
                                Debug.LogWarning("Component is null while component resource is not empty. Skipped.");
                                return;
                            }

                            ref var item = ref closure.layoutComponentItems[closure.index];

                            var instance = closure.element.Load(asset);
                            instance.SetInvisible();
                            closure.windowLayoutInstance.SetLoadedComponent(item.tag, instance);
                            item.componentInstance = instance;

                            instance.DoLoadScreenAsync(() => { --closure.instance.loadingCount; });
                        }));