public virtual FluentNodeHandler GetHandler() { // ? if (currentHandler != null) { return(currentHandler); } // Get the handler type attribute defined on the class FluentNodeHandlerAttribute handlerAttribute = (FluentNodeHandlerAttribute)this.GetType().GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(FluentNodeHandlerAttribute)); if (handlerAttribute == null) { Debug.LogError("You need to specify the FluentNodeHandler for '" + GetType().Name + "' by adding the FluentNodeHandler attribute or overriding GetHandler()", GameObject); return(null); } // Type fluentNodeHandlerType = handlerAttribute.FluentNodeHandlerType; // Make sure the handler is a monobehaviour if (!fluentNodeHandlerType.IsSubclassOf(typeof(MonoBehaviour))) { Debug.LogError("Your FluentNodeHandlerType '" + fluentNodeHandlerType.Name + "' needs to inherit from MonoBehaviour", GameObject); return(null); } // Try to get a component with the handler type from this game object FluentNodeHandler handler = GameObject.GetComponent(fluentNodeHandlerType) as FluentNodeHandler; if (handler == null) { // If the user had to add the handler explicitly but its missing, show an error if (handlerAttribute.IsExplicit) { Debug.LogError("You have to explicitly add the '" + fluentNodeHandlerType.Name + "' handler for the '" + GetType().Name + "' FluentNode to work", GameObject); return(null); } // Add the handler if we are allowed to if (fluentNodeHandlerType != null) { handler = GameObject.AddComponent(fluentNodeHandlerType) as FluentNodeHandler; } } currentHandler = handler; return(currentHandler); }
/// <summary> /// If a node does not override Execute we'll try and see if it has a handler /// If it does have a handler we start it, otherwise we just call Done /// </summary> /// <param name="fluentScript"></param> public virtual void Execute() { // Try to get a handler FluentNodeHandler handler = GetHandler(); // If there isn't a handler we complete the fluentnode if (handler == null) { DoneDelegate(this); return; } // Give this node to the handler we just created handler.HandleFluentNode(this); }
public FluentNode(GameObject gameObject) { InterruptDelegate = null; currentHandler = null; GameObject = gameObject; }