//============= 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 MyBT; #if UNITY_EDITOR using UnityEditor; [CustomEditor(typeof(ComponentHandler))] public class ComponentHandlerInspector : Editor { public override void OnInspectorGUI() { ComponentHandler myTarget = (ComponentHandler)target; GUILayout.TextArea("Check the ComponentController"); myTarget.hideFlags = HideFlags.HideInInspector; } public virtual void OnCustomInspectorGUI () { ComponentHandler myTarget = (ComponentHandler)target; if (!string.IsNullOrEmpty(myTarget.titleText)) { EditorGUILayout.BeginHorizontal(); GUILayout.Label($"{myTarget.titleText} functions", GUILayout.MinWidth(200)); myTarget.showHelpText = EditorGUILayout.Toggle(myTarget.showHelpText, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); // } // EditorGUILayout.BeginHorizontal(); // if (myTarget.helpText != null) { // myTarget.showHelpText = EditorGUILayout.ToggleLeft("Show Info", myTarget.showHelpText); // } // EditorGUILayout.Space(); // EditorGUILayout.Space(); // EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (myTarget.showHelpText) { if (myTarget.helpText != null) { // string[][] helpTextSplit = myTarget.helpText; for (int i=0; i().roomId; } } public virtual void Run (MyBT.NodeState nodeState) { if (Task.isDebugging) { Debug.LogWarning($"ComponentHandler.Run: not implemented for {this.GetType()}"); } } public virtual void Abort (MyBT.NodeState nodeState) { if (Task.isDebugging) { Debug.LogWarning($"ComponentHandler.Abort: not implemented for {this.GetType()}"); } } public virtual bool IsRunning (MyBT.NodeState nodeState) { if (Task.isDebugging) { Debug.LogWarning($"ComponentHandler.IsRunning: not implemented for {this.GetType()}"); } return false; } public virtual void Show (MyBT.NodeState nodeState) { // Debug.LogWarning($"ComponentHandler.ShowNow: not implemented for {this.GetType()}"); if ((nodeState == NodeState.FirstRun) || (nodeState == NodeState.Running)) { sourceAlpha = shown; targetAlpha = shown; timeSum = 1; SetAlpha(targetAlpha); Task.SetSucceeded(); } } public virtual void Hide (MyBT.NodeState nodeState) { // Debug.LogWarning($"ComponentHandler.HideNow: not implemented for {this.GetType()}"); if ((nodeState == NodeState.FirstRun) || (nodeState == NodeState.Running)) { sourceAlpha = hidden; targetAlpha = hidden; timeSum = 1; SetAlpha(targetAlpha); Task.SetSucceeded(); } } public virtual void FadeIn (MyBT.NodeState nodeState) { // Debug.LogWarning($"ComponentHandler.FadeIn: not implemented for {this.GetType()}"); if (nodeState == NodeState.FirstRun) { sourceAlpha = GetAlpha(); targetAlpha = shown; fadeTime = fadeInTime; timeSum = -Time.deltaTime / fadeInTime; } if (nodeState == NodeState.Running) { UpdateAlpha(); } } public virtual void FadeOut (MyBT.NodeState nodeState) { // Debug.LogWarning($"ComponentHandler.FadeOut: not implemented for {this.GetType()}"); if (nodeState == NodeState.FirstRun) { sourceAlpha = GetAlpha(); targetAlpha = hidden; fadeTime = fadeOutTime; timeSum = -Time.deltaTime / fadeOutTime; } if (nodeState == NodeState.Running) { UpdateAlpha(); } } public virtual void Set (MyBT.NodeState nodeState, string key, string value) { if (Task.isDebugging) { Debug.LogWarning($"ComponentHandler.Set: not implemented for {this.GetType()}"); } Task.SetError(); } protected float sourceAlpha; protected float targetAlpha; protected float timeSum; protected float fadeTime = 1f; protected float _prevCutOff = -1; protected float hidden = 1; protected float shown = 0; [HideAttributeinSubClass] public float fadeInTime = 1.5f; [HideAttributeinSubClass] public float fadeOutTime = 1.5f; private void UpdateAlpha() { if (timeSum < 1) { float diffColor = targetAlpha - GetAlpha(); timeSum += Time.deltaTime / fadeTime; float alphaValue = Mathf.Lerp(sourceAlpha, targetAlpha, timeSum); SetAlpha(alphaValue); } // set final value else { SetAlpha(targetAlpha); Task.SetSucceeded(); } } public virtual void SetAlpha(float alpha) { // Debug.LogWarning($"ComponentHandler.SetAlpha: not implemented for {this.GetType()} {alpha}"); } public virtual float GetAlpha() { // Debug.LogWarning($"ComponentHandler.GetAlpha: not implemented for {this.GetType()}"); return targetAlpha; } }