Example #1
0
        public static ObjectCustomizationPopup ShowPopup(GameObject[] gameObjects)
        {
            if (window != null)
            {
                window.Close();
            }

            if (gameObjects == null || gameObjects.Length == 0)
            {
                Debug.LogWarning("No object has been selected.");
                return(null);
            }

            ObjectCustomizationPopup.gameObjects = gameObjects;

            Vector2 v2   = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
            Vector2 size = new Vector2(256, 138);

            window          = GetWindow <ObjectCustomizationPopup>(gameObjects[0].name);
            window.position = new Rect(v2.x - size.x - 30f, v2.y - size.y * 0.5f, size.x, size.y);
            window.maxSize  = window.minSize = size;
            window.ShowPopup();
            window.Focus();

            return(window);
        }
Example #2
0
        public static ObjectCustomizationPopup ShowPopup(GameObject gameObject)
        {
            if (Selection.gameObjects.Length > 1 || Selection.activeGameObject == null)
            {
                return(null);
            }

            if (window == null)
            {
                window = ObjectCustomizationPopup.GetWindow <ObjectCustomizationPopup>(gameObject.name);
            }
            else
            {
                window.Close();
                window = ObjectCustomizationPopup.GetWindow <ObjectCustomizationPopup>(gameObject.name);
            }

            Vector2 v2   = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
            Vector2 size = new Vector2(256, 138);

            window.position = new Rect(v2.x, v2.y, size.x, size.y);
            window.maxSize  = window.minSize = size;
            window.ShowPopup();
            window.Focus();

            ObjectCustomizationPopup objectCustomizationPopup = window as ObjectCustomizationPopup;

            return(objectCustomizationPopup);
        }
Example #3
0
        public VisualElement CreateShelfElement()
        {
            VisualElement shelfButton = new VisualElement();

            shelfButton.name    = nameof(OpenSettings);
            shelfButton.tooltip = "";
            shelfButton.StyleHeight(23);
            shelfButton.StyleJustifyContent(Justify.Center);
            Color c = EditorGUIUtility.isProSkin ? new Color32(32, 32, 32, 255) : new Color32(128, 128, 128, 255);

            shelfButton.StyleBorderColor(c);
            shelfButton.StyleBorderWidth(0, 0, 1, 0);

            shelfButton.Add(new Label("Custom Selection"));

            shelfButton.RegisterCallback <MouseDownEvent>((evt) =>
            {
                var isPrefabMode = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null ? true : false;
                if (isPrefabMode)
                {
                    Debug.LogWarning("Cannot custom object in prefab.");
                    evt.StopPropagation();
                    return;
                }

                if (Application.isPlaying)
                {
                    Debug.LogWarning("Cannot custom object in play mode.");
                    evt.StopPropagation();
                    return;
                }

                if (Selection.gameObjects.Length == 1 && Selection.activeGameObject != null)
                {
                    ObjectCustomizationPopup.ShowPopup(Selection.activeGameObject);
                }
                else
                {
                    if (Selection.gameObjects.Length > 1)
                    {
                        Debug.LogWarning("Only one object is allowed.");
                    }
                    else
                    {
                        Debug.LogWarning("No object has been selected.");
                    }
                }

                evt.StopPropagation();
            });

            shelfButton.RegisterCallback <MouseEnterEvent>((evt) =>
            {
                shelfButton.StyleBackgroundColor(new Color(.5f, .5f, .5f, .5f));
            });

            shelfButton.RegisterCallback <MouseLeaveEvent>((evt) => { shelfButton.StyleBackgroundColor(Color.clear); });

            return(shelfButton);
        }
Example #4
0
        public VisualElement CreateShelfElement()
        {
            VisualElement shelfButton = new VisualElement();

            shelfButton.name    = nameof(OpenSettings);
            shelfButton.tooltip = "";
            shelfButton.StyleHeight(23);
            shelfButton.StyleJustifyContent(Justify.Center);
            Color c = EditorGUIUtility.isProSkin ? new Color32(32, 32, 32, 255) : new Color32(128, 128, 128, 255);

            shelfButton.StyleBorderColor(c);
            shelfButton.StyleBorderWidth(0, 0, 1, 0);

            shelfButton.Add(new Label("Custom Selection"));

            shelfButton.RegisterCallback <MouseDownEvent>((evt) =>
            {
                var isPrefabMode = PrefabStageUtility.GetCurrentPrefabStage() != null ? true : false;
                if (isPrefabMode)
                {
                    Debug.LogWarning("Cannot custom object in prefab.");
                    shelfButton.parent.StyleDisplay(false);
                    evt.StopPropagation();
                    return;
                }

                if (Application.isPlaying)
                {
                    Debug.LogWarning("Cannot custom object in play mode.");
                    shelfButton.parent.StyleDisplay(false);
                    evt.StopPropagation();
                    return;
                }

                ObjectCustomizationPopup.ShowPopup(Selection.GetFiltered <GameObject>(SelectionMode.ExcludePrefab));
                Selection.activeGameObject = null;

                shelfButton.parent.StyleDisplay(false);
                evt.StopPropagation();
            });

            shelfButton.RegisterCallback <MouseEnterEvent>((evt) =>
            {
                shelfButton.StyleBackgroundColor(new Color(.5f, .5f, .5f, .5f));
            });

            shelfButton.RegisterCallback <MouseLeaveEvent>((evt) => { shelfButton.StyleBackgroundColor(Color.clear); });

            return(shelfButton);
        }