Пример #1
0
        public override void OnStart()
        {
            // Tell the Behavior Manager that we are running a ICodeBehaviour instance.
            if (iCodeBehavior != null && (!waitForStateMachineCompletion.Value || BehaviorManager.instance.MapObjectToTask(iCodeBehavior, this, BehaviorManager.ThirdPartyObjectType.ICode)))
            {
                if (waitForStateMachineCompletion.Value)
                {
                    status = TaskStatus.Running;
                }
                else
                {
                    status = TaskStatus.Success;
                }

                // Synchronize variables
                if (synchronizeVariables.Value)
                {
                    BehaviorManager.instance.SyncVariablesToICode(Owner.GetBehaviorSource(), iCodeBehavior.stateMachine.Variables);
                }
                if (synchronizeGlobalVariables.Value)
                {
                    BehaviorManager.instance.SyncGlobalVariablesToICode();
                }

                iCodeBehavior.EnableStateMachine();
                iCodeBehavior.enabled = true;
            }
            else
            {
                // If something went wrong then return failure.
                status = TaskStatus.Failure;
            }
        }
        public override TaskStatus OnUpdate()
        {
            // Tell the Behavior Manager that we are running a State Machine instance.
            if (iCodeBehavior != null && BehaviorManager.instance.MapObjectToTask(iCodeBehavior, this, BehaviorManager.ThirdPartyObjectType.ICode))
            {
                status = TaskStatus.Failure;

                iCodeBehavior.EnableStateMachine();
                iCodeBehavior.enabled = true;

                // Remove the task from the mapping immediately after the event is called. If the state machine hasn't returned by now it is running longer than one frame and has lost its chance to return
                BehaviorManager.instance.RemoveActiveThirdPartyTask(this);
            }
            else
            {
                // If something went wrong then return failure.
                status = TaskStatus.Failure;
            }
            return(status);
        }