Skip to content

Commit

Permalink
test: updated the example world
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone-kito committed Nov 28, 2024
1 parent 502004f commit 50f8f9e
Show file tree
Hide file tree
Showing 2 changed files with 20,889 additions and 20,852 deletions.
37 changes: 37 additions & 0 deletions Packages/black.kit.launchpadicons/Editor/CatalogEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,52 @@

namespace black.kit.launchpadicons.Editor
{
/// <summary>The editor extension for the catalog.</summary>
[CustomEditor(typeof(Catalog))]
public sealed class CatalogEditor : UnityEditor.Editor
{
/// <summary>The path to the icons.</summary>
private const string ICONS_PATH = "Packages/black.kit.launchpadicons/Runtime";

/// <summary>The capacity of the icons group.</summary>
private const int ICONS_GROUP_CAPACITY = 64;

/// <summary>The background color for the new icons.</summary>
private static readonly Color bgNew = new(.467f, 1f, .733f, .39f);

/// <summary>The background color for the white icons.</summary>
private static readonly Color bgWhite = new(1f, 1f, 1f, .39f);

/// <summary>The icon color for the black icons.</summary>
private static readonly Color iconBlack = new(0f, 0f, 0f, .8f);

/// <summary>The icon color for the white icons.</summary>
private static readonly Color iconWhite = new(1f, 1f, 1f, .8f);

/// <summary>Get the name of the icon by the GUID.</summary>
/// <param name="guid">The GUID of the icon.</param>
/// <returns>The name of the icon.</returns>
private static (string guid, string name) GuidToName(string guid) =>
(
guid,
name: Path.GetFileNameWithoutExtension(
AssetDatabase.GUIDToAssetPath(guid))
);

/// <summary>Find the icons in the catalog.</summary>
/// <returns>The array of the GUIDs and names of the icons.</returns>
private static (string guid, string name)[] FindIcons() =>
AssetDatabase.FindAssets(
"t:Texture2D", new[] { ICONS_PATH })
.Select(GuidToName)
.OrderBy(x => x.name)
.ToArray();

/// <summary>Get the groups of the icons.</summary>
/// <param name="icons">
/// The array of the GUIDs and names of the icons.
/// </param>
/// <returns>The groups of the icons.</returns>
private static IEnumerable<(string guid, string name)>[] ToGroups(
(string guid, string name)[] icons)
{
Expand All @@ -49,6 +66,11 @@ private static (string guid, string name)[] FindIcons() =>
.ToArray();
}

/// <summary>Get the width of the group.</summary>
/// <param name="groupRect">The rect of the group.</param>
/// <param name="groupsLength">The length of the groups.</param>
/// <param name="layoutGroup">The layout group.</param>
/// <returns>The width of the group.</returns>
private static float GetWidth(
RectTransform groupRect,
int groupsLength,
Expand All @@ -59,13 +81,18 @@ private static float GetWidth(
return groupRect.sizeDelta.x * groupsLength + padding + spacing;
}

/// <summary>Remove all children of the parent.</summary>
/// <param name="parent">The parent of the children.</param>
private static void RemoveAllChildren(Transform parent)
{
Array.ForEach(
parent.Cast<Transform>().ToArray(),
x => DestroyImmediate(x.gameObject));
}

/// <summary>Get the rect of the catalog.</summary>
/// <param name="groupsLength">The length of the groups.</param>
/// <returns>The rect of the catalog.</returns>
private Vector2 GetCatalogRect(int groupsLength)
{
var containerGroup = TypedTarget.ContainerGrid;
Expand All @@ -76,6 +103,14 @@ private Vector2 GetCatalogRect(int groupsLength)
return new Vector2(width, height);
}

/// <summary>
/// Instantiate the icon in the container.
/// </summary>
/// <param name="iContainer">The container of the icon.</param>
/// <param name="guid">The GUID of the icon.</param>
/// <param name="name">The name of the icon.</param>
/// <param name="isNew">The flag of the new icon.</param>
/// <param name="isWhite">The flag of the white icon.</param>
private static void InstantiateIcon(
GameObject iContainer,
string guid,
Expand All @@ -93,6 +128,7 @@ private static void InstantiateIcon(
cb.Icon.color = isWhite ? iconWhite : iconBlack;
}

/// <summary>The inspector GUI of the catalog.</summary>
public override void OnInspectorGUI()
{
if (GUILayout.Button("Cleanup the catalog"))
Expand Down Expand Up @@ -129,6 +165,7 @@ public override void OnInspectorGUI()
/// <summary>The target of the inspector.</summary>
private Catalog TypedTarget => target as Catalog;

/// <summary>Remove all children of the catalog.</summary>
private void RemoveAllChildren()
{
var catalogRect = TypedTarget.GetComponent<RectTransform>();
Expand Down
Loading

0 comments on commit 50f8f9e

Please sign in to comment.