#if HAVE_NODECANVAS using System; using UnityEngine; using ParadoxNotion.Design; using NodeCanvas.Framework; using Framework.State; namespace Framework.Actors { /// Lets the player assume control over an actor [Category("Actors")] [Description("Lets the player assume control over an actor")] public class TakeControlTask : ActionTask { /// Actor over which the player will get control [RequiredField] public BBParameter Actor; /// Index of the player that will assume control of the actor public int PlayerIndex = 0; /// Injects the instance's dependencies /// Manages the active game object /// /// This method is called automatically by the services framework. Any parameters /// it requires will be filled out by looking up the respective services and creating /// them as needed. /// protected void Inject(IControlManager controlManager) { this.controlManager = controlManager; } /// Summary of what this action does protected override string info { get { return "Give player control over " + this.Actor.name; } } /// Called once when the action is executed protected override void OnExecute() { IControllable controllableActor = this.Actor.value.GetComponent(); if(controllableActor == null) { Debug.LogError( "Actor '" + this.Actor.name + "' is not a controllable actor that implements " + "the IControllable interface. Player will NOT get control of the actor." ); return; } // If we don't have the control manager, ask the dependency injector if(this.controlManager == null) { Services.ServiceInjector.InjectDependencies(this); } // If we still don't have it, something is very wrong and we blow up. if(this.controlManager == null) { throw new InvalidOperationException( "Could not obtain IControlManager service. The dependeny injector is broken." ); } this.controlManager.AssumeControl(this.PlayerIndex, controllableActor); EndAction(); } /// Service managing which actor the player is controlling [NonSerialized] private IControlManager controlManager; } } // namespace Framework.Actors #endif // HAVE_NODECANVAS