Exemple #1
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            GameObject goObserver = this.observer.GetGameObject(target);
            GameObject goTarget   = this.target.GetGameObject(target);

            if (goObserver == null)
            {
                return(false);
            }
            if (goTarget == null)
            {
                return(false);
            }

            Perception perception = goObserver.GetComponentInChildren <Perception>();

            if (perception == null)
            {
                return(false);
            }

            switch (this.operation)
            {
            case Operation.StartTracking:
                perception.StartListenPerceptron(Perception.Type.Sight, goTarget, null);
                break;

            case Operation.StopTracking:
                perception.StopListenPerceptron(Perception.Type.Sight, goTarget, null);
                break;
            }

            return(true);
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            this.perception = (Perception)this.target;

            this.spFieldOfView    = serializedObject.FindProperty("fieldOfView");
            this.spVisionDistance = serializedObject.FindProperty("visionDistance");
            this.spSightLayerMask = serializedObject.FindProperty("sightLayerMask");

            this.sectionSight = new Section("Sight", null, this.Repaint);
        }
Exemple #3
0
        private void OnDestroy()
        {
            GameObject goObserver = this.observer.GetGameObject(gameObject);
            GameObject goTarget   = this.target.GetGameObject(gameObject);

            if (goObserver != null && goTarget != null)
            {
                Perception sensesObserver = goObserver.GetComponent <Perception>();
                if (sensesObserver == null)
                {
                    return;
                }

                sensesObserver.StopListenPerceptron(Perception.Type.Sight, goTarget, this.Callback);
            }
        }
        // HELPER METHODS: ------------------------------------------------------------------------

        public static Transform GetEyes(Perception perception)
        {
            Transform         sight             = perception.transform;
            CharacterAnimator characterAnimator = perception.GetComponent <CharacterAnimator>();

            if (characterAnimator != null && characterAnimator.animator != null)
            {
                Transform head = characterAnimator.animator.GetBoneTransform(HumanBodyBones.Head);
                if (head != null)
                {
                    sight = head;
                }
            }

            return(sight);
        }
        private void Start()
        {
            this.cacheObserver = this.observer.GetComponent <Perception>(gameObject);
            this.cacheList     = this.listVariables.GetListVariables(gameObject);

            if (this.cacheList == null || this.cacheObserver == null)
            {
                return;
            }
            VariablesManager.events.StartListenListAdd(this.OnListCallback, this.cacheList.gameObject);
            VariablesManager.events.StartListenListRmv(this.OnListCallback, this.cacheList.gameObject);
            VariablesManager.events.StartListenListChg(this.OnListCallback, this.cacheList.gameObject);

            for (int i = 0; i < this.cacheList.variables.Count; ++i)
            {
                GameObject value = this.cacheList.variables[i].Get <GameObject>();
                this.OnListCallback(i, null, value);
            }
        }
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool Check(GameObject target)
        {
            GameObject goObserver = this.observer.GetGameObject(target);
            GameObject goTarget   = this.target.GetGameObject(target);

            if (goObserver == null)
            {
                return(false);
            }
            if (goTarget == null)
            {
                return(false);
            }

            Perception senses = goObserver.GetComponentInChildren <Perception>();

            if (senses == null)
            {
                return(false);
            }

            PerceptronSight sight = senses.GetPerceptron(Perception.Type.Sight) as PerceptronSight;

            if (sight == null)
            {
                return(false);
            }

            switch (this.condition)
            {
            case Condition.CanSee: return(sight.CanSee(goTarget));

            case Condition.CanNotSee: return(!sight.CanSee(goTarget));

            default: return(false);
            }
        }
 public virtual void Awake(Perception perception)
 {
     this.perception = perception;
 }
        // INITIALIZERS: --------------------------------------------------------------------------

        public override void Awake(Perception perception)
        {
            base.Awake(perception);
            this.eyes = PerceptronSight.GetEyes(perception);
        }