Skip to content

Commit

Permalink
Merge pull request #10 from kurone-kito/cumulative-updates
Browse files Browse the repository at this point in the history
v0.6.0: Added a new component, `ToggleWithAnimator` and cumulative updates
  • Loading branch information
kurone-kito authored May 3, 2024
2 parents 7ba38c2 + e101514 commit 090cee7
Show file tree
Hide file tree
Showing 59 changed files with 8,665 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Language: [🇬🇧](./CONTRIBUTING.md) | [🇯🇵](./CONTRIBUTING.ja.md) | **

---

1. 请注意我们有[行为准则](./CODE_OF_CONDUCT.ja.md),请在与项目的所有互动中遵循。
1. 请注意我们有[行为准则](./CODE_OF_CONDUCT.zh.md),请在与项目的所有互动中遵循。
2. 在为此存储库做出贡献时,请首先在进行更改之前与该存储库的所有者讨论您希望通过问题或任何其他方法进行的更改。
3. 如果您的想法可以通过**小修复显示,请直接使用[拉取请求](https://github.com/kurone-kito/launchpad-icons/pulls)**
- 本版本库有时会在拉取请求和发布之间建立一对一的绑定关系,但这并**不是必须的**。我们欢迎您的拉取请求。
Expand Down
4 changes: 4 additions & 0 deletions .imgbotconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compressWiki": true,
"ignoredFiles": ["*.svg"]
}
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet 6.0.420
dotnet 6.0.421
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"*.prefab": "yaml",
"*.unity": "yaml",
"*.uss": "css",
".imgbotconfig": "json",
".manifest": "json",
"LICENSE": "plaintext"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace black.kit.toybox.Editor
{
/// <summary>
/// The inspector of the <see cref="ToggleWithAnimator"/>.
/// </summary>
[CustomEditor(typeof(ToggleWithAnimator))]
public sealed class ToggleWithAnimatorEditor
: EditorBase<ToggleWithAnimator>
{
/// <summary>The usage of the target.</summary>
private readonly string[] usage = new[]
{
T.USAGE_LINK_ANIMATOR,
T.USAGE_LINK_TOGGLE,
T.USAGE_GLOBAL_TOGGLE_1,
};

/// <summary>Initialize the editor.</summary>
public ToggleWithAnimatorEditor()
: base(L10n.Tr(T.DETAIL_TOGGLE_WITH_ANIMATOR))
{
}

/// <summary>The callback to draw the inspector GUI.</summary>
public override void OnInspectorGUI()
{
DrawBanner();
DrawDetails();
EditorGUILayout.BeginVertical(GUI.skin.box);
DrawList(
usage, new ListOptions() { Ordered = true, Tr = L10n.Tr });
DrawUdonEvent(T.USAGE_ON_VALUE_CHANGED);
EditorGUILayout.EndVertical();
base.OnInspectorGUI();

serializedObject.Update();
var animator = AutoCompleteObject<Animator>(
ToggleWithAnimator.NAME_ANIMATOR);
var toggle = AutoCompleteObject<Toggle>(
ToggleWithAnimator.NAME_TOGGLE);
var param = serializedObject.FindProperty(
ToggleWithAnimator.NAME_PARAMETER);
if (animator)
{
animator.SetBool(
param.stringValue, toggle && toggle.isOn);
animator.Update(Time.deltaTime * 100f);
}
serializedObject.ApplyModifiedProperties();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions Packages/black.kit.toybox/Editor/EditorBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UdonSharp;
using UnityEditor;
using UnityEngine;
Expand All @@ -11,27 +12,32 @@ namespace black.kit.toybox.Editor
public abstract class EditorBase<Tb> : UnityEditor.Editor
where Tb : UdonSharpBehaviour
{
/// <summary>The translation function.</summary>
protected readonly Func<string, string> Tr;

/// <summary>The information of the banner.</summary>
private readonly BannerInit bannerInit;

/// <summary>Initialize the editor.</summary>
/// <param name="details">The details of the target.</param>
/// <param name="bannerInit">The information of the banner.</param>
public EditorBase(
string details, Lazy<BannerInit> bannerInit = null)
string details, Lazy<BannerInit> bannerInit = null, Func<string, string> tr = null)
: this(
details: details,
bannerInit: bannerInit?.Value ?? BannerInit.Toybox)
bannerInit: bannerInit?.Value ?? BannerInit.Toybox,
tr: tr)
{
}

/// <summary>Initialize the editor.</summary>
/// <param name="details">The details of the target.</param>
/// <param name="bannerInit">The information of the banner.</param>
public EditorBase(string details, BannerInit bannerInit) : base()
public EditorBase(string details, BannerInit bannerInit, Func<string, string> tr = null) : base()
{
this.details = details;
this.bannerInit = bannerInit;
Tr = tr ?? L10n.Tr;
}

/// <summary>The default style of the inspector.</summary>
Expand Down Expand Up @@ -101,16 +107,20 @@ protected void DrawBanner() =>
EditorUtils.DrawBanner(
banner: LoadTexture(), aspectRatio: bannerInit.AspectRatio);

/// <summary>
/// Draw the list of the inspector.
/// </summary>
/// <summary>Draw the list of the inspector.</summary>
/// <param name="list">The list to draw.</param>
/// <param name="selectable">The list is selectable.</param>
protected void DrawList(string[] list, bool selectable = false) =>
protected void DrawList(IEnumerable<string> list, bool selectable = false) =>
DrawList(list, new ListOptions() { Selectable = selectable, Tr = Tr });

/// <summary>Draw the list of the inspector.</summary>
/// <param name="list">The list to draw.</param>
/// <param name="options">The options of the list.</param>
protected void DrawList(IEnumerable<string> list, ListOptions options) =>
EditorUtils.DrawList(
list: list,
style: defaultStyle.Value,
options: new() { Selectable = selectable });
options: options);

/// <summary>Draw the description of the inspector.</summary>
protected void DrawDetails() =>
Expand All @@ -123,6 +133,12 @@ protected void DrawDetails() =>
private Texture LoadTexture(bool Force = false) =>
banner = (Force || !banner) ? bannerInit.LoadTexture() : banner;

/// <summary>Draw the Udon event of the inspector.</summary>
/// <param name="argument">The argument of the Udon event.</param>
protected void DrawUdonEvent(string argument) =>
EditorUtils.DrawUdonEvent(
argument: argument, style: defaultStyle.Value, tr: Tr);

#pragma warning disable IDE0051
/// <summary>The callback when the object is enabled.</summary>
private void OnEnable() => LoadTexture();
Expand Down
13 changes: 8 additions & 5 deletions Packages/black.kit.toybox/Editor/EditorUtils.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand Down Expand Up @@ -60,12 +61,14 @@ in list.Select((item, index) => (item, index)))
}
}

/// <summary>
/// Draw the Udon event of the inspector.
/// </summary>
/// <summary>Draw the Udon event of the inspector.</summary>
/// <param name="argument">The argument of the Udon event.</param>
/// <param name="style">The style of the list.</param>
public static void DrawUdonEvent(string argument, GUIStyle style)
/// <param name="tr">The translation function.</param>
public static void DrawUdonEvent(
string argument,
GUIStyle style,
Func<string, string> tr = null)
{
var list = new[]
{
Expand All @@ -75,7 +78,7 @@ public static void DrawUdonEvent(string argument, GUIStyle style)
argument,
};
EditorGUI.indentLevel++;
DrawList(list, style, new() { Selectable = true });
DrawList(list, style, new() { Selectable = true, Tr = tr });
EditorGUI.indentLevel--;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Packages/black.kit.toybox/Editor/GlobalUIEditorBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UdonSharp;
using UnityEditor;
using UnityEngine;
Expand All @@ -12,7 +13,7 @@ public abstract class GlobalUIEditorBase<Tb> : EditorBase<Tb>
/// <summary>Initialize the editor.</summary>
public GlobalUIEditorBase(
string details,
string[] usage,
IEnumerable<string> usage,
string argument) : base(details)
{
this.usage = usage;
Expand All @@ -26,10 +27,10 @@ public GlobalUIEditorBase(
}

/// <summary>The usage of the target.</summary>
private readonly string[] usage;
private readonly IEnumerable<string> usage;

/// <summary>The events usage of the target.</summary>
private readonly string[] events;
private readonly IEnumerable<string> events;

/// <summary>Draw the usage of the component.</summary>
protected void DrawUsage()
Expand Down
14 changes: 11 additions & 3 deletions Packages/black.kit.toybox/Editor/Structs/ListOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ public readonly struct ListOptions
/// <summary>The list is selectable.</summary>
public bool Selectable { get; init; }

/// <summary>The translation function.</summary>
public Func<string, string> Tr { get; init; }

/// <summary>
/// Initialize the options of the list of the inspector.
/// </summary>
/// <param name="ordered">The list is ordered.</param>
/// <param name="selectable">The list is selectable.</param>
public ListOptions(bool ordered = false, bool selectable = false)
public ListOptions(
bool ordered = false,
bool selectable = false,
Func<string, string> tr = null)
{
Ordered = ordered;
Selectable = selectable;
Tr = tr ?? L10n.Tr;
}

/// <summary>
Expand All @@ -46,9 +53,10 @@ public readonly Action<string, int> CreatePutItem(GUIStyle style)
Action<string> output = Selectable
? item => EditorGUILayout.SelectableLabel(item, style)
: item => EditorGUILayout.LabelField(item, style);
var tr = Tr ?? L10n.Tr; // Countermeasures to CS1673
Func<string, int, string> getText = Ordered
? (item, index) => $"{index + 1}.{L10n.Tr(item)}"
: (item, _) => L10n.Tr(item);
? (item, index) => $"{index + 1}.{tr(item)}"
: (item, _) => tr(item);
return (name, index) => output(getText(name, index));
}
}
Expand Down
4 changes: 4 additions & 0 deletions Packages/black.kit.toybox/Editor/T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class T
nameof(DETAIL_SEQUENCE_ACTIVE_RELAY_TO_ANIMATOR);
public const string DETAIL_SUBJECT = nameof(DETAIL_SUBJECT);
public const string DETAIL_TICKING_DOWN = nameof(DETAIL_TICKING_DOWN);
public const string DETAIL_TOGGLE_WITH_ANIMATOR =
nameof(DETAIL_TOGGLE_WITH_ANIMATOR);
public const string DETAIL_WHITELIST = nameof(DETAIL_WHITELIST);
public const string USAGE_COMPONENT = nameof(USAGE_COMPONENT);
public const string USAGE_DOORBELL = nameof(USAGE_DOORBELL);
Expand All @@ -27,6 +29,8 @@ public static class T
public const string USAGE_GLOBAL_TOGGLE_1 = nameof(USAGE_GLOBAL_TOGGLE_1);
public const string USAGE_GLOBAL_TOGGLES_0 = nameof(USAGE_GLOBAL_TOGGLES_0);
public const string USAGE_GLOBAL_TOGGLES_1 = nameof(USAGE_GLOBAL_TOGGLES_1);
public const string USAGE_LINK_ANIMATOR = nameof(USAGE_LINK_ANIMATOR);
public const string USAGE_LINK_TOGGLE = nameof(USAGE_LINK_TOGGLE);
public const string USAGE_ON_SCROLL = nameof(USAGE_ON_SCROLL);
public const string USAGE_ON_TOGGLE = nameof(USAGE_ON_TOGGLE);
public const string USAGE_ON_VALUE_CHANGED = nameof(USAGE_ON_VALUE_CHANGED);
Expand Down
9 changes: 9 additions & 0 deletions Packages/black.kit.toybox/Editor/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ msgstr "When the <b>Notify()</b> method is executed, the registered Observers ar
msgid "DETAIL_TICKING_DOWN"
msgstr "This component can send date and time information with a low load to the text component."

msgid "DETAIL_TOGGLE_WITH_ANIMATOR"
msgstr "This component works with the Toggle component to perform animation when toggling on and off."

msgid "DETAIL_WHITELIST"
msgstr "The allowlist to enable or disable the colliders and game objects. If local users are included in the allowlist, this component toggles between enabled and disabled states."

Expand Down Expand Up @@ -72,6 +75,12 @@ msgstr "1. place it on the same object as the ToggleGroup component or manually
msgid "USAGE_GLOBAL_TOGGLES_1"
msgstr "2. Set the following to <b>OnValueChanged (Boolean)</b> in each Toggle component associated with the ToggleGroup component."

msgid "USAGE_LINK_ANIMATOR"
msgstr "Deploy this component on the same object as the Animator component or manually link it."

msgid "USAGE_LINK_TOGGLE"
msgstr "Deploy this component on the same object as the Toggle component or manually link it."

msgid "USAGE_ON_SCROLL"
msgstr "Argument: <b>OnScroll</b>"

Expand Down
9 changes: 9 additions & 0 deletions Packages/black.kit.toybox/Editor/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ msgstr "<b>Notify()</b>メソッドを実行すると、登録されたObserver
msgid "DETAIL_TICKING_DOWN"
msgstr "このコンポーネントはテキストコンポーネントへ、日時情報を低負荷で渡せます。"

msgid "DETAIL_TOGGLE_WITH_ANIMATOR"
msgstr "このコンポーネントは、Toggleコンポーネントと連携して、オン・オフの切り替え時にアニメーションを実行します。"

msgid "DETAIL_WHITELIST"
msgstr "このコンポーネントに指定したユーザーのみ、登録しているオブジェクトやコライダーの有効・無効状態を反転します。"

Expand Down Expand Up @@ -71,6 +74,12 @@ msgstr "1.ToggleGroupコンポーネントと同一のオブジェクトに配
msgid "USAGE_GLOBAL_TOGGLES_1"
msgstr "2.ToggleGroupコンポーネントに紐づいた、各Toggleコンポーネントにおける<b>値の変更時(Boolean)</b>へ、以下を設定してください。"

msgid "USAGE_LINK_ANIMATOR"
msgstr "Animatorコンポーネントと同一のオブジェクトに配置するか、手動でコンポーネントを紐づけてください。"

msgid "USAGE_LINK_TOGGLE"
msgstr "Toggleコンポーネントと同一のオブジェクトに配置するか、手動でコンポーネントを紐づけてください。"

msgid "USAGE_ON_SCROLL"
msgstr "引数: <b>OnScroll</b>"

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 090cee7

Please sign in to comment.