public void SetValue(int value) { Label.text = value.ToString(); Label.fontSize = CalculateFontSize(value); TileStyle style = TileStyles.GetStyleForValue(value); TileRenderer.material.color = style.Color; Label.color = style.TextColor; }
public void OnGUI() { GUIStyle _miniButtonStyle = null; _miniButtonStyle = new GUIStyle(GUI.skin.button); _miniButtonStyle.fixedWidth = 24.0f; _miniButtonStyle.fixedHeight = 24.0f; _miniButtonStyle.fontSize = 12; _miniButtonStyle.margin = new RectOffset(3, 3, 3, 3); GUIStyle _mediumButtonStyle = null; _mediumButtonStyle = new GUIStyle(GUI.skin.button); _mediumButtonStyle.fixedWidth = 81.0f; _mediumButtonStyle.fixedHeight = 24.0f; _mediumButtonStyle.fontSize = 9; _mediumButtonStyle.margin = new RectOffset(3, 3, 3, 3); GUIStyle _bigButtonStyle = null; _bigButtonStyle = new GUIStyle(GUI.skin.button); _bigButtonStyle.fixedWidth = 174.0f; _bigButtonStyle.fixedHeight = 24.0f; _bigButtonStyle.fontSize = 9; _bigButtonStyle.margin = new RectOffset(3, 3, 3, 3); GUIStyle _mainBox = null; _mainBox = new GUIStyle(GUI.skin.customStyles[0]); _mainBox.fixedWidth = 200.0f; GUIStyle _helpStyle = null; _helpStyle = new GUIStyle(GUI.skin.label); _helpStyle.fontSize = 9; Color32 _color1 = new Color32((byte)100, (byte)255, (byte)255, (byte)255); Color32 _color2 = new Color32((byte)250, (byte)255, (byte)255, (byte)255); Color32 _color4 = new Color32((byte)255, (byte)255, (byte)200, (byte)255); Color32 _color3 = new Color32((byte)255, (byte)255, (byte)100, (byte)255); GUILayout.BeginVertical(_mainBox); EditorGUILayout.Space(); if (_toggleStyle) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Tile Styles", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleStyle = !_toggleStyle; _toggleHelpStyles = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpStyles = !_toggleHelpStyles; _toggleStyle = true; } EditorGUILayout.EndHorizontal(); if (_toggleStyle) { EditorGUILayout.Space(); if (_toggleHelpStyles) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Replace style of tiles and objects \nCycle trough objects in seleced style \nRotate tiles", _helpStyle); EditorGUILayout.EndVertical(); } GUI.color = _color4; if (_index >= 0) { _index = EditorGUILayout.Popup(_index, styleNames); _style = styles[_index]; } GUI.color = _color3; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Replace All", _bigButtonStyle)) { ReplaceStyles("All"); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = _color4; if (GUILayout.Button("Tiles", _mediumButtonStyle)) { ReplaceStyles("Tile"); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Objects", _mediumButtonStyle)) { ReplaceStyles("Object"); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUI.color = _color3; if (GUILayout.Button("Prev Tile", EditorStyles.miniButtonLeft)) { CycleGameObjects(false); } GUI.color = _color4; if (GUILayout.Button("Rotate", EditorStyles.miniButtonMid)) { RotateGameObjects(); } GUI.color = _color3; if (GUILayout.Button("Next Tile", EditorStyles.miniButtonRight)) { CycleGameObjects(true); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (_toggleMove) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Move & Duplicate", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleMove = !_toggleMove; _toggleHelpMove = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpMove = !_toggleHelpMove; _toggleMove = true; } EditorGUILayout.EndHorizontal(); if (_toggleMove) { EditorGUILayout.Space(); if (_toggleHelpMove) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Blue arrows moves tiles \nYellow arrows duplicates tiles", _helpStyle); EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical(); GUI.color = _color2; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("△", _miniButtonStyle)) { Move(new Vector3(0.0f, 0.0f, -1.0f), false); } GUI.color = _color1; Event e = Event.current; if (GUILayout.Button("▲", _miniButtonStyle)) { Move(new Vector3(0.0f, 1.0f, 0.0f), false); } GUI.color = _color2; if (GUILayout.Button("▽", _miniButtonStyle)) { Move(new Vector3(0.0f, 0.0f, 1.0f), false); } GUILayout.FlexibleSpace(); GUI.color = _color4; if (GUILayout.Button("△", _miniButtonStyle)) { Move(new Vector3(0.0f, 0.0f, -1.0f), true); } GUI.color = _color3; if (GUILayout.Button("▲", _miniButtonStyle) || e.character == 'k') { Move(new Vector3(0.0f, 1.0f, 0.0f), true); } GUI.color = _color4; if (GUILayout.Button("▽", _miniButtonStyle)) { Move(new Vector3(0.0f, 0.0f, 1.0f), true); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = _color1; if (GUILayout.Button("◄", _miniButtonStyle)) { Move(new Vector3(1.0f, 0.0f, 0.0f), false); } if (GUILayout.Button("▼", _miniButtonStyle)) { Move(new Vector3(0.0f, -1.0f, 0.0f), false); } if (GUILayout.Button("►", _miniButtonStyle)) { Move(new Vector3(-1.0f, 0.0f, 0.0f), false); } GUILayout.FlexibleSpace(); GUI.color = _color3; if (GUILayout.Button("◄", _miniButtonStyle)) { Move(new Vector3(1.0f, 0.0f, 0.0f), true); } if (GUILayout.Button("▼", _miniButtonStyle)) { Move(new Vector3(0.0f, -1.0f, 0.0f), true); } if (GUILayout.Button("►", _miniButtonStyle)) { Move(new Vector3(-1.0f, 0.0f, 0.0f), true); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } EditorGUILayout.Space(); if (_toggleRemove) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Remove Hidden Sides", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleRemove = !_toggleRemove; _toggleHelpSides = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpSides = !_toggleHelpSides; _toggleRemove = true; } EditorGUILayout.EndHorizontal(); if (_toggleRemove) { EditorGUILayout.Space(); if (_toggleHelpSides) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Edit meshes to remove geometry \n\nArrows manually remove side \nAuto Destroy remove blocked sides\nReset Sides revert to prefab", _helpStyle); EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical(); GUI.color = _color1; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("△", _miniButtonStyle)) { removey("back"); } GUI.color = _color2; if (GUILayout.Button("▲", _miniButtonStyle)) { removey("up"); } GUI.color = _color1; if (GUILayout.Button("▽", _miniButtonStyle)) { removey("front"); } GUILayout.FlexibleSpace(); GUI.color = _color3; if (GUILayout.Button("Auto Destroy", _mediumButtonStyle)) { if (Selection.activeTransform.GetComponent(typeof(TileToolGroup)) != null) { Transform[] glist = null; glist = new Transform[Selection.activeTransform.childCount]; Transform o = Selection.activeTransform; for (int k = 0; k < Selection.activeTransform.childCount; k++) { glist[k] = o.GetChild(k); } _selection = glist; } else { _selection = Selection.transforms; //Add selection to array } Undo.RecordObjects(_selection, "TileTool: Auto Destroy Sides"); for (int j = 0; j < _selection.Length; j++) { float pp = (float)j; EditorUtility.DisplayProgressBar("TileTool: Auto Destroy Sides", "", (pp + _selection.Length) / (_selection.Length * 2)); AutoRemoveSides(_selection[j].gameObject); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = _color2; if (GUILayout.Button("◄", _miniButtonStyle)) { removey("left"); } if (GUILayout.Button("▼", _miniButtonStyle)) { removey("down"); } if (GUILayout.Button("►", _miniButtonStyle)) { removey("right"); } GUILayout.FlexibleSpace(); GUI.color = _color4; if (GUILayout.Button("Reset Sides", _mediumButtonStyle)) { ResetToPrefab(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); GUI.color = Color.white; } EditorGUILayout.Space(); if (_toggleGroup) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Grouping", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleGroup = !_toggleGroup; _toggleHelpGroups = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpGroups = !_toggleHelpGroups; _toggleGroup = true; } EditorGUILayout.EndHorizontal(); if (_toggleGroup) { EditorGUILayout.Space(); if (_toggleHelpGroups) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Group selected tiles or objects", _helpStyle); EditorGUILayout.EndVertical(); } GUI.color = _color3; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Group", _mediumButtonStyle)) { Group(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("UnGroup", _mediumButtonStyle)) { UnGroup(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // EditorGUILayout.LabelField("Undo not supported for grouping", EditorStyles.miniLabel); } EditorGUILayout.Space(); if (_toggleReplace) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Replace GameObjects", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleReplace = !_toggleReplace; _toggleHelpReplace = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpReplace = !_toggleHelpReplace; _toggleReplace = true; } EditorGUILayout.EndHorizontal(); if (_toggleReplace) { EditorGUILayout.Space(); if (_toggleHelpReplace) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Replace selected objects in scene\nwith prefab", _helpStyle); EditorGUILayout.EndVertical(); } GUI.color = _color4; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); _replaceObject = (GameObject)EditorGUILayout.ObjectField(_replaceObject, typeof(GameObject), false, GUILayout.Width(81.0f)); GUI.color = _color3; GUILayout.FlexibleSpace(); if (GUILayout.Button("Replace", _mediumButtonStyle)) { if (_replaceObject != null) { ReplaceGameObjects(); } else { Debug.LogError("No Prefab assigned"); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (_toggleSnap) { GUI.color = _color1; } else { GUI.color = _color2; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Snapping", EditorStyles.toolbarButton, GUILayout.Width(180.0f))) { _toggleSnap = !_toggleSnap; _toggleHelpSnap = false; } GUI.color = _color3; if (GUILayout.Button("?", EditorStyles.toolbarButton, GUILayout.Width(20.0f))) { _toggleHelpSnap = !_toggleHelpSnap; _toggleSnap = true; } EditorGUILayout.EndHorizontal(); if (_toggleSnap) { EditorGUILayout.Space(); if (_toggleHelpSnap) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.TextArea("Snap gameobject position\nAutosnap only works with tiles", _helpStyle); EditorGUILayout.EndVertical(); } GUI.color = _color4; if (Selection.transforms.Length < _autoSnapMax) { doSnap = EditorGUILayout.Toggle("Autosnap", doSnap); } else { doSnap = EditorGUILayout.Toggle("Autosnap (disabled)", doSnap); } snapValue = EditorGUILayout.FloatField("Value", snapValue); _autoSnapMax = EditorGUILayout.IntField("Max Autosnap", _autoSnapMax); EditorGUILayout.Space(); GUI.color = _color3; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Snap", _bigButtonStyle)) { snap(false); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } //EditorGUILayout.LabelField("Selected Objects: " + Selection.transforms.Length, EditorStyles.miniLabel); GUILayout.EndVertical(); }
public TileStyle(int value, string colorString, bool blackText = false) { Value = value; Color = TileStyles.ParseColor(colorString); TextColor = TileStyles.ParseColor(blackText ? blackColor : whiteColor); }