예제 #1
0
파일: AIMBehaviour.cs 프로젝트: qipa/AI-4
        //--------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// This function is called when the script is loaded or a value is changed in the inspector (editor only).
        /// <para/>
        /// Use this function to validate the data of your MonoBehaviours. This can be used to ensure that when you
        /// modify data in an editor that the data stays within a certain range.
        /// </summary>
        protected virtual void OnValidate()
        {
            if (!Application.isPlaying)
            {
                aimContext = GetComponent <AIMContext>();
            }
        }
예제 #2
0
 void Start()
 {
     myBody     = this.GetComponent <Rigidbody2D>();
     anim       = this.GetComponent <Animator>();
     aimContext = this.GetComponent <AIMContext>();
     rend       = this.GetComponent <SpriteRenderer>();
     CambiarColorEnemy();
 }
예제 #3
0
    void Update()
    {
        AIMContext aimContext = GetComponent <AIMContext>();

        Vector2 target = aimContext.DecidedDirection - transform.position;

        controller.Move(aimContext.DecidedDirection.x * runSpeed * Time.deltaTime, _crouch, _jump);
        _jump = false;
    }
예제 #4
0
        private void OnEnable()
        {
            if (Context == null)
            {
                Context = GetComponentInChildren <AIMContext>();
            }

            if (Context == null)
            {
                enabled = false;
            }
        }
예제 #5
0
        private void Start()
        {
            // Spawn the entity
            spawnedEntity = (GameObject)Instantiate(Entity, transform.position, Quaternion.identity);
            NetworkServer.Spawn(spawnedEntity);

            AIMContext context = GetComponent <AIMContext>();

            // If you want to use this script for you own examples, you have to replace this controller with your own.
            PhysicsController2D controller = spawnedEntity.GetComponent <PhysicsController2D>();

            controller.Context = context;
            controller.enabled = true;
        }
예제 #6
0
파일: AIMBehaviour.cs 프로젝트: qipa/AI-4
        //--------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Awake is called when the script instance is being loaded.
        /// </summary>
        protected virtual void Awake()
        {
            aimContext = GetComponent <AIMContext>();
            aimContext.EvaluationPreparers.Add(this);
            context           = aimContext.Context;
            Behaviour.Context = context;
            Behaviour.Order   = Order;
            RegisterBehaviour();
            if (!initialized)
            {
                Reset();
            }

            gameObject.GetComponents <AIMSeek>();
        }
        private void OnEnable()
        {
            if (Body == null)
            {
                Body = gameObject.GetComponentInChildren <Rigidbody>();
            }
            if (Context == null)
            {
                Context = gameObject.GetComponentInChildren <AIMContext>();
            }

            // Disable if the setup is invalid.
            if (Body == null || Context == null)
            {
                enabled = false;
            }
        }
예제 #8
0
파일: AIMBehaviour.cs 프로젝트: qipa/AI-4
        //--------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Generates a list containing all objectives currently available within the associated <see cref="Context"/>.
        /// <para/>
        /// This may be used as default parametrization for behaviours allowing the use of multiple target objectives,
        /// like for instance <see cref="PlanarConvolution"/> and <see cref="Retention"/>.
        /// </summary>
        /// <returns>
        /// A list containing all objectives currently available within the associated <see cref="Context"/>.
        /// </returns>
        protected List <int> GetDefaultTargetObjectives()
        {
            List <int> targetObjectives = new List <int>();
            AIMContext aimContext       = GetComponent <AIMContext>();

            if (aimContext != null)
            {
                // The following is ugly but necessary due to Unity's arbitrary order of calling Awake
                if (aimContext.Context.Problem.ObjectiveCount == 0)
                {
                    aimContext.BuildContext();
                }

                for (int i = 0; i < aimContext.Context.Problem.ObjectiveCount; i++)
                {
                    targetObjectives.Add(i);
                }
            }
            return(targetObjectives);
        }
        private void OnEnable()
        {
            if (Animator == null)
            {
                Animator = GetComponent <Animator>();
            }

            if (Context == null)
            {
                Context = GetComponent <AIMContext>();
            }

            if (Context == null || Animator == null)
            {
                Debug.LogWarning('(' + typeof(RootMotionController).Name + ") " + name + ": deactivated because a " +
                                 "reference to either an AIMContext or an Animator is missing.");
                enabled = false;
                return;
            }

            Animator.applyRootMotion = true;
        }