Skip to content

Commit f1c3a20

Browse files
-Add tooltips for editors for RuleTile, RuleOverrideTile and AdvancedRuleOverrideTile (#281)
* -Add tooltips for editors for RuleTile, RuleOverrideTile and AdvancedRuleOverrideTile * -Fix inspector height for TilingRule.OutputSprite.Animation -Adjust padding and line height for RuleTile editor
1 parent aaf8aaa commit f1c3a20

File tree

3 files changed

+72
-23
lines changed

3 files changed

+72
-23
lines changed

Editor/Tiles/RuleOverrideTile/AdvancedRuleOverrideTileEditor.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ namespace UnityEditor
1111
[CustomEditor(typeof(AdvancedRuleOverrideTile))]
1212
public class AdvancedRuleOverrideTileEditor : RuleOverrideTileEditor
1313
{
14+
private static class Styles
15+
{
16+
public static readonly GUIContent defaultSprite = EditorGUIUtility.TrTextContent("Default Sprite"
17+
, "Overrides the default Sprite for the original Rule Tile.");
18+
public static readonly GUIContent defaultGameObject = EditorGUIUtility.TrTextContent("Default GameObject"
19+
, "Overrides the default GameObject for the original Rule Tile.");
20+
public static readonly GUIContent defaultCollider = EditorGUIUtility.TrTextContent("Default Collider"
21+
, "Overrides the default Collider for the original Rule Tile.");
22+
}
23+
1424
/// <summary>
1525
/// The AdvancedRuleOverrideTile being edited.
1626
/// </summary>
@@ -23,7 +33,6 @@ public class AdvancedRuleOverrideTileEditor : RuleOverrideTileEditor
2333

2434
static float k_DefaultElementHeight { get { return RuleTileEditor.k_DefaultElementHeight; } }
2535
static float k_SingleLineHeight { get { return RuleTileEditor.k_SingleLineHeight; } }
26-
static float k_LabelWidth { get { return RuleTileEditor.k_LabelWidth; } }
2736

2837
/// <summary>
2938
/// OnEnable for the AdvancedRuleOverrideTileEditor
@@ -49,9 +58,9 @@ public override void OnInspectorGUI()
4958
DrawTileField();
5059

5160
EditorGUI.BeginChangeCheck();
52-
overrideTile.m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", overrideTile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
53-
overrideTile.m_DefaultGameObject = EditorGUILayout.ObjectField("Default GameObject", overrideTile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
54-
overrideTile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", overrideTile.m_DefaultColliderType);
61+
overrideTile.m_DefaultSprite = EditorGUILayout.ObjectField(Styles.defaultSprite, overrideTile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
62+
overrideTile.m_DefaultGameObject = EditorGUILayout.ObjectField(Styles.defaultGameObject, overrideTile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
63+
overrideTile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup(Styles.defaultCollider, overrideTile.m_DefaultColliderType);
5564
if (EditorGUI.EndChangeCheck())
5665
SaveTile();
5766

Editor/Tiles/RuleOverrideTile/RuleOverrideTileEditor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace UnityEditor
1111
[CustomEditor(typeof(RuleOverrideTile))]
1212
public class RuleOverrideTileEditor : Editor
1313
{
14+
private static class Styles
15+
{
16+
public static readonly GUIContent overrideTile = EditorGUIUtility.TrTextContent("Tile"
17+
, "The Rule Tile to override.");
18+
}
19+
1420
/// <summary>
1521
/// The RuleOverrideTile being edited
1622
/// </summary>
@@ -255,7 +261,7 @@ public void DrawGameObjectElement(Rect rect, int index, bool active, bool focuse
255261
public void DrawTileField()
256262
{
257263
EditorGUI.BeginChangeCheck();
258-
RuleTile tile = EditorGUILayout.ObjectField("Tile", overrideTile.m_Tile, typeof(RuleTile), false) as RuleTile;
264+
RuleTile tile = EditorGUILayout.ObjectField(Styles.overrideTile, overrideTile.m_Tile, typeof(RuleTile), false) as RuleTile;
259265
if (EditorGUI.EndChangeCheck())
260266
{
261267
if (!LoopCheck(tile))

Editor/Tiles/RuleTile/RuleTileEditor.cs

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ public static Texture2D[] autoTransforms
7878
}
7979
}
8080

81+
private static class Styles
82+
{
83+
public static readonly GUIContent defaultSprite = EditorGUIUtility.TrTextContent("Default Sprite"
84+
, "The default Sprite set when creating a new Rule.");
85+
public static readonly GUIContent defaultGameObject = EditorGUIUtility.TrTextContent("Default GameObject"
86+
, "The default GameObject set when creating a new Rule.");
87+
public static readonly GUIContent defaultCollider = EditorGUIUtility.TrTextContent("Default Collider"
88+
, "The default Collider Type set when creating a new Rule.");
89+
90+
public static readonly GUIContent extendNeighbor = EditorGUIUtility.TrTextContent("Extend Neighbor"
91+
, "Enabling this allows you to increase the range of neighbors beyond the 3x3 box.");
92+
93+
public static readonly GUIContent tilingRules = EditorGUIUtility.TrTextContent("Tiling Rules");
94+
public static readonly GUIContent tilingRulesGameObject = EditorGUIUtility.TrTextContent("GameObject"
95+
, "The GameObject for the Tile which fits this Rule.");
96+
public static readonly GUIContent tilingRulesCollider = EditorGUIUtility.TrTextContent("Collider"
97+
, "The Collider Type for the Tile which fits this Rule");
98+
public static readonly GUIContent tilingRulesOutput = EditorGUIUtility.TrTextContent("Output"
99+
, "The Output for the Tile which fits this Rule. Each Output type has its own properties.");
100+
101+
public static readonly GUIContent tilingRulesNoise = EditorGUIUtility.TrTextContent("Noise"
102+
, "The Perlin noise factor when placing the Tile.");
103+
public static readonly GUIContent tilingRulesShuffle = EditorGUIUtility.TrTextContent("Shuffle"
104+
, "The randomized transform given to the Tile when placing it.");
105+
public static readonly GUIContent tilingRulesRandomSize = EditorGUIUtility.TrTextContent("Size"
106+
, "The number of Sprites to randomize from.");
107+
108+
public static readonly GUIContent tilingRulesMinSpeed = EditorGUIUtility.TrTextContent("Min Speed"
109+
, "The minimum speed at which the animation is played.");
110+
public static readonly GUIContent tilingRulesMaxSpeed = EditorGUIUtility.TrTextContent("Max Speed"
111+
, "The maximum speed at which the animation is played.");
112+
public static readonly GUIContent tilingRulesAnimationSize = EditorGUIUtility.TrTextContent("Size"
113+
, "The number of Sprites in the animation.");
114+
}
115+
81116
/// <summary>
82117
/// The RuleTile being edited
83118
/// </summary>
@@ -115,11 +150,11 @@ public static Texture2D[] autoTransforms
115150
/// <summary>
116151
/// Padding between Rule Elements
117152
/// </summary>
118-
public const float k_PaddingBetweenRules = 26f;
153+
public const float k_PaddingBetweenRules = 8f;
119154
/// <summary>
120155
/// Single line height
121156
/// </summary>
122-
public const float k_SingleLineHeight = 16f;
157+
public const float k_SingleLineHeight = 18f;
123158
/// <summary>
124159
/// Width for labels
125160
/// </summary>
@@ -216,10 +251,8 @@ public float GetElementHeight(RuleTile.TilingRuleOutput rule)
216251
switch (rule.m_Output)
217252
{
218253
case RuleTile.TilingRule.OutputSprite.Random:
219-
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 3) + k_PaddingBetweenRules;
220-
break;
221254
case RuleTile.TilingRule.OutputSprite.Animation:
222-
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 2) + k_PaddingBetweenRules;
255+
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 3) + k_PaddingBetweenRules;
223256
break;
224257
}
225258

@@ -359,14 +392,14 @@ public static List<RuleOverrideTile> FindAffectedOverrideTiles(RuleTile target)
359392
/// <param name="rect">GUI Rect to draw the header at</param>
360393
public void OnDrawHeader(Rect rect)
361394
{
362-
GUI.Label(rect, "Tiling Rules");
395+
GUI.Label(rect, Styles.tilingRules);
363396

364397
Rect toggleRect = new Rect(rect.xMax - rect.height, rect.y, rect.height, rect.height);
365398
Rect toggleLabelRect = new Rect(rect.x, rect.y, rect.width - toggleRect.width - 5f, rect.height);
366399

367400
EditorGUI.BeginChangeCheck();
368401
extendNeighbor = EditorGUI.Toggle(toggleRect, extendNeighbor);
369-
EditorGUI.LabelField(toggleLabelRect, "Extend Neighbor", new GUIStyle()
402+
EditorGUI.LabelField(toggleLabelRect, Styles.extendNeighbor, new GUIStyle()
370403
{
371404
alignment = TextAnchor.MiddleRight,
372405
fontStyle = FontStyle.Bold,
@@ -392,9 +425,9 @@ public override void OnInspectorGUI()
392425
{
393426
EditorGUI.BeginChangeCheck();
394427

395-
tile.m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
396-
tile.m_DefaultGameObject = EditorGUILayout.ObjectField("Default GameObject", tile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
397-
tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", tile.m_DefaultColliderType);
428+
tile.m_DefaultSprite = EditorGUILayout.ObjectField(Styles.defaultSprite, tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
429+
tile.m_DefaultGameObject = EditorGUILayout.ObjectField(Styles.defaultGameObject, tile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
430+
tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup(Styles.defaultCollider, tile.m_DefaultColliderType);
398431

399432
DrawCustomFields(false);
400433

@@ -701,39 +734,40 @@ public virtual void SpriteOnGUI(Rect rect, RuleTile.TilingRuleOutput tilingRule)
701734
public void RuleInspectorOnGUI(Rect rect, RuleTile.TilingRuleOutput tilingRule)
702735
{
703736
float y = rect.yMin;
704-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "GameObject");
737+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesGameObject);
705738
tilingRule.m_GameObject = (GameObject)EditorGUI.ObjectField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), "", tilingRule.m_GameObject, typeof(GameObject), false);
706739
y += k_SingleLineHeight;
707-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Collider");
740+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesCollider);
708741
tilingRule.m_ColliderType = (Tile.ColliderType)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_ColliderType);
709742
y += k_SingleLineHeight;
710-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Output");
743+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesOutput);
711744
tilingRule.m_Output = (RuleTile.TilingRule.OutputSprite)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_Output);
712745
y += k_SingleLineHeight;
713746

714747
if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Animation)
715748
{
716-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Min Speed");
749+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesMinSpeed);
717750
tilingRule.m_MinAnimationSpeed = EditorGUI.FloatField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_MinAnimationSpeed);
718751
y += k_SingleLineHeight;
719-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Max Speed");
752+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesMaxSpeed);
720753
tilingRule.m_MaxAnimationSpeed = EditorGUI.FloatField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_MaxAnimationSpeed);
721754
y += k_SingleLineHeight;
722755
}
723756
if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Random)
724757
{
725-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Noise");
758+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesNoise);
726759
tilingRule.m_PerlinScale = EditorGUI.Slider(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_PerlinScale, 0.001f, 0.999f);
727760
y += k_SingleLineHeight;
728761

729-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Shuffle");
762+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesShuffle);
730763
tilingRule.m_RandomTransform = (RuleTile.TilingRule.Transform)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_RandomTransform);
731764
y += k_SingleLineHeight;
732765
}
733766

734767
if (tilingRule.m_Output != RuleTile.TilingRule.OutputSprite.Single)
735768
{
736-
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Size");
769+
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight)
770+
, tilingRule.m_Output == RuleTile.TilingRuleOutput.OutputSprite.Animation ? Styles.tilingRulesAnimationSize : Styles.tilingRulesRandomSize);
737771
EditorGUI.BeginChangeCheck();
738772
int newLength = EditorGUI.DelayedIntField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_Sprites.Length);
739773
if (EditorGUI.EndChangeCheck())

0 commit comments

Comments
 (0)