Skip to content

Commit

Permalink
-Add tooltips for editors for RuleTile, RuleOverrideTile and Advanced…
Browse files Browse the repository at this point in the history
…RuleOverrideTile (#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
  • Loading branch information
ChuanXin-Unity committed May 28, 2021
1 parent aaf8aaa commit f1c3a20
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 23 deletions.
17 changes: 13 additions & 4 deletions Editor/Tiles/RuleOverrideTile/AdvancedRuleOverrideTileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace UnityEditor
[CustomEditor(typeof(AdvancedRuleOverrideTile))]
public class AdvancedRuleOverrideTileEditor : RuleOverrideTileEditor
{
private static class Styles
{
public static readonly GUIContent defaultSprite = EditorGUIUtility.TrTextContent("Default Sprite"
, "Overrides the default Sprite for the original Rule Tile.");
public static readonly GUIContent defaultGameObject = EditorGUIUtility.TrTextContent("Default GameObject"
, "Overrides the default GameObject for the original Rule Tile.");
public static readonly GUIContent defaultCollider = EditorGUIUtility.TrTextContent("Default Collider"
, "Overrides the default Collider for the original Rule Tile.");
}

/// <summary>
/// The AdvancedRuleOverrideTile being edited.
/// </summary>
Expand All @@ -23,7 +33,6 @@ public class AdvancedRuleOverrideTileEditor : RuleOverrideTileEditor

static float k_DefaultElementHeight { get { return RuleTileEditor.k_DefaultElementHeight; } }
static float k_SingleLineHeight { get { return RuleTileEditor.k_SingleLineHeight; } }
static float k_LabelWidth { get { return RuleTileEditor.k_LabelWidth; } }

/// <summary>
/// OnEnable for the AdvancedRuleOverrideTileEditor
Expand All @@ -49,9 +58,9 @@ public override void OnInspectorGUI()
DrawTileField();

EditorGUI.BeginChangeCheck();
overrideTile.m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", overrideTile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
overrideTile.m_DefaultGameObject = EditorGUILayout.ObjectField("Default GameObject", overrideTile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
overrideTile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", overrideTile.m_DefaultColliderType);
overrideTile.m_DefaultSprite = EditorGUILayout.ObjectField(Styles.defaultSprite, overrideTile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
overrideTile.m_DefaultGameObject = EditorGUILayout.ObjectField(Styles.defaultGameObject, overrideTile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
overrideTile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup(Styles.defaultCollider, overrideTile.m_DefaultColliderType);
if (EditorGUI.EndChangeCheck())
SaveTile();

Expand Down
8 changes: 7 additions & 1 deletion Editor/Tiles/RuleOverrideTile/RuleOverrideTileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace UnityEditor
[CustomEditor(typeof(RuleOverrideTile))]
public class RuleOverrideTileEditor : Editor
{
private static class Styles
{
public static readonly GUIContent overrideTile = EditorGUIUtility.TrTextContent("Tile"
, "The Rule Tile to override.");
}

/// <summary>
/// The RuleOverrideTile being edited
/// </summary>
Expand Down Expand Up @@ -255,7 +261,7 @@ public void DrawGameObjectElement(Rect rect, int index, bool active, bool focuse
public void DrawTileField()
{
EditorGUI.BeginChangeCheck();
RuleTile tile = EditorGUILayout.ObjectField("Tile", overrideTile.m_Tile, typeof(RuleTile), false) as RuleTile;
RuleTile tile = EditorGUILayout.ObjectField(Styles.overrideTile, overrideTile.m_Tile, typeof(RuleTile), false) as RuleTile;
if (EditorGUI.EndChangeCheck())
{
if (!LoopCheck(tile))
Expand Down
70 changes: 52 additions & 18 deletions Editor/Tiles/RuleTile/RuleTileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ public static Texture2D[] autoTransforms
}
}

private static class Styles
{
public static readonly GUIContent defaultSprite = EditorGUIUtility.TrTextContent("Default Sprite"
, "The default Sprite set when creating a new Rule.");
public static readonly GUIContent defaultGameObject = EditorGUIUtility.TrTextContent("Default GameObject"
, "The default GameObject set when creating a new Rule.");
public static readonly GUIContent defaultCollider = EditorGUIUtility.TrTextContent("Default Collider"
, "The default Collider Type set when creating a new Rule.");

public static readonly GUIContent extendNeighbor = EditorGUIUtility.TrTextContent("Extend Neighbor"
, "Enabling this allows you to increase the range of neighbors beyond the 3x3 box.");

public static readonly GUIContent tilingRules = EditorGUIUtility.TrTextContent("Tiling Rules");
public static readonly GUIContent tilingRulesGameObject = EditorGUIUtility.TrTextContent("GameObject"
, "The GameObject for the Tile which fits this Rule.");
public static readonly GUIContent tilingRulesCollider = EditorGUIUtility.TrTextContent("Collider"
, "The Collider Type for the Tile which fits this Rule");
public static readonly GUIContent tilingRulesOutput = EditorGUIUtility.TrTextContent("Output"
, "The Output for the Tile which fits this Rule. Each Output type has its own properties.");

public static readonly GUIContent tilingRulesNoise = EditorGUIUtility.TrTextContent("Noise"
, "The Perlin noise factor when placing the Tile.");
public static readonly GUIContent tilingRulesShuffle = EditorGUIUtility.TrTextContent("Shuffle"
, "The randomized transform given to the Tile when placing it.");
public static readonly GUIContent tilingRulesRandomSize = EditorGUIUtility.TrTextContent("Size"
, "The number of Sprites to randomize from.");

public static readonly GUIContent tilingRulesMinSpeed = EditorGUIUtility.TrTextContent("Min Speed"
, "The minimum speed at which the animation is played.");
public static readonly GUIContent tilingRulesMaxSpeed = EditorGUIUtility.TrTextContent("Max Speed"
, "The maximum speed at which the animation is played.");
public static readonly GUIContent tilingRulesAnimationSize = EditorGUIUtility.TrTextContent("Size"
, "The number of Sprites in the animation.");
}

/// <summary>
/// The RuleTile being edited
/// </summary>
Expand Down Expand Up @@ -115,11 +150,11 @@ public static Texture2D[] autoTransforms
/// <summary>
/// Padding between Rule Elements
/// </summary>
public const float k_PaddingBetweenRules = 26f;
public const float k_PaddingBetweenRules = 8f;
/// <summary>
/// Single line height
/// </summary>
public const float k_SingleLineHeight = 16f;
public const float k_SingleLineHeight = 18f;
/// <summary>
/// Width for labels
/// </summary>
Expand Down Expand Up @@ -216,10 +251,8 @@ public float GetElementHeight(RuleTile.TilingRuleOutput rule)
switch (rule.m_Output)
{
case RuleTile.TilingRule.OutputSprite.Random:
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 3) + k_PaddingBetweenRules;
break;
case RuleTile.TilingRule.OutputSprite.Animation:
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 2) + k_PaddingBetweenRules;
inspectorHeight = k_DefaultElementHeight + k_SingleLineHeight * (rule.m_Sprites.Length + 3) + k_PaddingBetweenRules;
break;
}

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

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

EditorGUI.BeginChangeCheck();
extendNeighbor = EditorGUI.Toggle(toggleRect, extendNeighbor);
EditorGUI.LabelField(toggleLabelRect, "Extend Neighbor", new GUIStyle()
EditorGUI.LabelField(toggleLabelRect, Styles.extendNeighbor, new GUIStyle()
{
alignment = TextAnchor.MiddleRight,
fontStyle = FontStyle.Bold,
Expand All @@ -392,9 +425,9 @@ public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();

tile.m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
tile.m_DefaultGameObject = EditorGUILayout.ObjectField("Default GameObject", tile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", tile.m_DefaultColliderType);
tile.m_DefaultSprite = EditorGUILayout.ObjectField(Styles.defaultSprite, tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
tile.m_DefaultGameObject = EditorGUILayout.ObjectField(Styles.defaultGameObject, tile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup(Styles.defaultCollider, tile.m_DefaultColliderType);

DrawCustomFields(false);

Expand Down Expand Up @@ -701,39 +734,40 @@ public virtual void SpriteOnGUI(Rect rect, RuleTile.TilingRuleOutput tilingRule)
public void RuleInspectorOnGUI(Rect rect, RuleTile.TilingRuleOutput tilingRule)
{
float y = rect.yMin;
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "GameObject");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesGameObject);
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);
y += k_SingleLineHeight;
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Collider");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesCollider);
tilingRule.m_ColliderType = (Tile.ColliderType)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_ColliderType);
y += k_SingleLineHeight;
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Output");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesOutput);
tilingRule.m_Output = (RuleTile.TilingRule.OutputSprite)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_Output);
y += k_SingleLineHeight;

if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Animation)
{
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Min Speed");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesMinSpeed);
tilingRule.m_MinAnimationSpeed = EditorGUI.FloatField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_MinAnimationSpeed);
y += k_SingleLineHeight;
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Max Speed");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesMaxSpeed);
tilingRule.m_MaxAnimationSpeed = EditorGUI.FloatField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_MaxAnimationSpeed);
y += k_SingleLineHeight;
}
if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Random)
{
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Noise");
GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), Styles.tilingRulesNoise);
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);
y += k_SingleLineHeight;

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

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

0 comments on commit f1c3a20

Please sign in to comment.