Пример #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();

            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();
        }
Пример #2
0
        public static GameObject CreateNewPalette(string folder_path, string name, Grid.CellLayout layout, GridPalette.CellSizing cell_sizing, Vector3 cell_size, Grid.CellSwizzle swizzle)
        {
            var tmp_go = new GameObject(name);
            var grid   = tmp_go.AddComponent <Grid>();

            // We set size to kEpsilon to mark this as new uninitialized palette
            // Nice default size can be decided when first asset is dragged in
            grid.cellSize    = cell_size;
            grid.cellLayout  = layout;
            grid.cellSwizzle = swizzle;
            CreateNewLayer(tmp_go, "Layer1", layout);

            var path = AssetDatabase.GenerateUniqueAssetPath(folder_path + "/" + name + ".prefab");

            Object prefab  = PrefabUtility.SaveAsPrefabAssetAndConnect(tmp_go, path, InteractionMode.AutomatedAction);
            var    palette = GridPalette.CreateInstance <GridPalette>();

            palette.name       = "Palette Settings";
            palette.cellSizing = cell_sizing;
            AssetDatabase.AddObjectToAsset(palette, prefab);
            PrefabUtility.ApplyPrefabInstance(tmp_go, InteractionMode.AutomatedAction);
            AssetDatabase.Refresh();

            GameObject.DestroyImmediate(tmp_go);
            return(AssetDatabase.LoadAssetAtPath <GameObject>(path));
        }
        public static GameObject CreateNewPaletteNamed(string name, Grid.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize, Grid.CellSwizzle swizzle)
        {
            string defaultPath = ProjectBrowser.s_LastInteractedProjectBrowser ? ProjectBrowser.s_LastInteractedProjectBrowser.GetActiveFolderPath() : "Assets";
            string folderPath  = EditorUtility.SaveFolderPanel("Create palette into folder ", defaultPath, "");

            folderPath = FileUtil.GetProjectRelativePath(folderPath);

            if (string.IsNullOrEmpty(folderPath))
            {
                return(null);
            }

            return(CreateNewPalette(folderPath, name, layout, cellSizing, cellSize, swizzle));
        }
Пример #4
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));
            EditorGUI.BeginChangeCheck();
            var newLayout = (GridLayout.CellLayout)EditorGUILayout.EnumPopup(m_Layout);

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

                case GridLayout.CellLayout.Isometric:
                case GridLayout.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))
                {
                    s_LastClosedTime = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond;

                    // case 1077362: Close window to prevent overlap with OS folder window when saving new palette asset
                    Close();

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

                    GameObject go = GridPaletteUtility.CreateNewPaletteAtCurrentFolder(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();
        }
Пример #5
0
 internal static GridPalette CreateGridPalette(GridPalette.CellSizing cellSizing)
 {
     return(CreateGridPalette(cellSizing, TransparencySortMode.Default, defaultSortAxis));
 }
Пример #6
0
 /// <summary>
 /// Creates a Palette Asset at the current selected folder path. This will show a popup allowing you to choose
 /// a different folder path for saving the Palette Asset if required.
 /// </summary>
 /// <param name="name">Name of the Palette Asset.</param>
 /// <param name="layout">Grid Layout of the Palette Asset.</param>
 /// <param name="cellSizing">Cell Sizing of the Palette Asset.</param>
 /// <param name="cellSize">Cell Size of the Palette Asset.</param>
 /// <param name="swizzle">Cell Swizzle of the Palette.</param>
 /// <returns>The created Palette Asset if successful.</returns>
 public static GameObject CreateNewPaletteAtCurrentFolder(string name, GridLayout.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize, GridLayout.CellSwizzle swizzle)
 {
     return(CreateNewPaletteAtCurrentFolder(name, layout, cellSizing, cellSize, swizzle
                                            , TransparencySortMode.Default, defaultSortAxis));
 }
        public static GameObject CreateNewPalette(string folderPath, string name, Grid.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize, Grid.CellSwizzle swizzle)
        {
            GameObject temporaryGO = new GameObject(name);
            Grid       grid        = temporaryGO.AddComponent <Grid>();

            // We set size to kEpsilon to mark this as new uninitialized palette
            // Nice default size can be decided when first asset is dragged in
            grid.cellSize    = cellSize;
            grid.cellLayout  = layout;
            grid.cellSwizzle = swizzle;
            CreateNewLayer(temporaryGO, "Layer1", layout);

            string path = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + name + ".prefab");

            Object      prefab  = PrefabUtility.CreateEmptyPrefab(path);
            GridPalette palette = GridPalette.CreateInstance <GridPalette>();

            palette.name       = "Palette Settings";
            palette.cellSizing = cellSizing;
            AssetDatabase.AddObjectToAsset(palette, prefab);
            PrefabUtility.ReplacePrefab(temporaryGO, prefab, ReplacePrefabOptions.Default);
            AssetDatabase.Refresh();

            GameObject.DestroyImmediate(temporaryGO);
            return(AssetDatabase.LoadAssetAtPath <GameObject>(path));
        }
Пример #8
0
        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));
        }
Пример #9
0
        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);
        }
        static void CreateAssetObject(string defaultAssetName, GridLayout.CellLayout layout, GridLayout.CellSwizzle swizzle, GridPalette.CellSizing cellSizing, Vector3 cellSize)
        {
            var assetSelectionPath = AssetDatabase.GetAssetPath(Selection.activeObject);
            var isFolder           = false;

            if (!string.IsNullOrEmpty(assetSelectionPath))
            {
                isFolder = File.GetAttributes(assetSelectionPath).HasFlag(FileAttributes.Directory);
            }
            var path = ProjectWindowUtil.GetActiveFolderPath();

            if (isFolder)
            {
                path = assetSelectionPath;
            }

            var destName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(path, defaultAssetName));
            var icon     = EditorGUIUtility.IconContent <GameObject>().image as Texture2D;
            CreateAssetEndNameEditAction action = ScriptableObject.CreateInstance <CreateAssetEndNameEditAction>();

            action.swizzle    = swizzle;
            action.layout     = layout;
            action.cellSize   = cellSize;
            action.cellSizing = cellSizing;
            StartNewAssetNameEditingDelegate(0, action, destName, icon, "");
        }
Пример #11
0
 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();
 }