public static void TileDataField(Rect position, GUIContent label, SerializedProperty property, Tileset tileset) { Event e = Event.current; bool isLeftMouseReleased = e.type == EventType.MouseUp && e.button == 0; //NOTE: there is a bug with DrawTextureWithTexCoords where the texture disappears. It is fixed by overriding the Editor Script with a CustomEditor. Rect rVisualTile = new Rect(position.x, position.y, k_TilePreviewSize, k_TilePreviewSize); uint tileData = (uint)property.intValue; TilesetBrush brush = tileset.FindBrush(Tileset.GetBrushIdFromTileData(tileData)); if (brush) { tileData = brush.PreviewTileData(); } TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, tileset); if (isLeftMouseReleased && rVisualTile.Contains(e.mousePosition)) { EditorWindow wnd = EditorWindow.focusedWindow; TileSelectionWindow.Show(tileset); TileSelectionWindow.Instance.Ping(); wnd.Focus(); GUI.FocusControl(""); } EditorGUI.PropertyField(new Rect(position.x, position.y + k_TilePreviewSize, position.width, position.height - k_TilePreviewSize), property, label); }
public static void Show(Tileset tileset = null) { s_instance = (TileSelectionWindow)EditorWindow.GetWindow(typeof(TileSelectionWindow), false, "Tile Palette", true); s_instance.m_tilesetControl.Tileset = tileset; if (tileset == null) { s_instance.OnSelectionChange(); } s_instance.wantsMouseMove = true; }
public static void DoSelectTile(TileGridControl tileGridControl, int tileIdx) { tileGridControl.m_selectedTileIdx = tileIdx; EditorWindow wnd = EditorWindow.focusedWindow; TileSelectionWindow.Show(tileGridControl.Tileset); TileSelectionWindow.Instance.Ping(); wnd.Focus(); GUI.FocusControl(""); }
public override void OnEnable() { base.OnEnable(); m_brush = (RandomBrush)target; if (m_brush.Tileset != null) { m_brush.Tileset.OnTileSelected += OnTileSelected; } m_randTileList = new ReorderableList(serializedObject, serializedObject.FindProperty("RandomTiles"), true, true, true, true); m_randTileList.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, "Random Tiles", EditorStyles.boldLabel); }; m_randTileList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { Rect rTile = rect; rTile.width = rTile.height = m_brush.Tileset.VisualTileSize.y; uint tileData = m_brush.RandomTiles[index]; int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId); if (tileId != Tileset.k_TileId_Empty) { GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset); } Rect rTileId = rect; rTileId.x += rTile.width + 20; rTileId.width -= rTile.width + 20; rTileId.height = rect.height / 2; GUI.Label(rTileId, "Id(" + tileId + ")"); if (GUI.Button(new Rect(rect.x + rect.width - 50f, rect.y, 50f, EditorGUIUtility.singleLineHeight), "Empty")) { m_brush.RandomTiles[index] = Tileset.k_TileData_Empty; } }; m_randTileList.onSelectCallback += (ReorderableList list) => { TileSelectionWindow.Show(m_brush.Tileset); TileSelectionWindow.Instance.Ping(); }; m_randTileList.onAddCallback += (ReorderableList list) => { if (list.index >= 0) { list.serializedProperty.InsertArrayElementAtIndex(list.index); } else { list.serializedProperty.InsertArrayElementAtIndex(0); } }; }
private bool m_displayAutocompleteBtn = false; // fix gui warning when button appears public void Display(Vector2 visualTileSize) { GUI.changed |= m_hasChanged; m_hasChanged = false; Event e = Event.current; bool isLeftMouseReleased = e.type == EventType.MouseUp && e.button == 0; if (isLeftMouseReleased) { m_hasFocus = m_tileSelectionRect.Contains(e.mousePosition); } bool hasEmptyTiles = false; int size = m_width * m_height; Color cSelectedBorderColor = new Color(1f, 1f, 0f, 1f); if (!m_hasFocus) { cSelectedBorderColor *= .8f; } GUILayout.BeginHorizontal(); { // Draw Autotile Combination Control GUI.backgroundColor = Tileset.BackgroundColor; GUILayoutUtility.GetRect(visualTileSize.x * m_width, visualTileSize.y * m_height + 1f); Rect rArea = GUILayoutUtility.GetLastRect(); { if (m_backgroundTexture) { GUI.DrawTexture(new Rect(rArea.position, Vector2.Scale(visualTileSize, new Vector2(m_width, m_height))), m_backgroundTexture); } GUI.backgroundColor = Color.white; for (int tileIdx = 0; tileIdx < size; ++tileIdx) { int gx = tileIdx % m_width; int gy = tileIdx / m_width; Rect rVisualTile = new Rect(gx * visualTileSize.x, gy * visualTileSize.y, visualTileSize.x, visualTileSize.y); rVisualTile.position += rArea.position; uint tileData = m_getTileDataFunc(tileIdx); hasEmptyTiles |= tileData == Tileset.k_TileData_Empty; TilesetBrush brush = Tileset.FindBrush(Tileset.GetBrushIdFromTileData(tileData)); if (brush) { tileData = TilesetBrush.ApplyAndMergeTileFlags(brush.PreviewTileData(), tileData); } int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId); if (tileId != Tileset.k_TileId_Empty) { TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, tileData, Tileset); } Color bgColor = new Color(1f - Tileset.BackgroundColor.r, 1f - Tileset.BackgroundColor.g, 1f - Tileset.BackgroundColor.b, Tileset.BackgroundColor.a); HandlesEx.DrawRectWithOutline(rVisualTile, m_selectedTileIdx == tileIdx ? new Color(0f, 0f, 0f, 0.1f) : new Color(), m_selectedTileIdx == tileIdx ? cSelectedBorderColor : bgColor); if (isLeftMouseReleased && rVisualTile.Contains(e.mousePosition)) { m_selectedTileIdx = tileIdx; EditorWindow wnd = EditorWindow.focusedWindow; TileSelectionWindow.Show(Tileset); TileSelectionWindow.Instance.Ping(); wnd.Focus(); GUI.FocusControl(""); } } } uint brushTileData = m_selectedTileIdx >= 0 ? m_getTileDataFunc(m_selectedTileIdx) : Tileset.k_TileData_Empty; brushTileData = DoTileDataPropertiesLayout(brushTileData, Tileset, AllowBrushSelection); if (m_selectedTileIdx >= 0) { m_setTileDataFunc(m_selectedTileIdx, brushTileData); } } GUILayout.EndHorizontal(); if (e.type == EventType.Repaint) { m_tileSelectionRect = GUILayoutUtility.GetLastRect(); } m_displayAutocompleteBtn = e.type == EventType.Layout ? !hasEmptyTiles && m_tileIdOff != 0 : m_displayAutocompleteBtn; if (size > 1 && m_displayAutocompleteBtn && GUILayout.Button("Autocomplete relative to last change")) { Undo.RecordObject(m_target, "MultipleTileChanged"); for (int tileIdx = 0; tileIdx < size; ++tileIdx) { if (tileIdx != m_tileIdOffSkipIdx) { int brushTileId = (int)(m_getTileDataFunc(tileIdx) & Tileset.k_TileDataMask_TileId); brushTileId += m_tileIdOff; if (brushTileId < 0 || brushTileId >= m_tileset.Tiles.Count) { m_setTileDataFunc(tileIdx, Tileset.k_TileData_Empty); } else { uint tileData = m_getTileDataFunc(tileIdx); tileData &= ~Tileset.k_TileDataMask_TileId; tileData |= (uint)(brushTileId & Tileset.k_TileDataMask_TileId); m_setTileDataFunc(tileIdx, tileData); } } } m_tileIdOff = 0; EditorUtility.SetDirty(m_target); } if (Tileset.TileSelection != null && Tileset.TileSelection.selectionData.Count == m_width * m_height && Tileset.TileSelection.rowLength == m_width) { if (GUILayout.Button("Autocomplete from selection")) { Undo.RecordObject(m_target, "MultipleTileChanged"); for (int tileIdx = 0; tileIdx < size; ++tileIdx) { int selectionIdx = (tileIdx % m_width) + (m_height - 1 - tileIdx / m_width) * m_width; int brushTileId = (int)(Tileset.TileSelection.selectionData[selectionIdx] & Tileset.k_TileDataMask_TileId); m_setTileDataFunc(tileIdx, (uint)(brushTileId & Tileset.k_TileDataMask_TileId)); } m_tileIdOff = 0; EditorUtility.SetDirty(m_target); } } if (ShowHelpBox) { EditorGUILayout.HelpBox(HelpBoxText, MessageType.Info); } }
public override void OnEnable() { base.OnEnable(); m_brush = (RandomBrush)target; if (m_brush.Tileset != null) { m_brush.Tileset.OnTileSelected += OnTileSelected; m_brush.Tileset.OnBrushSelected += OnBrushSelected; } m_randTileList = new ReorderableList(serializedObject, serializedObject.FindProperty("RandomTileList"), true, true, true, true); m_randTileList.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, "Random Tiles", EditorStyles.boldLabel); }; m_randTileList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { Rect rTile = rect; rTile.width = rTile.height = m_brush.Tileset.VisualTileSize.y; uint tileData = m_brush.RandomTileList[index].tileData; int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId); int brushId = Tileset.GetBrushIdFromTileData(tileData); TilesetBrush brush = m_brush.Tileset.FindBrush(brushId); if (brush) { GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset, brush.GetAnimUV()); } else if (tileId != Tileset.k_TileId_Empty) { GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset); } Rect rTileId = rect; rTileId.x += rTile.width + 10; rTileId.width -= rTile.width + 20; rTileId.height = rect.height / 2; if (brush) { GUI.Label(rTileId, "Brush Id(" + brushId + ")"); } else { GUI.Label(rTileId, "Id(" + tileId + ")"); } SerializedProperty randomTileDataProperty = m_randTileList.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty probabilityFactorProperty = randomTileDataProperty.FindPropertyRelative("probabilityFactor"); Rect rProbabilityField = new Rect(rect.x + rTile.width + 10f, rect.y + EditorGUIUtility.singleLineHeight * 2.5f, rect.width - rTile.width - 10f, EditorGUIUtility.singleLineHeight); Rect rProbabilityLabel = new Rect(rProbabilityField.x, rProbabilityField.y - EditorGUIUtility.singleLineHeight, rProbabilityField.width, rProbabilityField.height); float sumProbabilityFactor = m_brush.GetSumProbabilityFactor(); float probability = sumProbabilityFactor >= 0 ? probabilityFactorProperty.floatValue * 100f / sumProbabilityFactor : 100f; EditorGUI.PrefixLabel(rProbabilityLabel, new GUIContent("Probability (" + Mathf.RoundToInt(probability) + "%)")); EditorGUI.PropertyField(rProbabilityField, probabilityFactorProperty, GUIContent.none); if (probabilityFactorProperty.floatValue == 0f) { serializedObject.ApplyModifiedProperties(); sumProbabilityFactor = m_brush.GetSumProbabilityFactor(); if (sumProbabilityFactor <= 0f) { probabilityFactorProperty.floatValue = 0.01f; } } if (GUI.Button(new Rect(rect.x + rect.width - 50f, rect.y, 50f, EditorGUIUtility.singleLineHeight), "Clear")) { m_brush.RandomTileList[index].tileData = Tileset.k_TileData_Empty; } }; m_randTileList.onSelectCallback += (ReorderableList list) => { TileSelectionWindow.Show(m_brush.Tileset); TileSelectionWindow.Instance.Ping(); }; m_randTileList.onAddCallback += (ReorderableList list) => { if (list.index >= 0) { list.serializedProperty.InsertArrayElementAtIndex(list.index); } else { list.serializedProperty.InsertArrayElementAtIndex(0); } list.index = Mathf.Max(0, list.index + 1); list.serializedProperty.serializedObject.ApplyModifiedProperties(); m_brush.RandomTileList[list.index].probabilityFactor = 1f; if (m_brush.Tileset.SelectedTile != null) { m_randTileList.GrabKeyboardFocus(); OnTileSelected(m_brush.Tileset, -1, m_brush.Tileset.SelectedTileId); } }; }
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); }
void OnEnable() { s_instance = this; }
private SerializedProperty m_tileDataProperty = null; // used by PropertyDrawers void OnEnable() { s_instance = this; m_tilesetControl.OnTileSelected += HandleTileSelected; m_tilesetControl.OnBrushSelected += HandleBrushSelected; }
private bool m_displayAutocompleteBtn = false; // fix gui warning when button appears public void Display(Object target, uint[] aTileData, int[] tileIdxMap, int gridWidth, int gridHeight, Vector2 visualTileSize, int[] symbolIdxMap) { GUI.changed = m_hasChanged; m_hasChanged = false; m_target = target; m_aBrushTileData = aTileData; Event e = Event.current; bool isRightMouseReleased = e.type == EventType.MouseUp && e.button == 0; if (isRightMouseReleased && !m_tileSelectionRect.Contains(e.mousePosition)) { m_selectedTileIdx = -1; } GUILayout.BeginHorizontal(); // Draw Autotile Combination Control GUI.backgroundColor = Tileset.BackgroundColor; GUILayout.BeginScrollView(Vector2.zero, (GUIStyle)"Button", GUILayout.Width(visualTileSize.x * gridWidth), GUILayout.Height(visualTileSize.y * gridHeight + 1f)); GUI.backgroundColor = Color.white; for (int i = 0; i < gridWidth * gridHeight; ++i) { int gx = i % gridWidth; int gy = i / gridHeight; int tileIdx = tileIdxMap[i]; Rect rVisualTile = new Rect(gx * visualTileSize.x, gy * visualTileSize.y, visualTileSize.x, visualTileSize.y); int tileId = (int)(m_aBrushTileData[tileIdx] & Tileset.k_TileDataMask_TileId); if (tileId != Tileset.k_TileId_Empty) { //Rect tileUV = Tileset.Tiles[tileId].uv; //GUI.DrawTextureWithTexCoords(rVisualTile, Tileset.AtlasTexture, tileUV, true); TilesetEditor.DoGUIDrawTileFromTileData(rVisualTile, m_aBrushTileData[tileIdx], Tileset); } else if (symbolIdxMap != null) { GUI.DrawTexture(rVisualTile, GetTileSymbolTexture((byte)symbolIdxMap[i]), ScaleMode.ScaleToFit, true); } Color bgColor = new Color(1f - Tileset.BackgroundColor.r, 1f - Tileset.BackgroundColor.g, 1f - Tileset.BackgroundColor.b, Tileset.BackgroundColor.a); HandlesEx.DrawRectWithOutline(rVisualTile, m_selectedTileIdx == tileIdx ? new Color(0f, 0f, 0f, 0.1f) : new Color(), m_selectedTileIdx == tileIdx ? new Color(1f, 1f, 0f, 1f) : bgColor); if (isRightMouseReleased && rVisualTile.Contains(e.mousePosition)) { m_selectedTileIdx = tileIdx; EditorWindow wnd = EditorWindow.focusedWindow; TileSelectionWindow.Show(Tileset); TileSelectionWindow.Instance.Ping(); wnd.Focus(); GUI.FocusControl(""); } } GUILayout.EndScrollView(); uint brushTileData = m_selectedTileIdx >= 0 ? m_aBrushTileData[m_selectedTileIdx] : Tileset.k_TileData_Empty; brushTileData = DoTileDataPropertiesLayout(brushTileData, Tileset); if (m_selectedTileIdx >= 0) { m_aBrushTileData[m_selectedTileIdx] = brushTileData; } GUILayout.EndHorizontal(); if (e.type == EventType.Repaint) { m_tileSelectionRect = GUILayoutUtility.GetLastRect(); } bool hasEmptyTiles = ArrayUtility.Contains<uint>(m_aBrushTileData, Tileset.k_TileData_Empty); m_displayAutocompleteBtn = e.type == EventType.Layout ? !hasEmptyTiles && m_tileIdOff != 0 : m_displayAutocompleteBtn; if (m_displayAutocompleteBtn && GUILayout.Button("Autocomplete relative to last change")) { Undo.RecordObject(m_target, "MultipleTileChanged"); for (int i = 0; i < tileIdxMap.Length; ++i) { int tileIdx = tileIdxMap[i]; if (tileIdx != m_tileIdOffSkipIdx) { int brushTileId = (int)(m_aBrushTileData[tileIdx] & Tileset.k_TileDataMask_TileId); brushTileId += m_tileIdOff; if (brushTileId < 0 || brushTileId >= m_tileset.Tiles.Count) { m_aBrushTileData[tileIdx] = Tileset.k_TileData_Empty; } else { m_aBrushTileData[tileIdx] &= ~Tileset.k_TileDataMask_TileId; m_aBrushTileData[tileIdx] |= (uint)(brushTileId & Tileset.k_TileDataMask_TileId); } } } m_tileIdOff = 0; EditorUtility.SetDirty(m_target); } if (ShowHelpBox) { EditorGUILayout.HelpBox("Select a tile from the grid, then select a tile from Tile Selection Window to change the tile.", MessageType.Info); } }
public override void OnEnable() { base.OnEnable(); m_brush = (AnimBrush)target; if (m_brush.Tileset != null) { m_brush.Tileset.OnTileSelected += OnTileSelected; } m_frameList = new ReorderableList(serializedObject, serializedObject.FindProperty("AnimFrames"), true, true, true, true); m_frameList.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, "Anim Frames", EditorStyles.boldLabel); }; m_frameList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { Rect rTile = rect; rTile.width = rTile.height = m_brush.Tileset.VisualTileSize.y; uint tileData = m_brush.AnimFrames[index].tileId; int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId); if (tileId != Tileset.k_TileId_Empty) { Rect tileUV = m_brush.Tileset.Tiles[tileId].uv; tileUV.position += m_brush.AnimFrames[index].UVOffset; GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset); } Rect rTileId = rect; rTileId.x += rTile.width + 20; rTileId.width -= rTile.width + 20; rTileId.height = rect.height / 2; GUI.Label(rTileId, "Id(" + tileId + ")"); Vector2 uvOffset = m_brush.AnimFrames[index].UVOffset; Vector2 UvPxOffset = new Vector2(uvOffset.x / m_brush.Tileset.AtlasTexture.texelSize.x, uvOffset.y / m_brush.Tileset.AtlasTexture.texelSize.y); rTileId.y += rTileId.height; GUI.Label(rTileId, "UVOffset(" + UvPxOffset.x + "," + UvPxOffset.y + ")"); int btnIdx = 0; float btnSize = rect.height / 2; for (int gy = 0; gy < 2; ++gy) { for (int gx = 0; gx < 3; ++gx, ++btnIdx) { Rect btnRect = new Rect(rect.x + rect.width - (gx + 1) * btnSize, rect.y + gy * rect.height / 2f, btnSize, btnSize); switch (btnIdx) { case 0: if (GUI.Button(btnRect, "R")) { uvOffset = Vector2.zero; } break; case 1: if (GUI.Button(btnRect, "▲")) { uvOffset.y -= m_brush.Tileset.AtlasTexture.texelSize.y; } break; case 3: if (GUI.Button(btnRect, "▶")) { uvOffset.x -= m_brush.Tileset.AtlasTexture.texelSize.x; } break; case 4: if (GUI.Button(btnRect, "▼")) { uvOffset.y += m_brush.Tileset.AtlasTexture.texelSize.y; } break; case 5: if (GUI.Button(btnRect, "◀")) { uvOffset.x += m_brush.Tileset.AtlasTexture.texelSize.x; } break; } } } m_brush.AnimFrames[index].UVOffset = uvOffset; }; m_frameList.onSelectCallback += (ReorderableList list) => { TileSelectionWindow.Show(m_brush.Tileset); TileSelectionWindow.Instance.Ping(); }; }
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); }