コード例 #1
0
 public static void Show(Tileset tileset = null)
 {
     s_instance = (TilePropertiesWindow)EditorWindow.GetWindow(typeof(TilePropertiesWindow), false, "Tile Properties", true);
     s_instance.m_tilePropertiesControl.Tileset = tileset;
     if (tileset == null)
     {
         s_instance.OnSelectionChange();
     }
     s_instance.wantsMouseMove = true;
 }
コード例 #2
0
 void OnEnable()
 {
     s_instance = this;
     minSize    = new Vector2(200f, 200f);
 }
コード例 #3
0
        private ReorderableList CreateTilemapReorderableList()
        {
            ReorderableList reordList = new ReorderableList(serializedObject, serializedObject.FindProperty("m_tilemaps"), true, true, true, true);

            reordList.displayAdd         = reordList.displayRemove = true;
            reordList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Tilemaps", EditorStyles.boldLabel);
                Texture2D btnTexture = reordList.elementHeight == 0f ? EditorGUIUtility.FindTexture("winbtn_win_max_h") : EditorGUIUtility.FindTexture("winbtn_win_min_h");
                if (GUI.Button(new Rect(rect.x + rect.width - rect.height, rect.y, rect.height, rect.height), btnTexture, EditorStyles.label))
                {
                    GUI.changed             = true;
                    reordList.elementHeight = reordList.elementHeight == 0f ? 21f : 0f;
                    reordList.draggable     = reordList.elementHeight > 0f;
                    reordList.displayAdd    = reordList.draggable;
                    reordList.displayRemove = reordList.draggable;
                }
            };
            reordList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (reordList.elementHeight == 0)
                {
                    return;
                }
                var element = reordList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                Tilemap tilemap = element.objectReferenceValue as Tilemap;
                if (tilemap)
                {
                    SerializedObject tilemapSerialized    = new SerializedObject(tilemap);
                    SerializedObject tilemapObjSerialized = new SerializedObject(tilemapSerialized.FindProperty("m_GameObject").objectReferenceValue);

                    Rect rToggle       = new Rect(rect.x, rect.y, 16f, EditorGUIUtility.singleLineHeight);
                    Rect rName         = new Rect(rect.x + 20f, rect.y, rect.width - 130f - 20f, EditorGUIUtility.singleLineHeight);
                    Rect rColliders    = new Rect(rect.x + rect.width - 125f, rect.y, 125f, EditorGUIUtility.singleLineHeight);
                    Rect rSortingLayer = new Rect(rect.x + rect.width - 125f, rect.y, 80f, EditorGUIUtility.singleLineHeight);
                    Rect rSortingOrder = new Rect(rect.x + rect.width - 40f, rect.y, 40f, EditorGUIUtility.singleLineHeight);

                    tilemap.IsVisible = EditorGUI.Toggle(rToggle, GUIContent.none, tilemap.IsVisible, STEditorStyles.Instance.visibleToggleStyle);
                    EditorGUI.PropertyField(rName, tilemapObjSerialized.FindProperty("m_Name"), GUIContent.none);
                    if (TilemapEditor.EditMode == TilemapEditor.eEditMode.Collider)
                    {
                        SerializedProperty colliderTypeProperty = tilemapSerialized.FindProperty("ColliderType");
                        string[]           colliderTypeNames    = new List <string>(System.Enum.GetNames(typeof(eColliderType)).Select(x => x.Replace('_', ' '))).ToArray();
                        EditorGUI.BeginChangeCheck();
                        colliderTypeProperty.intValue = GUI.Toolbar(rColliders, colliderTypeProperty.intValue, colliderTypeNames);
                        if (EditorGUI.EndChangeCheck())
                        {
                            tilemapSerialized.ApplyModifiedProperties();
                            tilemap.Refresh(false, true);
                        }
                    }
                    else
                    {
                        // Sorting Layer and Order in layer
                        EditorGUI.BeginChangeCheck();
                        EditorGUI.PropertyField(rSortingLayer, tilemapSerialized.FindProperty("m_sortingLayer"), GUIContent.none);
                        EditorGUI.PropertyField(rSortingOrder, tilemapSerialized.FindProperty("m_orderInLayer"), GUIContent.none);
                        tilemapSerialized.FindProperty("m_orderInLayer").intValue = (tilemapSerialized.FindProperty("m_orderInLayer").intValue << 16) >> 16; // convert from int32 to int16 keeping sign
                        if (EditorGUI.EndChangeCheck())
                        {
                            tilemapSerialized.ApplyModifiedProperties();
                            tilemap.RefreshChunksSortingAttributes();
                            SceneView.RepaintAll();
                        }
                        //---
                    }

                    if (GUI.changed)
                    {
                        tilemapObjSerialized.ApplyModifiedProperties();
                    }
                }
            };
            reordList.onReorderCallback = (ReorderableList list) =>
            {
                var targetObj   = target as TilemapGroup;
                int sibilingIdx = 0;
                foreach (Tilemap tilemap in targetObj.Tilemaps)
                {
                    tilemap.transform.SetSiblingIndex(sibilingIdx++);
                }
                Repaint();
            };
            reordList.onSelectCallback = (ReorderableList list) =>
            {
                m_selectedIndexProp.intValue = reordList.index;
                serializedObject.ApplyModifiedProperties();
                GUI.changed = true;
                TileSelectionWindow.RefreshIfVisible();
                TilePropertiesWindow.RefreshIfVisible();
            };
            reordList.onAddCallback = (ReorderableList list) =>
            {
                var targetObj = target as TilemapGroup;
                Undo.RegisterCompleteObjectUndo(targetObj, "New Tilemap");
                GameObject obj = new GameObject();
                Undo.RegisterCreatedObjectUndo(obj, "New Tilemap");
                Tilemap newTilemap = obj.AddComponent <Tilemap>();
                obj.transform.parent = targetObj.transform;
                obj.name             = GameObjectUtility.GetUniqueNameForSibling(obj.transform.parent, "New Tilemap");

                Tilemap copiedTilemap = targetObj.SelectedTilemap;
                if (copiedTilemap)
                {
                    UnityEditorInternal.ComponentUtility.CopyComponent(copiedTilemap);
                    UnityEditorInternal.ComponentUtility.PasteComponentValues(newTilemap);
                    obj.name = GameObjectUtility.GetUniqueNameForSibling(obj.transform.parent, copiedTilemap.name);
                }
            };
            reordList.onRemoveCallback = (ReorderableList list) =>
            {
                m_tilemapRemovingList.Add(m_target.SelectedTilemap.gameObject);
            };

            return(reordList);
        }
コード例 #4
0
        public void Display()
        {
            Event e = Event.current;

            m_dblClick.Update();

            // This way a gui exception is avoided
            if (e.type == EventType.Layout && m_selectBrushInInspector != null)
            {
                Selection.activeObject   = m_selectBrushInInspector;
                m_selectBrushInInspector = null;
            }

            if (m_lastTime == 0f)
            {
                m_lastTime = Time.realtimeSinceStartup;
            }
            m_timeDt   = Time.realtimeSinceStartup - m_lastTime;
            m_lastTime = Time.realtimeSinceStartup;

            if (Tileset == null)
            {
                EditorGUILayout.HelpBox("There is no tileset selected", MessageType.Info);
                return;
            }
            else if (Tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("There is no atlas texture set", MessageType.Info);
                return;
            }
            else if (Tileset.Tiles.Count == 0)
            {
                EditorGUILayout.HelpBox("There are no tiles to show in the current tileset", MessageType.Info);
                return;
            }

            if (m_scrollStyle == null)
            {
                m_scrollStyle = new GUIStyle("ScrollView");
            }

            if (m_customBox == null)
            {
                m_customBox = new GUIStyle("Box");
            }

            float visualTilePadding       = 1;
            bool  isLeftMouseReleased     = e.type == EventType.MouseUp && e.button == 0;
            bool  isRightMouseReleased    = e.type == EventType.MouseUp && e.button == 1;
            bool  isInsideTileScrollArea  = e.isMouse && m_rTileScrollArea.Contains(e.mousePosition);
            bool  isInsideBrushScrollArea = e.isMouse && m_rBrushScrollArea.Contains(e.mousePosition);

            // TileViews
            if (m_tileViewList == null || m_tileViewList.list != Tileset.TileViews)
            {
                if (e.type != EventType.Layout)
                {
                    m_tileViewList = TilesetEditor.CreateTileViewReorderableList(Tileset);
                    m_tileViewList.onSelectCallback += (ReorderableList list) =>
                    {
                        m_viewMode = eViewMode.TileView;
                        RemoveTileSelection();
                    };
                    m_tileViewList.onRemoveCallback += (ReorderableList list) =>
                    {
                        RemoveTileSelection();
                    };
                }
            }
            else
            {
                GUI.color = Color.cyan;
                GUILayout.BeginVertical(m_customBox);
                m_tileViewList.index = Mathf.Clamp(m_tileViewList.index, -1, Tileset.TileViews.Count - 1);
                m_tileViewList.DoLayoutList();
                Rect rList = GUILayoutUtility.GetLastRect();
                if (e.isMouse && !rList.Contains(e.mousePosition))
                {
                    m_tileViewList.ReleaseKeyboardFocus();
                }
                GUILayout.EndVertical();
                GUI.color = Color.white;
            }
            TileView tileView = m_tileViewList != null && m_tileViewList.index >= 0 ? Tileset.TileViews[m_tileViewList.index] : null;

            if (m_viewMode == eViewMode.Tileset)
            {
                Tileset.TileRowLength = Mathf.Clamp(EditorGUILayout.IntField("TileRowLength", Tileset.TileRowLength), 1, Tileset.Width);
            }

            m_viewMode = (eViewMode)EditorGUILayout.EnumPopup("View Mode", m_viewMode);
            if (tileView == null)
            {
                m_viewMode = eViewMode.Tileset;
            }
            if (m_viewMode != m_prevViewMode)
            {
                m_prevViewMode = m_viewMode;
                RemoveTileSelection();
            }

            // Draw Background Color Selector
            Tileset.BackgroundColor = EditorGUILayout.ColorField("Background Color", Tileset.BackgroundColor);
            if (m_prevBgColor != Tileset.BackgroundColor || m_scrollStyle.normal.background == null)
            {
                m_prevBgColor = Tileset.BackgroundColor;
                if (m_scrollStyle.normal.background == null)
                {
                    m_scrollStyle.normal.background = new Texture2D(1, 1)
                    {
                        hideFlags = HideFlags.DontSave
                    }
                }
                ;
                m_scrollStyle.normal.background.SetPixel(0, 0, Tileset.BackgroundColor);
                m_scrollStyle.normal.background.Apply();
            }
            //---

            string sTileIdLabel = Tileset.SelectedTileId != Tileset.k_TileId_Empty? " (id:" + Tileset.SelectedTileId + ")" : "";

            EditorGUILayout.LabelField("Tile Palette" + sTileIdLabel, EditorStyles.boldLabel);

            // keeps values safe
            m_tileViewRowLength = Mathf.Max(1, m_tileViewRowLength);

            float tileAreaWidth  = m_tileViewRowLength * (Tileset.VisualTileSize.x + visualTilePadding) + 4f;
            float tileAreaHeight = (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (m_visibleTileCount - 1) / m_tileViewRowLength) + 4f;

            m_tileViewRowLength = m_viewMode == eViewMode.TileView && tileView != null ? tileView.tileSelection.rowLength : Tileset.TileRowLength;

            m_tilesScrollPos = EditorGUILayout.BeginScrollView(m_tilesScrollPos, m_scrollStyle);
            {
                // Scroll Moving Drag
                if (e.type == EventType.MouseDrag && (e.button == 1 || e.button == 2))
                {
                    m_tilesScrollPos -= e.delta;
                }
                else
                {
                    DoAutoScroll();
                }

                if (e.isMouse)
                {
                    m_lastTileScrollMousePos = e.mousePosition;
                }
                if (Tileset.Tiles != null)
                {
                    GUILayoutUtility.GetRect(tileAreaWidth, tileAreaHeight);
                    m_visibleTileCount = 0;
                    List <uint> visibleTileList = new List <uint>();
                    int         tileViewWidth   = m_viewMode == eViewMode.Tileset ? Tileset.Width : tileView.tileSelection.rowLength;
                    int         tileViewHeight  = m_viewMode == eViewMode.Tileset ? Tileset.Height : ((tileView.tileSelection.selectionData.Count - 1) / tileView.tileSelection.rowLength) + 1;
                    int         totalCount      = ((((tileViewWidth - 1) / m_tileViewRowLength) + 1) * m_tileViewRowLength) * tileViewHeight;
                    for (int i = 0; i < totalCount; ++i)
                    {
                        int  tileId   = GetTileIdFromIdx(i, m_tileViewRowLength, tileViewWidth, tileViewHeight);
                        uint tileData = (uint)tileId;
                        if (m_viewMode == eViewMode.TileView && tileId != Tileset.k_TileId_Empty)
                        {
                            tileData = tileView.tileSelection.selectionData[tileId];
                            tileId   = (int)(tileData & Tileset.k_TileDataMask_TileId);
                        }
                        Tile tile = tileId != Tileset.k_TileId_Empty && tileId < Tileset.Tiles.Count ? Tileset.Tiles[tileId] : null;
                        visibleTileList.Add(tileData);

                        int  tx          = m_visibleTileCount % m_tileViewRowLength;
                        int  ty          = m_visibleTileCount / m_tileViewRowLength;
                        Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);

                        // Optimization, skipping not visible tiles
                        Rect rLocalVisualTile = rVisualTile; rLocalVisualTile.position -= m_tilesScrollPos;
                        if (!rLocalVisualTile.Overlaps(m_rTileScrollSize))
                        {
                            ; // Do Nothing
                        }
                        else
                        //---
                        {
                            // Draw Tile
                            if (tile == null)
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.2f), new Color(0f, 0f, 0f, 0.2f));
                            }
                            else
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.1f), new Color(0f, 0f, 0f, 0.1f));
                                TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset);
                            }

                            Rect rTileRect = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                            if (rVisualTile.Contains(e.mousePosition))
                            {
                                if (e.type == EventType.MouseDrag && e.button == 0)
                                {
                                    m_pointedTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseDown && e.button == 0)
                                {
                                    m_startDragTileIdxRect = m_pointedTileIdxRect = m_endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseUp && e.button == 0)
                                {
                                    m_endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                    DoSetTileSelection();
                                }
                            }

                            if ((isLeftMouseReleased || isRightMouseReleased) && isInsideTileScrollArea && rVisualTile.Contains(e.mousePosition) &&
                                (m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key) && // and there is not dragging selection
                                m_rTileScrollSize.Contains(e.mousePosition - m_tilesScrollPos))   // and it's inside the scroll area
                            {
                                Tileset.SelectedTileId = tileId;

                                //Give focus to SceneView to get key events
                                FocusSceneView();

                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (tile != null && Tileset.SelectedTileId == tileId)
                            {
                                HandlesEx.DrawRectWithOutline(rTileRect, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }

                        ++m_visibleTileCount;
                    }
                    m_visibleTileList = visibleTileList;

                    // Draw selection rect
                    if (m_startDragTileIdxRect.Key != m_pointedTileIdxRect.Key /*&& m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key*/)
                    {
                        Rect rSelection = new Rect(m_startDragTileIdxRect.Value.center, m_pointedTileIdxRect.Value.center - m_startDragTileIdxRect.Value.center);
                        rSelection.Set(Mathf.Min(rSelection.xMin, rSelection.xMax), Mathf.Min(rSelection.yMin, rSelection.yMax), Mathf.Abs(rSelection.width), Mathf.Abs(rSelection.height));
                        rSelection.xMin -= m_startDragTileIdxRect.Value.width / 2;
                        rSelection.xMax += m_startDragTileIdxRect.Value.width / 2;
                        rSelection.yMin -= m_startDragTileIdxRect.Value.height / 2;
                        rSelection.yMax += m_startDragTileIdxRect.Value.height / 2;
                        HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 1f, 1f));
                    }
                }
            }
            EditorGUILayout.EndScrollView();
            if (e.type == EventType.Repaint)
            {
                m_rTileScrollArea          = GUILayoutUtility.GetLastRect();
                m_rTileScrollSize          = m_rTileScrollArea;
                m_rTileScrollSize.position = Vector2.zero; // reset position to the Contains and Overlaps inside the tile scroll view without repositioning the position of local positions
                if (tileAreaWidth > m_rTileScrollSize.width)
                {
                    m_rTileScrollSize.height -= GUI.skin.verticalScrollbar.fixedWidth;
                }
                if (tileAreaHeight > m_rTileScrollSize.height)
                {
                    m_rTileScrollSize.width -= GUI.skin.verticalScrollbar.fixedWidth;
                }
            }

            EditorGUILayout.BeginHorizontal();
            string sBrushIdLabel = Tileset.SelectedBrushId > 0 ? " (id:" + Tileset.SelectedBrushId + ")" : "";

            EditorGUILayout.LabelField("Brush Palette" + sBrushIdLabel, EditorStyles.boldLabel);
            m_displayBrushReordList = EditorUtils.DoToggleButton("Display List", m_displayBrushReordList);
            EditorGUILayout.EndHorizontal();

            int tileRowLength = (int)(m_rTileScrollSize.width / (Tileset.VisualTileSize.x + visualTilePadding));

            if (tileRowLength <= 0)
            {
                tileRowLength = 1;
            }
            float fBrushesScrollMaxHeight = Screen.height / 4;
            //commented because m_rTileScrollSize.width.height was changed to Screen.height;  fBrushesScrollMaxHeight -= fBrushesScrollMaxHeight % 2; // sometimes because size of tile scroll affects size of brush scroll, the height is dancing between +-1, so this is always taking the pair value
            float fBrushesScrollHeight = Mathf.Min(fBrushesScrollMaxHeight, 4 + (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count / tileRowLength)));

            EditorGUILayout.BeginVertical(GUILayout.MinHeight(fBrushesScrollHeight));
            if (m_displayBrushReordList)
            {
                DisplayBrushReorderableList();
            }
            else
            {
                bool isRefreshBrushes = false;
                m_brushesScrollPos = EditorGUILayout.BeginScrollView(m_brushesScrollPos, m_scrollStyle);
                {
                    Rect rScrollView = new Rect(0, 0, m_rTileScrollSize.width, 0);
                    tileRowLength = Mathf.Clamp((int)rScrollView.width / (int)(Tileset.VisualTileSize.x + visualTilePadding), 1, tileRowLength);
                    if (Tileset.Brushes != null)
                    {
                        GUILayout.Space((Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count - 1) / tileRowLength));
                        for (int i = 0; i < Tileset.Brushes.Count; ++i)
                        {
                            Tileset.BrushContainer brushCont = Tileset.Brushes[i];
                            if (brushCont.BrushAsset == null)
                            {
                                isRefreshBrushes = true;
                                continue;
                            }

                            int  tx          = i % tileRowLength;
                            int  ty          = i / tileRowLength;
                            Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);
                            //Fix Missing Tileset reference
                            if (brushCont.BrushAsset.Tileset == null)
                            {
                                Debug.LogWarning("Fixed missing tileset reference in brush " + brushCont.BrushAsset.name + " Id(" + brushCont.Id + ")");
                                brushCont.BrushAsset.Tileset = Tileset;
                            }
                            uint tileData = Tileset.k_TileData_Empty;
                            if (brushCont.BrushAsset.IsAnimated())
                            {
                                tileData = brushCont.BrushAsset.GetAnimTileData();
                            }
                            else
                            {
                                tileData = brushCont.BrushAsset.PreviewTileData();
                            }
                            TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset, brushCont.BrushAsset.GetAnimUV());
                            if ((isLeftMouseReleased || isRightMouseReleased || m_dblClick.IsDblClick) && isInsideBrushScrollArea && rVisualTile.Contains(Event.current.mousePosition))
                            {
                                Tileset.SelectedBrushId = brushCont.Id;
                                RemoveTileSelection();
                                if (m_dblClick.IsDblClick)
                                {
                                    EditorGUIUtility.PingObject(brushCont.BrushAsset);
                                    m_selectBrushInInspector = brushCont.BrushAsset;
                                }
                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (Tileset.SelectedBrushId == brushCont.Id)
                            {
                                Rect rSelection = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                                HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }
                    }

                    if (isRefreshBrushes)
                    {
                        Tileset.RemoveNullBrushes();
                    }
                }
                EditorGUILayout.EndScrollView();
                if (e.type == EventType.Repaint)
                {
                    m_rBrushScrollArea = GUILayoutUtility.GetLastRect();
                }
            }
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Import all brushes found"))
            {
                TilesetEditor.AddAllBrushesFoundInTheProject(Tileset);
                EditorUtility.SetDirty(Tileset);
            }
        }
コード例 #5
0
ファイル: TilesetControl.cs プロジェクト: javier-montoya/Moxi
        public void Display()
        {
            AssetPreview.SetPreviewTextureCacheSize(256); //FIX clickeing issues when displaying multiple prefab previews (when a tile has a prefab attached
            Event e = Event.current;

            m_dblClick.Update();

            //FIX: when a tileset is changed, the layout change and during some frames, the BeginScrollView could return wrong values
            // This will make sure the scroll position is updated after mouse is over the control
            if (e.isMouse || e.type == EventType.ScrollWheel)
            {
                m_updateScrollPos = true;
            }

            // This way a gui exception is avoided
            if (e.type == EventType.Layout && m_selectBrushInInspector != null)
            {
                Selection.activeObject   = m_selectBrushInInspector;
                m_selectBrushInInspector = null;
            }

            if (m_lastTime == 0f)
            {
                m_lastTime = Time.realtimeSinceStartup;
            }
            m_timeDt   = Time.realtimeSinceStartup - m_lastTime;
            m_lastTime = Time.realtimeSinceStartup;

            if (Tileset == null)
            {
                EditorGUILayout.HelpBox("There is no tileset selected", MessageType.Info);
                return;
            }
            else if (Tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("There is no atlas texture set", MessageType.Info);
                return;
            }
            else if (Tileset.Tiles.Count == 0)
            {
                EditorGUILayout.HelpBox("There are no tiles to show in the current tileset", MessageType.Info);
                return;
            }

            m_sharedData = GetSharedTilesetData(Tileset);

            float visualTilePadding       = 1;
            bool  isLeftMouseReleased     = e.type == EventType.MouseUp && e.button == 0;
            bool  isRightMouseReleased    = e.type == EventType.MouseUp && e.button == 1;
            bool  isInsideTileScrollArea  = e.isMouse && m_rTileScrollArea.Contains(e.mousePosition);
            bool  isInsideBrushScrollArea = e.isMouse && m_rBrushScrollArea.Contains(e.mousePosition);

            // Create TileView ReorderableList
            if (m_sharedData.tileViewList == null || m_sharedData.tileViewList.list != Tileset.TileViews)
            {
                m_sharedData.tileViewList = TilesetEditor.CreateTileViewReorderableList(Tileset);
                m_sharedData.tileViewList.onSelectCallback += (ReorderableList list) =>
                {
                    /* NOTE: this will select the tileview for the painting brush. Commented just in case.
                     * if(list.index >= 0)
                     * {
                     *  TileSelection tileSelection = Tileset.TileViews[list.index].tileSelection.Clone();
                     *  tileSelection.FlipVertical();
                     *  Tileset.TileSelection = tileSelection;
                     * }
                     * else*/
                    RemoveTileSelection();
                };
                m_sharedData.tileViewList.onRemoveCallback += (ReorderableList list) =>
                {
                    RemoveTileSelection();
                };
            }

            // Draw TileView ReorderableList
            {
                GUI.color = Color.cyan;
                GUILayout.BeginVertical(Styles.Instance.customBox);
                m_sharedData.tileViewList.index = Mathf.Clamp(m_sharedData.tileViewList.index, -1, Tileset.TileViews.Count - 1);
                m_sharedData.tileViewList.DoLayoutList();
                Rect rList = GUILayoutUtility.GetLastRect();
                if (e.isMouse && !rList.Contains(e.mousePosition))
                {
                    m_sharedData.tileViewList.ReleaseKeyboardFocus();
                }
                GUILayout.EndVertical();
                GUI.color = Color.white;
            }
            TileView tileView = m_sharedData.tileViewList != null && m_sharedData.tileViewList.index >= 0 ? Tileset.TileViews[m_sharedData.tileViewList.index] : null;

            if (tileView == null)
            {
                Tileset.TileRowLength = Mathf.Clamp(EditorGUILayout.IntField("TileRowLength", Tileset.TileRowLength), 1, Tileset.Width);
            }


            List <string> viewNameList = new List <string>()
            {
                "(All)"
            };

            viewNameList.AddRange(Tileset.TileViews.Select(x => x.name));
            string[] tileViewNames  = viewNameList.ToArray();
            int[]    tileViewValues = Enumerable.Range(-1, Tileset.TileViews.Count + 1).ToArray();
            EditorGUI.BeginChangeCheck();
            m_sharedData.tileViewList.index = EditorGUILayout.IntPopup("Tileset View", m_sharedData.tileViewList.index, tileViewNames, tileViewValues);
            if (EditorGUI.EndChangeCheck())
            {
                RemoveTileSelection();
            }

            // Draw Background Color Selector
            Tileset.BackgroundColor = EditorGUILayout.ColorField("Background Color", Tileset.BackgroundColor);
            if (m_prevBgColor != Tileset.BackgroundColor || Styles.Instance.scrollStyle.normal.background == null)
            {
                m_prevBgColor = Tileset.BackgroundColor;
                if (Styles.Instance.scrollStyle.normal.background == null)
                {
                    Styles.Instance.scrollStyle.normal.background = new Texture2D(1, 1)
                    {
                        hideFlags = HideFlags.DontSave
                    }
                }
                ;
                Styles.Instance.scrollStyle.normal.background.SetPixel(0, 0, Tileset.BackgroundColor);
                Styles.Instance.scrollStyle.normal.background.Apply();
            }
            //---

            // Draw Zoom Selector
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(EditorGUIUtility.FindTexture("ViewToolZoom"), GUILayout.Width(35f));
            float visualTileZoom = EditorGUILayout.Slider(Tileset.VisualTileSize.x / Tileset.TilePxSize.x, 0.25f, 4f);

            Tileset.VisualTileSize = visualTileZoom * Tileset.TilePxSize;
            if (GUILayout.Button("Reset", GUILayout.Width(50f)))
            {
                Tileset.VisualTileSize = new Vector2(32f * Tileset.TilePxSize.x / Tileset.TilePxSize.y, 32f);
            }
            EditorGUILayout.EndHorizontal();
            //---

            string sTileIdLabel = Tileset.SelectedTileId != Tileset.k_TileId_Empty? " (id:" + Tileset.SelectedTileId + ")" : "";

            EditorGUILayout.LabelField("Tile Palette" + sTileIdLabel, EditorStyles.boldLabel);

            // keeps values safe
            m_sharedData.tileViewRowLength = Mathf.Max(1, m_sharedData.tileViewRowLength);

            float tileAreaWidth  = m_sharedData.tileViewRowLength * (Tileset.VisualTileSize.x + visualTilePadding) + 4f;
            float tileAreaHeight = (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (m_visibleTileCount - 1) / m_sharedData.tileViewRowLength) + 4f;

            m_sharedData.tileViewRowLength = tileView != null ? tileView.tileSelection.rowLength : Tileset.TileRowLength;

            //float minTileScrollHeight = (Tileset.VisualTileSize.y + visualTilePadding) * 6f;// NOTE: GUILayout.MinHeight is not working with BeginScrollView
            Vector2 tilesScrollPos = EditorGUILayout.BeginScrollView(m_sharedData.tilesScrollPos, Styles.Instance.scrollStyle /*, GUILayout.MinHeight(minTileScrollHeight)*/);

            if (m_updateScrollPos)
            {
                m_sharedData.tilesScrollPos = tilesScrollPos;
            }
            {
                // Scroll Moving Drag
                if (e.type == EventType.MouseDrag && (e.button == 1 || e.button == 2))
                {
                    m_sharedData.tilesScrollPos -= e.delta;
                }
                else
                {
                    DoAutoScroll();
                }

                if (e.isMouse)
                {
                    m_lastTileScrollMousePos = e.mousePosition;
                }
                if (Tileset.Tiles != null)
                {
                    GUILayoutUtility.GetRect(tileAreaWidth, tileAreaHeight);
                    m_visibleTileCount = 0;
                    List <uint> visibleTileList = new List <uint>();
                    int         tileViewWidth   = tileView != null ? tileView.tileSelection.rowLength : Tileset.Width;
                    int         tileViewHeight  = tileView != null ? ((tileView.tileSelection.selectionData.Count - 1) / tileView.tileSelection.rowLength) + 1 : Tileset.Height;
                    int         totalCount      = ((((tileViewWidth - 1) / m_sharedData.tileViewRowLength) + 1) * m_sharedData.tileViewRowLength) * tileViewHeight;
                    for (int i = 0; i < totalCount; ++i)
                    {
                        int  tileId   = GetTileIdFromIdx(i, m_sharedData.tileViewRowLength, tileViewWidth, tileViewHeight);
                        uint tileData = (uint)tileId;
                        if (tileView != null && tileId != Tileset.k_TileId_Empty)
                        {
                            tileData = tileView.tileSelection.selectionData[tileId];
                            tileId   = (int)(tileData & Tileset.k_TileDataMask_TileId);
                        }
                        Tile tile = Tileset.GetTile(tileId);
                        visibleTileList.Add(tileData);

                        int  tx          = m_visibleTileCount % m_sharedData.tileViewRowLength;
                        int  ty          = m_visibleTileCount / m_sharedData.tileViewRowLength;
                        Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);

                        // Optimization, skipping not visible tiles
                        Rect rLocalVisualTile = rVisualTile; rLocalVisualTile.position -= m_sharedData.tilesScrollPos;
                        if (!rLocalVisualTile.Overlaps(m_rTileScrollSize))
                        {
                            ; // Do Nothing
                        }
                        else
                        //---
                        {
                            // Draw Tile
                            if (tile == null)
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.2f), new Color(0f, 0f, 0f, 0.2f));
                            }
                            else
                            {
                                HandlesEx.DrawRectWithOutline(rVisualTile, new Color(0f, 0f, 0f, 0.1f), new Color(0f, 0f, 0f, 0.1f));
                                TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset);
                            }

                            Rect rTileRect = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                            if (rVisualTile.Contains(e.mousePosition))
                            {
                                if (e.type == EventType.MouseDrag && e.button == 0)
                                {
                                    m_sharedData.pointedTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseDown && e.button == 0)
                                {
                                    m_sharedData.startDragTileIdxRect = m_sharedData.pointedTileIdxRect = m_sharedData.endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                }
                                else if (e.type == EventType.MouseUp && e.button == 0)
                                {
                                    m_sharedData.endDragTileIdxRect = new KeyValuePair <int, Rect>(m_visibleTileCount, rTileRect);
                                    DoSetTileSelection();
                                }
                            }

                            if ((isLeftMouseReleased || isRightMouseReleased) && isInsideTileScrollArea && rVisualTile.Contains(e.mousePosition) &&
                                (m_sharedData.startDragTileIdxRect.Key == m_sharedData.endDragTileIdxRect.Key) && // and there is not dragging selection
                                m_rTileScrollSize.Contains(e.mousePosition - m_sharedData.tilesScrollPos))   // and it's inside the scroll area
                            {
                                Tileset.SelectedTileId = tileId;

                                //Give focus to SceneView to get key events
                                FocusSceneView();

                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (tile != null && Tileset.SelectedTileId == tileId)
                            {
                                HandlesEx.DrawRectWithOutline(rTileRect, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }

                        ++m_visibleTileCount;
                    }
                    m_visibleTileList = visibleTileList;

                    // Draw selection rect
                    if (m_sharedData.startDragTileIdxRect.Key != m_sharedData.pointedTileIdxRect.Key /*&& m_startDragTileIdxRect.Key == m_endDragTileIdxRect.Key*/)
                    {
                        Rect rSelection = new Rect(m_sharedData.startDragTileIdxRect.Value.center, m_sharedData.pointedTileIdxRect.Value.center - m_sharedData.startDragTileIdxRect.Value.center);
                        rSelection.Set(Mathf.Min(rSelection.xMin, rSelection.xMax), Mathf.Min(rSelection.yMin, rSelection.yMax), Mathf.Abs(rSelection.width), Mathf.Abs(rSelection.height));
                        rSelection.xMin -= m_sharedData.startDragTileIdxRect.Value.width / 2;
                        rSelection.xMax += m_sharedData.startDragTileIdxRect.Value.width / 2;
                        rSelection.yMin -= m_sharedData.startDragTileIdxRect.Value.height / 2;
                        rSelection.yMax += m_sharedData.startDragTileIdxRect.Value.height / 2;
                        HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 1f, 1f));
                    }
                }
            }
            EditorGUILayout.EndScrollView();
            if (e.type == EventType.Repaint)
            {
                m_rTileScrollArea          = GUILayoutUtility.GetLastRect();
                m_rTileScrollSize          = m_rTileScrollArea;
                m_rTileScrollSize.position = Vector2.zero; // reset position to the Contains and Overlaps inside the tile scroll view without repositioning the position of local positions
                if (tileAreaWidth > m_rTileScrollSize.width)
                {
                    m_rTileScrollSize.height -= GUI.skin.verticalScrollbar.fixedWidth;
                }
                if (tileAreaHeight > m_rTileScrollSize.height)
                {
                    m_rTileScrollSize.width -= GUI.skin.verticalScrollbar.fixedWidth;
                }
            }

            EditorGUILayout.BeginHorizontal();
            string sBrushIdLabel = Tileset.SelectedBrushId > 0 ? " (id:" + Tileset.SelectedBrushId + ")" : "";

            EditorGUILayout.LabelField("Brush Palette" + sBrushIdLabel, EditorStyles.boldLabel);
            m_displayBrushReordList = EditorUtils.DoToggleButton("Display List", m_displayBrushReordList);
            EditorGUILayout.EndHorizontal();
            Tileset.BrushTypeMask = EditorGUILayout.MaskField("Brush Mask", Tileset.BrushTypeMask, Tileset.GetBrushTypeArray());

            int tileRowLength = (int)(m_rTileScrollSize.width / (Tileset.VisualTileSize.x + visualTilePadding));

            if (tileRowLength <= 0)
            {
                tileRowLength = 1;
            }
            float fBrushesScrollMaxHeight = Screen.height / 4;
            //commented because m_rTileScrollSize.width.height was changed to Screen.height;  fBrushesScrollMaxHeight -= fBrushesScrollMaxHeight % 2; // sometimes because size of tile scroll affects size of brush scroll, the height is dancing between +-1, so this is always taking the pair value
            float fBrushesScrollHeight = Mathf.Min(fBrushesScrollMaxHeight, 4 + (Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count / tileRowLength)));

            EditorGUILayout.BeginVertical(GUILayout.MinHeight(fBrushesScrollHeight));
            if (m_displayBrushReordList)
            {
                DisplayBrushReorderableList();
            }
            else
            {
                bool    refreshBrushes   = false;
                Vector2 brushesScrollPos = EditorGUILayout.BeginScrollView(m_sharedData.brushesScrollPos, Styles.Instance.scrollStyle);
                if (m_updateScrollPos)
                {
                    m_sharedData.brushesScrollPos = brushesScrollPos;
                }
                {
                    Rect rScrollView = new Rect(0, 0, m_rTileScrollSize.width, 0);
                    tileRowLength = Mathf.Clamp((int)rScrollView.width / (int)(Tileset.VisualTileSize.x + visualTilePadding), 1, tileRowLength);
                    if (Tileset.Brushes != null)
                    {
                        GUILayout.Space((Tileset.VisualTileSize.y + visualTilePadding) * (1 + (Tileset.Brushes.Count - 1) / tileRowLength));
                        for (int i = 0, idx = 0; i < Tileset.Brushes.Count; ++i, ++idx)
                        {
                            Tileset.BrushContainer brushCont = Tileset.Brushes[i];
                            if (brushCont.BrushAsset == null || brushCont.BrushAsset.Tileset != Tileset)
                            {
                                refreshBrushes = true;
                                continue;
                            }
                            if (!brushCont.BrushAsset.ShowInPalette || !Tileset.IsBrushVisibleByTypeMask(brushCont.BrushAsset))
                            {
                                --idx;
                                continue;
                            }

                            int  tx          = idx % tileRowLength;
                            int  ty          = idx / tileRowLength;
                            Rect rVisualTile = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), Tileset.VisualTileSize.x, Tileset.VisualTileSize.y);
                            //Fix Missing Tileset reference
                            if (brushCont.BrushAsset.Tileset == null)
                            {
                                Debug.LogWarning("Fixed missing tileset reference in brush " + brushCont.BrushAsset.name + " Id(" + brushCont.Id + ")");
                                brushCont.BrushAsset.Tileset = Tileset;
                            }
                            uint tileData = Tileset.k_TileData_Empty;
                            if (brushCont.BrushAsset.IsAnimated())
                            {
                                tileData = brushCont.BrushAsset.GetAnimTileData();
                            }
                            else
                            {
                                tileData = brushCont.BrushAsset.PreviewTileData();
                            }
                            TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset, brushCont.BrushAsset.GetAnimUV());
                            if ((isLeftMouseReleased || isRightMouseReleased || m_dblClick.IsDblClick) && isInsideBrushScrollArea && rVisualTile.Contains(Event.current.mousePosition))
                            {
                                Tileset.SelectedBrushId = brushCont.Id;
                                RemoveTileSelection();
                                if (m_dblClick.IsDblClick)
                                {
                                    EditorGUIUtility.PingObject(brushCont.BrushAsset);
                                    m_selectBrushInInspector = brushCont.BrushAsset;
                                }
                                if (isRightMouseReleased)
                                {
                                    TilePropertiesWindow.Show(Tileset);
                                }
                            }
                            else if (Tileset.SelectedBrushId == brushCont.Id)
                            {
                                Rect rSelection = new Rect(2 + tx * (Tileset.VisualTileSize.x + visualTilePadding), 2 + ty * (Tileset.VisualTileSize.y + visualTilePadding), (Tileset.VisualTileSize.x + visualTilePadding), (Tileset.VisualTileSize.y + visualTilePadding));
                                HandlesEx.DrawRectWithOutline(rSelection, new Color(0f, 0f, 0f, 0.1f), new Color(1f, 1f, 0f, 1f));
                            }
                        }
                    }

                    if (refreshBrushes)
                    {
                        Tileset.RemoveInvalidBrushes();
                        Tileset.UpdateBrushTypeArray();
                    }
                }
                EditorGUILayout.EndScrollView();
                if (e.type == EventType.Repaint)
                {
                    m_rBrushScrollArea = GUILayoutUtility.GetLastRect();
                }
            }
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Import all brushes found in the project"))
            {
                TilesetEditor.AddAllBrushesFoundInTheProject(Tileset);
                EditorUtility.SetDirty(Tileset);
            }
        }
コード例 #6
0
 void OnEnable()
 {
     s_instance = this;
 }
コード例 #7
0
        private ReorderableList CreateTilemapReorderableList()
        {
            ReorderableList reordList = new ReorderableList(serializedObject, serializedObject.FindProperty("m_tilemaps"), true, true, true, true);

            reordList.displayAdd         = reordList.displayRemove = true;
            reordList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Tilemaps", EditorStyles.boldLabel);
                Texture2D btnTexture = reordList.elementHeight == 0f ? EditorGUIUtility.FindTexture("winbtn_win_max_h") : EditorGUIUtility.FindTexture("winbtn_win_min_h");
                if (GUI.Button(new Rect(rect.width - rect.height, rect.y, rect.height, rect.height), btnTexture, EditorStyles.label))
                {
                    reordList.elementHeight = reordList.elementHeight == 0f ? EditorGUIUtility.singleLineHeight : 0f;
                    reordList.draggable     = reordList.elementHeight > 0f;
                }
            };
            reordList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = reordList.serializedProperty.GetArrayElementAtIndex(index);

                if (Event.current.type == EventType.Repaint)
                {
                    m_reordListRectsDic[m_reordIdx] = rect;
                }
                else if (Event.current.type == EventType.Layout)
                {
                    m_reordListRectsDic.TryGetValue(m_reordIdx, out rect);
                }
                m_reordIdx++;

                rect.y += 2;

                Tilemap          tilemap              = element.objectReferenceValue as Tilemap;
                SerializedObject tilemapSerialized    = new SerializedObject(tilemap);
                SerializedObject tilemapObjSerialized = new SerializedObject(tilemapSerialized.FindProperty("m_GameObject").objectReferenceValue);

                GUILayout.BeginArea(rect);
                EditorGUILayout.BeginHorizontal();
                tilemap.IsVisible = EditorGUILayout.Toggle(tilemap.IsVisible, GUILayout.Width(16));
                EditorGUILayout.PropertyField(tilemapObjSerialized.FindProperty("m_Name"), GUIContent.none);
                if (TilemapEditor.EditMode == TilemapEditor.eEditMode.Collider)
                {
                    SerializedProperty colliderTypeProperty = tilemapSerialized.FindProperty("ColliderType");
                    string[]           colliderTypeNames    = new List <string>(System.Enum.GetNames(typeof(eColliderType)).Select(x => x.Replace('_', ' '))).ToArray();
                    EditorGUI.BeginChangeCheck();
                    colliderTypeProperty.intValue = GUILayout.SelectionGrid(colliderTypeProperty.intValue, colliderTypeNames, colliderTypeNames.Length, GUILayout.MaxHeight(0.9f * EditorGUIUtility.singleLineHeight));
                    if (EditorGUI.EndChangeCheck())
                    {
                        tilemapSerialized.ApplyModifiedProperties();
                        tilemap.Refresh(false, true);
                    }
                }
                else
                {
                    // Sorting Layer and Order in layer
                    EditorGUI.BeginChangeCheck();
                    EditorGUIUtility.labelWidth = 1;
                    EditorGUILayout.PropertyField(tilemapSerialized.FindProperty("m_sortingLayer"), new GUIContent(" "));
                    EditorGUIUtility.labelWidth = 40;
                    EditorGUILayout.PropertyField(tilemapSerialized.FindProperty("m_orderInLayer"), new GUIContent("Order"), GUILayout.MaxWidth(90));
                    EditorGUIUtility.labelWidth = 0;
                    tilemapSerialized.FindProperty("m_orderInLayer").intValue = (tilemapSerialized.FindProperty("m_orderInLayer").intValue << 16) >> 16; // convert from int32 to int16 keeping sign
                    if (EditorGUI.EndChangeCheck())
                    {
                        tilemapSerialized.ApplyModifiedProperties();
                        tilemap.RefreshChunksSortingAttributes();
                        SceneView.RepaintAll();
                    }
                    //---
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.EndArea();

                if (GUI.changed)
                {
                    tilemapObjSerialized.ApplyModifiedProperties();
                }
            };
            reordList.onReorderCallback = (ReorderableList list) =>
            {
                var targetObj   = target as TilemapGroup;
                int sibilingIdx = 0;
                foreach (Tilemap tilemap in targetObj.Tilemaps)
                {
                    tilemap.transform.SetSiblingIndex(sibilingIdx++);
                }
                Repaint();
            };
            reordList.onSelectCallback = (ReorderableList list) =>
            {
                serializedObject.FindProperty("m_selectedIndex").intValue = reordList.index;
                serializedObject.ApplyModifiedProperties();
                GUI.changed = true;
                TileSelectionWindow.RefreshIfVisible();
                TilePropertiesWindow.RefreshIfVisible();
            };
            reordList.onAddCallback = (ReorderableList list) =>
            {
                var targetObj = target as TilemapGroup;
                Undo.RegisterCompleteObjectUndo(targetObj, "New Tilemap");
                GameObject obj = new GameObject();
                Undo.RegisterCreatedObjectUndo(obj, "New Tilemap");
                Tilemap newTilemap = obj.AddComponent <Tilemap>();
                obj.transform.parent = targetObj.transform;
                obj.name             = GameObjectUtility.GetUniqueNameForSibling(obj.transform.parent, "New Tilemap");

                Tilemap copiedTilemap = targetObj.SelectedTilemap;
                if (copiedTilemap)
                {
                    UnityEditorInternal.ComponentUtility.CopyComponent(copiedTilemap);
                    UnityEditorInternal.ComponentUtility.PasteComponentValues(newTilemap);
                    obj.SendMessage("_DoDuplicate");
                    obj.name = GameObjectUtility.GetUniqueNameForSibling(obj.transform.parent, copiedTilemap.name);
                }
            };
            reordList.onRemoveCallback = (ReorderableList list) =>
            {
                var targetObj = target as TilemapGroup;
                Undo.DestroyObjectImmediate(targetObj.SelectedTilemap.gameObject);
                //NOTE: Fix argument exception
                if (m_tilemapReordList.index == targetObj.Tilemaps.Count - 1)
                {
                    serializedObject.FindProperty("m_selectedIndex").intValue = m_tilemapReordList.index = m_tilemapReordList.index - 1;
                }
            };

            return(reordList);
        }