UP-Viagg-io/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedUiText.cs

94 lines
2.6 KiB
C#
Raw Normal View History

2024-01-19 16:30:05 +01:00
//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
//
// Purpose: Part of the My Behaviour Tree Controller Code
//
//=============================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using MyBT;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(NamedUiText))]
public class NamedUiTextInspector : ComponentHandlerInspector {
}
#endif
[System.Serializable]
public class NamedUiText : ComponentHandler {
public override string TypeLabel () {
return "UiText";
}
public override string ContentLabel() {
UpdateComponent();
return "";
}
public override void UpdateComponent() {
base.UpdateComponent();
uiTextComponent = GetComponent<UnityEngine.UI.Text>();
}
public UnityEngine.UI.Text uiTextComponent;
public override string titleText {
get {
return "Set \"text\", FadeIn&Out";
}
}
public override string[][] helpText {
get {
return new string[][] {
new string[] {"Show", null, $"BTC.Show(\"{roomId}\", \"{gameObject.name}\")"},
new string[] {"Hide", null, $"BTC.Hide(\"{roomId}\", \"{gameObject.name}\")"},
new string[] {"FadeIn", null, $"BTC.FadeIn(\"{roomId}\", \"{gameObject.name}\")"},
new string[] {"FadeOut", null, $"BTC.FadeOut(\"{roomId}\", \"{gameObject.name}\")"},
new string[] {"Set Text", "Set Text Content", $"BTC.Set(\"{roomId}\", \"{gameObject.name}\", \"text\", \"Text Content\")"},
};
}
}
// public override void Start() {
// }
public override void Set(NodeState nodeState, string key, string value) {
if ((nodeState == NodeState.FirstRun) || (nodeState == NodeState.Running)) {
if (key == "text") {
uiTextComponent.text = value;
Task.SetSucceeded();
return;
}
else {
Task.SetError();
return;
}
}
}
public override void Update() {
base.Update();
}
#region both values setting
public override void SetAlpha(float alpha) {
if (uiTextComponent != null) {
Color col = uiTextComponent.color;
col.a = 1 - alpha;
uiTextComponent.color = col;
}
}
public override float GetAlpha() {
if (uiTextComponent != null) {
return 1-uiTextComponent.color.a;
}
return 0;
}
#endregion
}