AboveButton/BelowButton/PostFieldButtonThere are 3 general buttons:
AboveButtonwill draw a button on aboveBelowButtonwill draw a button on belowPostFieldButtonwill draw a button at the end of the field
All of them have the same arguments:
-
string funcNamecalled when you click the button
-
string buttonLabel=nulllabel of the button, support tags like
RichLabel.nullmeans using function name as label.If it starts with
$, the leading$will be removed andisCallbackwill be set totrue. Use\$to escape the starting$. -
bool isCallback = falsea callback or property name for button's label, same as
RichLabel -
bool hideReturnValue=falseWhen
true, if the function has return value, the returned value will not be displayed -
string groupBy = ""See
GroupBysection. Does NOT work onPostFieldButton -
Allow Multiple: Yes
Note: Compared to Button in SaintsEditor, these buttons can receive the value of the decorated field, and will not get parameter drawers.
About the function been called:
- If the method returns
IEnumerator, it will wait that enumerator with a progress bar, and allow you to cancel in the middle - If the method returns
async Task,async UniTask, it will execute the task until it finishs or errors out - If the method returns
async Task<T>,async UniTask<T>, apon completed, the returned value will be displayed - If any error happends, and Error box with info will display
using SaintsField; [SerializeField] private bool _errorOut; [field: SerializeField] private string _labelByField; [AboveButton(nameof(ClickErrorButton), nameof(_labelByField), true)] [AboveButton(nameof(ClickErrorButton), "Click <color=green><icon='eye.png' /></color>!")] [AboveButton(nameof(ClickButton), "quot; + nameof(GetButtonLabel), groupBy: "OK")] [AboveButton(nameof(ClickButton), "quot; + nameof(GetButtonLabel), groupBy: "OK")] [PostFieldButton(nameof(ToggleAndError), nameof(GetButtonLabelIcon), true)] [BelowButton(nameof(ClickButton), "quot; + nameof(GetButtonLabel), groupBy: "OK")] [BelowButton(nameof(ClickButton), "quot; + nameof(GetButtonLabel), groupBy: "OK")] [BelowButton(nameof(ClickErrorButton), "Below <color=green><icon='eye.png' /></color>!")] public int _someInt; private void ClickErrorButton() => Debug.Log("CLICKED!"); private string GetButtonLabel() => _errorOut ? "Error <color=red>me</color>!" : "No <color=green>Error</color>!"; private string GetButtonLabelIcon() => _errorOut ? "<color=red><icon='eye.png' /></color>" : "<color=green><icon='eye.png' /></color>"; private void ClickButton(int intValue) { Debug.Log(quot;get value: {intValue}"); if(_errorOut) { throw new Exception("Expected exception!"); } } private void ToggleAndError() { Toggle(); if(_errorOut) { throw new Exception("Expected exception!"); } } private void Toggle() => _errorOut = !_errorOut;
Example of colored functions:
[AboveButton(nameof(AsyncVoid))] [BelowButton(nameof(AsyncWithInt))] [PostFieldButton(nameof(AsyncUniTaskBase), "<icon=star.png/>")] [BelowButton(nameof(AsyncUniTaskValue))] public bool ok; private async Task AsyncVoid() { Debug.Log("Async start"); await Task.Delay(1000); Debug.Log("Async end"); } private async Task<int> AsyncWithInt() { Debug.Log("Async start"); await Task.Delay(1000); Debug.Log("Async end"); return 100; } private async UniTask AsyncUniTaskBase() { Debug.Log("Async start"); // await UniTask.Yield(); await UniTask.WaitUntil(() => ok); // throw new Exception("xx"); Debug.Log("Async end"); } private async UniTask<string> AsyncUniTaskValue() { Debug.Log("Async start"); // await UniTask.Yield(); await UniTask.WaitUntil(() => ok); // throw new Exception("xx"); return "fine"; }
You can control each's show/hide/enable/disable with
AboveButtonShowIfAboveButtonHideIfBelowButtonShowIfBelowButtonHideIfPostFieldButtonShowIfPostFieldButtonHideIfAboveButtonDisableIfAboveButtonEnableIfBelowButtonDisableIfBelowButtonEnableIfPostFieldButtonDisableIfPostFieldButtonEnableIf
They all shares the same syntax for show/hide/enable/disable-if
public bool showHideToggle; [PostFieldButtonShowIf(nameof(showHideToggle))] [PostFieldButton(":Debug.Log", "show")] [PostFieldButtonHideIf(nameof(showHideToggle))] [PostFieldButton(":Debug.Log", "hide")] public string f; public bool disableToggle; [PostFieldButtonDisableIf(nameof(disableToggle))] [PostFieldButton(":Debug.Log", "disable")] [PostFieldButtonEnableIf(nameof(disableToggle))] [PostFieldButton(":Debug.Log", "enable")] public string f2;