public override void OnInspectorGUI() { serializedObject.UpdateIfRequiredOrScript(); EditorGUILayout.PropertyField(m_AnimationFrameRate, Styles.animationFrameRateLabel); EditorGUILayout.PropertyField(m_TilemapColor, Styles.tilemapColorLabel); EditorGUILayout.PropertyField(m_TileAnchor, Styles.tileAnchorLabel); EditorGUILayout.PropertyField(m_Orientation, Styles.orientationLabel); GUI.enabled = (!m_Orientation.hasMultipleDifferentValues && Tilemap.Orientation.Custom == tilemap.orientation); if (targets.Length > 1) { EditorGUILayout.PropertyField(m_OrientationMatrix, true); } else { EditorGUI.BeginChangeCheck(); var orientationMatrix = TileEditor.TransformMatrixOnGUI(tilemap.orientationMatrix); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Tilemap property change"); tilemap.orientationMatrix = orientationMatrix; } } GUI.enabled = true; serializedObject.ApplyModifiedProperties(); }
public static Matrix4x4 TransformMatrixOnGUI(Matrix4x4 matrix) { Matrix4x4 result = matrix; if (matrix.ValidTRS()) { EditorGUI.BeginChangeCheck(); Vector3 vector = TileEditor.Round(matrix.GetColumn(3), 3); Vector3 vector2 = TileEditor.Round(matrix.rotation.eulerAngles, 3); Vector3 vector3 = TileEditor.Round(matrix.lossyScale, 3); vector = EditorGUILayout.Vector3Field(TileEditor.Styles.positionLabel, vector, new GUILayoutOption[0]); vector2 = EditorGUILayout.Vector3Field(TileEditor.Styles.rotationLabel, vector2, new GUILayoutOption[0]); vector3 = EditorGUILayout.Vector3Field(TileEditor.Styles.scaleLabel, vector3, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck() && vector3.x != 0f && vector3.y != 0f && vector3.z != 0f) { result = Matrix4x4.TRS(vector, Quaternion.Euler(vector2), vector3); } } else { GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Label(TileEditor.Styles.invalidMatrixLabel, new GUILayoutOption[0]); if (GUILayout.Button(TileEditor.Styles.resetMatrixLabel, new GUILayoutOption[0])) { result = Matrix4x4.identity; } GUILayout.EndVertical(); } return(result); }
public override void OnInspectorGUI() { TileEditor.DoTilePreview(this.tile.sprite, this.tile.color, Matrix4x4.identity); base.serializedObject.Update(); EditorGUILayout.PropertyField(this.m_Sprite, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_Color, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_ColliderType, new GUILayoutOption[0]); base.serializedObject.ApplyModifiedProperties(); }
public override void OnSelectionInspectorGUI() { BoundsInt position = GridSelection.position; Tilemap component = GridSelection.target.GetComponent <Tilemap>(); int num = position.size.x * position.size.y * position.size.z; if (component != null && num > 0) { base.OnSelectionInspectorGUI(); GUILayout.Space(10f); if (this.m_SelectionTiles == null || this.m_SelectionTiles.Length != num) { this.m_SelectionTiles = new TileBase[num]; this.m_SelectionColors = new Color[num]; this.m_SelectionMatrices = new Matrix4x4[num]; this.m_SelectionFlagsArray = new TileFlags[num]; this.m_SelectionSprites = new Sprite[num]; this.m_SelectionColliderTypes = new Tile.ColliderType[num]; } int num2 = 0; foreach (Vector3Int current in position.allPositionsWithin) { this.m_SelectionTiles[num2] = component.GetTile(current); this.m_SelectionColors[num2] = component.GetColor(current); this.m_SelectionMatrices[num2] = component.GetTransformMatrix(current); this.m_SelectionFlagsArray[num2] = component.GetTileFlags(current); this.m_SelectionSprites[num2] = component.GetSprite(current); this.m_SelectionColliderTypes[num2] = component.GetColliderType(current); num2++; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_SelectionTiles.Any((TileBase tile) => tile != this.m_SelectionTiles.First <TileBase>()); Vector3Int position2 = new Vector3Int(position.xMin, position.yMin, position.zMin); TileBase tile2 = EditorGUILayout.ObjectField(GridBrushEditor.Styles.tileLabel, component.GetTile(position2), typeof(TileBase), false, new GUILayoutOption[0]) as TileBase; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(component, "Edit Tilemap"); foreach (Vector3Int current2 in position.allPositionsWithin) { component.SetTile(current2, tile2); } } bool flag = this.m_SelectionFlagsArray.All((TileFlags flags) => (flags & TileFlags.LockColor) == (this.m_SelectionFlagsArray.First <TileFlags>() & TileFlags.LockColor)); using (new EditorGUI.DisabledScope(!flag || (this.m_SelectionFlagsArray[0] & TileFlags.LockColor) != TileFlags.None)) { EditorGUI.showMixedValue = this.m_SelectionColors.Any((Color color) => color != this.m_SelectionColors.First <Color>()); EditorGUI.BeginChangeCheck(); Color color2 = EditorGUILayout.ColorField(GridBrushEditor.Styles.colorLabel, this.m_SelectionColors[0], new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(component, "Edit Tilemap"); foreach (Vector3Int current3 in position.allPositionsWithin) { component.SetColor(current3, color2); } } } bool flag2 = this.m_SelectionFlagsArray.All((TileFlags flags) => (flags & TileFlags.LockTransform) == (this.m_SelectionFlagsArray.First <TileFlags>() & TileFlags.LockTransform)); using (new EditorGUI.DisabledScope(!flag2 || (this.m_SelectionFlagsArray[0] & TileFlags.LockTransform) != TileFlags.None)) { EditorGUI.showMixedValue = this.m_SelectionMatrices.Any((Matrix4x4 matrix) => matrix != this.m_SelectionMatrices.First <Matrix4x4>()); EditorGUI.BeginChangeCheck(); Matrix4x4 transform = TileEditor.TransformMatrixOnGUI(this.m_SelectionMatrices[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(component, "Edit Tilemap"); foreach (Vector3Int current4 in position.allPositionsWithin) { component.SetTransformMatrix(current4, transform); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = this.m_SelectionSprites.Any((Sprite sprite) => sprite != this.m_SelectionSprites.First <Sprite>()); EditorGUILayout.ObjectField(GridBrushEditor.Styles.spriteLabel, this.m_SelectionSprites[0], typeof(Sprite), false, new GUILayoutOption[] { GUILayout.Height(16f) }); EditorGUI.showMixedValue = this.m_SelectionColliderTypes.Any((Tile.ColliderType colliderType) => colliderType != this.m_SelectionColliderTypes.First <Tile.ColliderType>()); EditorGUILayout.EnumPopup(GridBrushEditor.Styles.colliderTypeLabel, this.m_SelectionColliderTypes[0], new GUILayoutOption[0]); EditorGUI.showMixedValue = !flag; EditorGUILayout.Toggle(GridBrushEditor.Styles.lockColorLabel, (this.m_SelectionFlagsArray[0] & TileFlags.LockColor) != TileFlags.None, new GUILayoutOption[0]); EditorGUI.showMixedValue = !flag2; EditorGUILayout.Toggle(GridBrushEditor.Styles.lockTransformLabel, (this.m_SelectionFlagsArray[0] & TileFlags.LockTransform) != TileFlags.None, new GUILayoutOption[0]); } EditorGUI.showMixedValue = false; } }
public override void OnSelectionInspectorGUI() { BoundsInt selection = GridSelection.position; Tilemap tilemap = GridSelection.target.GetComponent <Tilemap>(); int cellCount = selection.size.x * selection.size.y * selection.size.z; if (tilemap != null && cellCount > 0) { base.OnSelectionInspectorGUI(); GUILayout.Space(10f); if (m_SelectionTiles == null || m_SelectionTiles.Length != cellCount) { m_SelectionTiles = new TileBase[cellCount]; m_SelectionColors = new Color[cellCount]; m_SelectionMatrices = new Matrix4x4[cellCount]; m_SelectionFlagsArray = new TileFlags[cellCount]; m_SelectionSprites = new Sprite[cellCount]; m_SelectionColliderTypes = new Tile.ColliderType[cellCount]; } int index = 0; foreach (var p in selection.allPositionsWithin) { m_SelectionTiles[index] = tilemap.GetTile(p); m_SelectionColors[index] = tilemap.GetColor(p); m_SelectionMatrices[index] = tilemap.GetTransformMatrix(p); m_SelectionFlagsArray[index] = tilemap.GetTileFlags(p); m_SelectionSprites[index] = tilemap.GetSprite(p); m_SelectionColliderTypes[index] = tilemap.GetColliderType(p); index++; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First()); var position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin); TileBase newTile = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTile(p, newTile); } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First()); EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight)); } bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor)); using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0)) { EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First()); EditorGUI.BeginChangeCheck(); Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetColor(p, newColor); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First()); EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]); } bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform)); using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0)) { EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First()); EditorGUI.BeginChangeCheck(); Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTransformMatrix(p, newTransformMatrix); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = !colorFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0); EditorGUI.showMixedValue = !transformFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0); } EditorGUI.showMixedValue = false; } }