Skip to content

Commit

Permalink
remove custom drawers for components, various housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed Apr 16, 2024
1 parent 24e83f0 commit a2b33e3
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 129 deletions.
2 changes: 2 additions & 0 deletions Assets/LDtkUnity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Total new components:
- `LDtkComponentLayerParallax` A component to handle simple parallax in runtime to mimic the same movements as in LDtk.

- Added implicit operator to string for `LDtkIid`

- Total new ScriptableObjects
- LDtkDefinitionObjectAutoLayerRule
- LDtkDefinitionObjectAutoLayerRuleGroup
Expand Down
23 changes: 1 addition & 22 deletions Assets/LDtkUnity/Editor/CustomEditor/LDtkComponentLayerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ namespace LDtkUnity.Editor
[CanEditMultipleObjects]
internal sealed class LDtkComponentLayerEditor : UnityEditor.Editor
{
private SerializedProperty _identifier;
private SerializedProperty _doc;
private SerializedProperty _type;
private SerializedProperty _scale;

private void OnEnable()
{
_identifier = serializedObject.FindProperty(LDtkComponentLayer.PROPERTY_IDENTIFIER);
_doc = serializedObject.FindProperty(LDtkComponentLayer.PROPERTY_DOC);
_type = serializedObject.FindProperty(LDtkComponentLayer.PROPERTY_TYPE);
_scale = serializedObject.FindProperty(LDtkComponentLayer.PROPERTY_LAYER_SCALE);
}

public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(_identifier);
EditorGUILayout.PropertyField(_doc);
EditorGUILayout.PropertyField(_type);
EditorGUILayout.PropertyField(_scale);
serializedObject.ApplyModifiedProperties();
}

}
}
48 changes: 2 additions & 46 deletions Assets/LDtkUnity/Editor/CustomEditor/LDtkComponentLevelEditor.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,11 @@
using UnityEditor;
using UnityEngine;

namespace LDtkUnity.Editor
{
[CustomEditor(typeof(LDtkComponentLevel), true)]
[CanEditMultipleObjects]
internal sealed class LDtkComponentLevelEditor : UnityEditor.Editor
{
private SerializedProperty _identifier;
private SerializedProperty _size;
private SerializedProperty _bgColor;
private SerializedProperty _smartColor;
private SerializedProperty _worldDepth;
private SerializedProperty _neighbors;

private void OnEnable()
{
_identifier = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_IDENTIFIER);
_size = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_SIZE);
_bgColor = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_BG_COLOR);
_smartColor = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_SMART_COLOR);
_worldDepth = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_WORLD_DEPTH);
_neighbors = serializedObject.FindProperty(LDtkComponentLevel.PROPERTY_NEIGHBOURS);
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_identifier);
EditorGUILayout.PropertyField(_size);
EditorGUILayout.PropertyField(_bgColor);
EditorGUILayout.PropertyField(_smartColor);
EditorGUILayout.PropertyField(_worldDepth);
DrawNeighbours();

serializedObject.ApplyModifiedProperties();
}

private void DrawNeighbours()
{
if (_neighbors.arraySize <= 0)
{
return;
}

GUILayout.Label("Neighbours", EditorStyles.miniBoldLabel);
for (int i = 0; i < _neighbors.arraySize; i++)
{
SerializedProperty prop = _neighbors.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(prop);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,11 @@
using UnityEditor;
using UnityEngine;

namespace LDtkUnity.Editor
{
[CustomEditor(typeof(LDtkComponentProject), true)]
[CanEditMultipleObjects]
internal sealed class LDtkComponentProjectEditor : UnityEditor.Editor
{
private static readonly GUIContent ProjectContent = new GUIContent
{
text = "Json Data",
tooltip = "Reference to the Json. Call FromJson in this component to get it's data"
};

private static readonly GUIContent LevelsContent = new GUIContent
{
text = "This project uses separate level files. The levels are instead available from their separate levels.",
};

public override void OnInspectorGUI()
{
SerializedProperty projectProp = serializedObject.FindProperty(LDtkComponentProject.PROPERTY_PROJECT);

using (new EditorGUI.DisabledScope(true))
{
EditorGUILayout.PropertyField(projectProp, ProjectContent);
}

TryDrawExternalLevelsLabel();
}

private void TryDrawExternalLevelsLabel()
{
SerializedProperty levelsProp = serializedObject.FindProperty(LDtkComponentProject.PROPERTY_SEPARATE_LEVELS);
if (!levelsProp.boolValue)
{
return;
}

using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUIUtility.IconSizeScope(Vector2.one * 16))
{
GUIContent iconContent = new GUIContent
{
image = LDtkIconUtility.LoadLevelFileIcon()
};
EditorGUILayout.LabelField(iconContent, GUILayout.Width(18));
}

EditorGUILayout.HelpBox(LevelsContent);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal sealed class LDtkEntityDrawerComponentEditor : UnityEditor.Editor
public override void OnInspectorGUI()
{
EditorGUILayout.HelpBox("This object draws the scene content. Configure what to draw in preferences", MessageType.None);
EditorGUILayout.HelpBox("This will be removed in a future update", MessageType.Warning);
if (GUILayout.Button("LDtk To Unity's Preferences"))
{
SettingsService.OpenUserPreferences(LDtkPrefsProvider.PROVIDER_PATH);
Expand Down
6 changes: 3 additions & 3 deletions Assets/LDtkUnity/Editor/PropertyDrawer/LDtkNeighbourDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
using (new EditorGUIUtility.IconSizeScope(Vector2.one * 25))
{
LDtkIidEditor.DrawIidAndGameObject(position, _labelRect, _propLevelIid, content);
DrawNeighbour();
DrawNeighbour(_labelRect);
}
}

Expand All @@ -44,9 +44,9 @@ public void TryInitialise(SerializedProperty property)
_propLevelIid = property.FindPropertyRelative(LDtkNeighbour.PROPERTY_LEVEL_IID);
}

private void DrawNeighbour()
private void DrawNeighbour(Rect labelRect)
{
Rect dirRect = GUILayoutUtility.GetLastRect();
Rect dirRect = labelRect;
dirRect.height = EditorGUIUtility.singleLineHeight;
dirRect.width = EditorGUIUtility.singleLineHeight + 6;
dirRect.x -= 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal sealed partial class LDtkTilesetImporter : LDtkJsonImporter<LDtkTileset
/// <summary>
/// Any sprites that were defined from entity/level fields.
/// It's separate because we don't want to draw them in the sprite editor window, or otherwise make them configurable.
/// Also because they won't have tilemap assets generated for them anyways, as their size wouldn't fit in the tilemap.
/// Also, because they won't have tilemap assets generated for them anyway, as their size wouldn't fit in the tilemap.
/// </summary>
private List<LDtkSpriteRect> _additionalTiles = new List<LDtkSpriteRect>();
[SerializeField] internal SecondarySpriteTexture[] _secondaryTextures;
Expand Down Expand Up @@ -222,7 +222,7 @@ private LDtkArtifactAssetsTileset MakeAndCacheArtifacts(TextureGenerationOutput
ImportContext.AddObjectToAsset(spr.name, spr);
Profiler.EndSample();

//any indexes past the sprite count is additional sprites. dont make tile, just sprite.
//any indexes past the sprite count is additional sprites. Don't make tile, just sprite.
if (i >= _sprites.Count)
{
Profiler.BeginSample("AddAdditionalSprite");
Expand Down Expand Up @@ -870,7 +870,7 @@ public LDtkArtifactAssetsTileset LoadArtifacts(LDtkDebugInstance projectCtx)
//It's possible that the artifact assets don't exist, either because the texture importer failed to import, or the artifact assets weren't produced due to being an aseprite file or otherwise
if (_cachedArtifacts == null)
{
LDtkDebug.LogError($"Loading artifacts didn't work for getting tileset sprite artifacts. Was the tileset file properly imported? At \"{assetPath}\"", projectCtx);
LDtkDebug.LogError($"Loading artifacts didn't work for getting tileset sprite artifacts. You should investigate the tileset file at \"{assetPath}\"", projectCtx);
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions Assets/LDtkUnity/Runtime/Components/LDtkIid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ internal void SetIid(ILDtkIid iid)
_iid = iid.Iid;
LDtkIidComponentBank.Add(this);
}

public static implicit operator string(LDtkIid iid) => iid.Iid;
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Runtime/Fields/LDtkFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace LDtkUnity
public partial class LDtkFields : MonoBehaviour
{
internal const string PROPERTY_FIELDS = nameof(_fields);

[SerializeField] private LDtkField[] _fields = Array.Empty<LDtkField>();

private readonly Dictionary<string, int> _keys = new Dictionary<string, int>();
Expand All @@ -27,8 +28,7 @@ private void CacheFields()
{
for (int i = 0; i < _fields.Length; i++)
{
LDtkField field = _fields[i];
_keys.Add(field.Identifier, i);
_keys.Add(_fields[i].Identifier, i);
}
}

Expand Down
6 changes: 0 additions & 6 deletions Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,6 @@ public partial class LDtkFields
/// <returns>
/// The field's value. If the field doesn't exist, then returns a default value type.
/// </returns>
/// <remarks>
/// This function uses Object.FindObjectsOfType if a cached component is not found, so it is slow and not recommended to use every frame.
/// </remarks>
public LDtkReferenceToAnEntityInstance GetEntityReference(string identifier) => GetFieldSingle(identifier, LDtkFieldType.EntityRef,element => element.GetEntityRefValue());

/// <summary>
Expand All @@ -531,9 +528,6 @@ public partial class LDtkFields
/// <returns>
/// The field's value. If the field doesn't exist, then returns a default value type.
/// </returns>
/// <remarks>
/// This function uses Object.FindObjectsOfType if a cached component is not found, so it is slow and not recommended to use every frame.
/// </remarks>
public LDtkReferenceToAnEntityInstance[] GetEntityReferenceArray(string identifier) => GetFieldArray(identifier, LDtkFieldType.EntityRef, element => element.GetEntityRefValue());

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static void Remove(LDtkIid iid)
}

/// <summary>
/// Gets a iid GameObject. The objects are only available after their OnEnable. Otherwise, try using <see cref="FindObjectOfIid"/>. <br/>
/// Gets an iid GameObject. The objects are only available after their OnEnable. Otherwise, try using <see cref="FindObjectOfIid"/>. <br/>
/// If the component was not found, then make sure the referenced component is active and accessed after it's OnEnable.
/// </summary>
/// <param name="iid">
Expand Down
2 changes: 1 addition & 1 deletion Assets/LDtkUnity/Runtime/Tools/LDtkExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal static string ToHex(this Color color)

internal static Color ToColor(this int hexInt)
{
string hexString = hexInt.ToString("X");
string hexString = hexInt.ToString("X6");
hexString = $"#{hexString}";
return ToColor(hexString);
}
Expand Down

0 comments on commit a2b33e3

Please sign in to comment.