Example #1
0
        internal void OnGUI()
        {
            GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, "grey_border");
            GUILayout.Space(3);

            GUILayout.Label(Styles.header, EditorStyles.boldLabel);
            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.nameLabel, GUILayout.Width(90f));
            m_Name = EditorGUILayout.TextField(m_Name);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.gridLabel, GUILayout.Width(90f));
            m_Layout = (Grid.CellLayout)EditorGUILayout.EnumPopup(m_Layout);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.sizeLabel, GUILayout.Width(90f));
            m_CellSizing = (GridPalette.CellSizing)EditorGUILayout.EnumPopup(m_CellSizing);
            GUILayout.EndHorizontal();

            using (new EditorGUI.DisabledScope(m_CellSizing == GridPalette.CellSizing.Automatic))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(GUIContent.none, GUILayout.Width(90f));
                m_CellSize = EditorGUILayout.Vector3Field(GUIContent.none, m_CellSize);
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(5f);

            // Cancel, Ok
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button(Styles.cancel))
            {
                Close();
            }

            using (new EditorGUI.DisabledScope(String.IsNullOrEmpty(m_Name)))
            {
                if (GUILayout.Button(Styles.ok))
                {
                    GameObject go = GridPaletteUtility.CreateNewPaletteNamed(m_Name, m_Layout, m_CellSizing, m_CellSize);
                    if (go != null)
                    {
                        m_Owner.palette = go;
                        m_Owner.Repaint();
                    }
                    Close();
                    GUIUtility.ExitGUI();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();
        }
Example #2
0
        public void ResetPreviewInstance()
        {
            if (m_PreviewUtility == null)
            {
                InitPreviewUtility();
            }

            DestroyPreviewInstance();
            if (palette != null)
            {
                m_PaletteInstance = previewUtility.InstantiatePrefabInScene(palette);

                // Prevent palette from overriding the prefab while it is active, unless user saves the palette
                PrefabUtility.DisconnectPrefabInstance(m_PaletteInstance);

                EditorUtility.InitInstantiatedPreviewRecursive(m_PaletteInstance);
                m_PaletteInstance.transform.position   = new Vector3(0, 0, 0);
                m_PaletteInstance.transform.rotation   = Quaternion.identity;
                m_PaletteInstance.transform.localScale = Vector3.one;

                string      assetPath    = AssetDatabase.GetAssetPath(palette);
                GridPalette paletteAsset = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath);
                if (paletteAsset != null)
                {
                    if (paletteAsset.cellSizing == GridPalette.CellSizing.Automatic)
                    {
                        Grid grid = m_PaletteInstance.GetComponent <Grid>();
                        if (grid != null)
                        {
                            grid.cellSize = GridPaletteUtility.CalculateAutoCellSize(grid, grid.cellSize);
                        }
                        else
                        {
                            Debug.LogWarning("Grid component not found from: " + assetPath);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("GridPalette subasset not found from: " + assetPath);
                }

                foreach (var renderer in m_PaletteInstance.GetComponentsInChildren <Renderer>())
                {
                    renderer.gameObject.layer          = Camera.PreviewCullingLayer;
                    renderer.allowOcclusionWhenDynamic = false;
                }

                foreach (var transform in m_PaletteInstance.GetComponentsInChildren <Transform>())
                {
                    transform.gameObject.hideFlags = HideFlags.HideAndDontSave;
                }

                PreviewRenderUtility.SetEnabledRecursive(m_PaletteInstance, false);

                clipboardView.ResetPreviewMesh();
            }
        }
Example #3
0
 public void ResetPreviewInstance()
 {
     if (this.m_PreviewUtility == null)
     {
         this.InitPreviewUtility();
     }
     this.DestroyPreviewInstance();
     if (this.palette != null)
     {
         this.m_PaletteInstance = this.previewUtility.InstantiatePrefabInScene(this.palette);
         PrefabUtility.DisconnectPrefabInstance(this.m_PaletteInstance);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_PaletteInstance);
         this.m_PaletteInstance.transform.position   = new Vector3(0f, 0f, 0f);
         this.m_PaletteInstance.transform.rotation   = Quaternion.identity;
         this.m_PaletteInstance.transform.localScale = Vector3.one;
         string      assetPath   = AssetDatabase.GetAssetPath(this.palette);
         GridPalette gridPalette = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath);
         if (gridPalette != null)
         {
             if (gridPalette.cellSizing == GridPalette.CellSizing.Automatic)
             {
                 Grid component = this.m_PaletteInstance.GetComponent <Grid>();
                 if (component != null)
                 {
                     component.cellSize = GridPaletteUtility.CalculateAutoCellSize(component, component.cellSize);
                 }
                 else
                 {
                     Debug.LogWarning("Grid component not found from: " + assetPath);
                 }
             }
         }
         else
         {
             Debug.LogWarning("GridPalette subasset not found from: " + assetPath);
         }
         Renderer[] componentsInChildren = this.m_PaletteInstance.GetComponentsInChildren <Renderer>();
         for (int i = 0; i < componentsInChildren.Length; i++)
         {
             Renderer renderer = componentsInChildren[i];
             renderer.gameObject.layer          = Camera.PreviewCullingLayer;
             renderer.allowOcclusionWhenDynamic = false;
         }
         Transform[] componentsInChildren2 = this.m_PaletteInstance.GetComponentsInChildren <Transform>();
         for (int j = 0; j < componentsInChildren2.Length; j++)
         {
             Transform transform = componentsInChildren2[j];
             transform.gameObject.hideFlags = HideFlags.HideAndDontSave;
         }
         PreviewRenderUtility.SetEnabledRecursive(this.m_PaletteInstance, false);
         this.clipboardView.ResetPreviewMesh();
     }
 }
        public static GameObject CreateNewPaletteNamed(string name, GridLayout.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize)
        {
            string folder = (!ProjectBrowser.s_LastInteractedProjectBrowser) ? "Assets" : ProjectBrowser.s_LastInteractedProjectBrowser.GetActiveFolderPath();
            string text   = EditorUtility.SaveFolderPanel("Create palette into folder ", folder, "");

            text = FileUtil.GetProjectRelativePath(text);
            GameObject result;

            if (string.IsNullOrEmpty(text))
            {
                result = null;
            }
            else
            {
                result = GridPaletteUtility.CreateNewPalette(text, name, layout, cellSizing, cellSize);
            }
            return(result);
        }
        public static GameObject CreateNewPalette(string folderPath, string name, GridLayout.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize)
        {
            GameObject gameObject = new GameObject(name);
            Grid       grid       = gameObject.AddComponent <Grid>();

            grid.cellSize   = cellSize;
            grid.cellLayout = layout;
            GridPaletteUtility.CreateNewLayer(gameObject, "Layer1", layout);
            string text = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + name + ".prefab");

            UnityEngine.Object @object     = PrefabUtility.CreateEmptyPrefab(text);
            GridPalette        gridPalette = ScriptableObject.CreateInstance <GridPalette>();

            gridPalette.name       = "Palette Settings";
            gridPalette.cellSizing = cellSizing;
            AssetDatabase.AddObjectToAsset(gridPalette, @object);
            PrefabUtility.ReplacePrefab(gameObject, @object, ReplacePrefabOptions.Default);
            AssetDatabase.Refresh();
            UnityEngine.Object.DestroyImmediate(gameObject);
            return(AssetDatabase.LoadAssetAtPath <GameObject>(text));
        }
Example #6
0
        internal void OnGUI()
        {
            GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, "grey_border");
            GUILayout.Space(3);

            GUILayout.Label(Styles.header, EditorStyles.boldLabel);
            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.nameLabel, GUILayout.Width(90f));
            m_Name = EditorGUILayout.TextField(m_Name);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.gridLabel, GUILayout.Width(90f));
            m_Layout = (Grid.CellLayout)EditorGUILayout.EnumPopup(m_Layout);
            GUILayout.EndHorizontal();

            if (m_Layout == GridLayout.CellLayout.Hexagon)
            {
                GUILayout.BeginHorizontal();
                float oldLabelWidth = UnityEditor.EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 94;
                m_HexagonLayout             = EditorGUILayout.Popup(Styles.hexagonLabel, m_HexagonLayout, Styles.hexagonSwizzleTypeLabel);
                EditorGUIUtility.labelWidth = oldLabelWidth;
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.sizeLabel, GUILayout.Width(90f));
            m_CellSizing = (GridPalette.CellSizing)EditorGUILayout.EnumPopup(m_CellSizing);
            GUILayout.EndHorizontal();

            using (new EditorGUI.DisabledScope(m_CellSizing == GridPalette.CellSizing.Automatic))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(GUIContent.none, GUILayout.Width(90f));
                m_CellSize = EditorGUILayout.Vector3Field(GUIContent.none, m_CellSize);
                GUILayout.EndHorizontal();
            }

            GUILayout.FlexibleSpace();

            // Cancel, Ok
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button(Styles.cancel))
            {
                Close();
            }

            using (new EditorGUI.DisabledScope(!Utils.Paths.IsValidAssetPath(m_Name)))
            {
                if (GUILayout.Button(Styles.ok))
                {
                    var swizzle = Grid.CellSwizzle.XYZ;
                    if (m_Layout == GridLayout.CellLayout.Hexagon)
                    {
                        swizzle = Styles.hexagonSwizzleTypeValue[m_HexagonLayout];
                    }

                    GameObject go = GridPaletteUtility.CreateNewPaletteNamed(m_Name, m_Layout, m_CellSizing, m_CellSize, swizzle);
                    if (go != null)
                    {
                        m_Owner.palette = go;
                        m_Owner.Repaint();
                    }
                    GUIUtility.ExitGUI();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();
        }
        internal void OnGUI()
        {
            GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, "grey_border");
            GUILayout.Space(3);

            GUILayout.Label(Styles.header, EditorStyles.boldLabel);
            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.nameLabel, GUILayout.Width(90f));
            m_Name = EditorGUILayout.TextField(m_Name);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.gridLabel, GUILayout.Width(90f));
            EditorGUI.BeginChangeCheck();
            var newLayout = (Grid.CellLayout)EditorGUILayout.EnumPopup(m_Layout);

            if (EditorGUI.EndChangeCheck())
            {
                // Set useful user settings for certain layouts
                switch (newLayout)
                {
                case Grid.CellLayout.Rectangle:
                case Grid.CellLayout.Hexagon:
                {
                    m_CellSizing = GridPalette.CellSizing.Automatic;
                    m_CellSize   = new Vector3(1, 1, 0);
                    break;
                }

                case Grid.CellLayout.Isometric:
                case Grid.CellLayout.IsometricZAsY:
                {
                    m_CellSizing = GridPalette.CellSizing.Manual;
                    m_CellSize   = new Vector3(1, 0.5f, 1);
                    break;
                }
                }
                m_Layout = newLayout;
            }
            GUILayout.EndHorizontal();

            if (m_Layout == GridLayout.CellLayout.Hexagon)
            {
                GUILayout.BeginHorizontal();
                float oldLabelWidth = UnityEditor.EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 94;
                m_HexagonLayout             = EditorGUILayout.Popup(Styles.hexagonLabel, m_HexagonLayout, Styles.hexagonSwizzleTypeLabel);
                EditorGUIUtility.labelWidth = oldLabelWidth;
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.sizeLabel, GUILayout.Width(90f));
            m_CellSizing = (GridPalette.CellSizing)EditorGUILayout.EnumPopup(m_CellSizing);
            GUILayout.EndHorizontal();

            using (new EditorGUI.DisabledScope(m_CellSizing == GridPalette.CellSizing.Automatic))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(GUIContent.none, GUILayout.Width(90f));
                m_CellSize = EditorGUILayout.Vector3Field(GUIContent.none, m_CellSize);
                GUILayout.EndHorizontal();
            }

            GUILayout.FlexibleSpace();

            // Cancel, Ok
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button(Styles.cancel))
            {
                Close();
            }

            using (new EditorGUI.DisabledScope(!Utils.Paths.IsValidAssetPath(m_Name)))
            {
                if (GUILayout.Button(Styles.ok))
                {
                    // case 1077362: Close window to prevent overlap with OS folder window when saving new palette asset
                    Close();

                    var swizzle = Grid.CellSwizzle.XYZ;
                    if (m_Layout == GridLayout.CellLayout.Hexagon)
                    {
                        swizzle = Styles.hexagonSwizzleTypeValue[m_HexagonLayout];
                    }

                    GameObject go = GridPaletteUtility.CreateNewPaletteNamed(m_Name, m_Layout, m_CellSizing, m_CellSize, swizzle);
                    if (go != null)
                    {
                        m_Owner.palette = go;
                        m_Owner.Repaint();
                    }

                    GUIUtility.ExitGUI();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();
        }
 internal void OnGUI()
 {
     GUI.Label(new Rect(0f, 0f, base.position.width, base.position.height), GUIContent.none, "grey_border");
     GUILayout.Space(3f);
     GUILayout.Label(GridPaletteAddPopup.Styles.header, EditorStyles.boldLabel, new GUILayoutOption[0]);
     GUILayout.Space(4f);
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.Label(GridPaletteAddPopup.Styles.nameLabel, new GUILayoutOption[]
     {
         GUILayout.Width(90f)
     });
     this.m_Name = EditorGUILayout.TextField(this.m_Name, new GUILayoutOption[0]);
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.Label(GridPaletteAddPopup.Styles.gridLabel, new GUILayoutOption[]
     {
         GUILayout.Width(90f)
     });
     this.m_Layout = (GridLayout.CellLayout)EditorGUILayout.EnumPopup(this.m_Layout, new GUILayoutOption[0]);
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.Label(GridPaletteAddPopup.Styles.sizeLabel, new GUILayoutOption[]
     {
         GUILayout.Width(90f)
     });
     this.m_CellSizing = (GridPalette.CellSizing)EditorGUILayout.EnumPopup(this.m_CellSizing, new GUILayoutOption[0]);
     GUILayout.EndHorizontal();
     using (new EditorGUI.DisabledScope(this.m_CellSizing == GridPalette.CellSizing.Automatic))
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         GUILayout.Label(GUIContent.none, new GUILayoutOption[]
         {
             GUILayout.Width(90f)
         });
         this.m_CellSize = EditorGUILayout.Vector3Field(GUIContent.none, this.m_CellSize, new GUILayoutOption[0]);
         GUILayout.EndHorizontal();
     }
     GUILayout.Space(5f);
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.Space(10f);
     if (GUILayout.Button(GridPaletteAddPopup.Styles.cancel, new GUILayoutOption[0]))
     {
         base.Close();
     }
     using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(this.m_Name)))
     {
         if (GUILayout.Button(GridPaletteAddPopup.Styles.ok, new GUILayoutOption[0]))
         {
             GameObject gameObject = GridPaletteUtility.CreateNewPaletteNamed(this.m_Name, this.m_Layout, this.m_CellSizing, this.m_CellSize);
             if (gameObject != null)
             {
                 this.m_Owner.palette = gameObject;
                 this.m_Owner.Repaint();
             }
             base.Close();
             GUIUtility.ExitGUI();
         }
     }
     GUILayout.Space(10f);
     GUILayout.EndHorizontal();
 }