Beispiel #1
0
        new void Awake()
        {
            base.Awake();

            //// initialize focus
            touchStorage = RegisterSenseInBlackboard(BehaviourPack.touchId);
        }
Beispiel #2
0
        new void Awake()
        {
            base.Awake();

            //// initialize focus
            painStorage = RegisterSenseInBlackboard(BehaviourPack.painId);
            var healthController = GetComponentInParent <HealthController>();

            healthController.onDamageCallback += (data) =>
            {
                if (!tPain.IsReadyRestart())
                {
                    return;
                }

                MemoryEvent ev = new MemoryEvent();
                ev.exactPosition = data.position;
                ev.forward       = data.direction;
                // we have no information about hit velocity; just assume it is stationary
                ev.velocity = Vector2.zero;
                ev.lifetimeTimer.Restart();

                painStorage.PerceiveEvent(ev);

                Debug.DrawRay(ev.position, Vector3.up, Color.blue, 0.25f);
            };
        }
Beispiel #3
0
        public StimuliFilter(StimuliStorage storage,
                             Func <MemoryEvent, float> measureMethod)
        {
            Debug.Assert(storage != null);
            Debug.Assert(measureMethod != null);

            this.storage       = storage;
            this.measureMethod = measureMethod;
        }
Beispiel #4
0
        public FocusFilterStorage(Transform transform, StimuliStorage storage,
                                  StimuliStorage.MeasureEventMethod measureMethod)
            : base(transform)
        {
            Debug.Assert(storage != null);
            Debug.Assert(measureMethod != null);

            this.storage       = storage;
            this.measureMethod = measureMethod;
        }
Beispiel #5
0
        new void Awake()
        {
            base.Awake();

            // cache transform
            cachedTransform = base.transform;

            enemyStorage   = RegisterSenseInBlackboard(BehaviourPack.enemyId);
            allyStorage    = RegisterSenseInBlackboard(BehaviourPack.allyId);
            neutralStorage = RegisterSenseInBlackboard(BehaviourPack.neutralId);
        }
Beispiel #6
0
        // filters by distance from local position
        public StimuliFilter(StimuliStorage storage, Transform transform,
                             Vector2 localPoint, float distanceUtilityScale = 0.0f, float timeUtilityScale = 1.0f, float maxLifetime = float.MaxValue)
        {
            Debug.Assert(storage != null);

            this.storage       = storage;
            this.measureMethod = (MemoryEvent memoryEvent) =>
            {
                if (memoryEvent.elapsedDistance > maxLifetime)
                {
                    return(float.MaxValue);
                }

                float timeUtility     = -memoryEvent.elapsedTime;
                float distanceUtility = -(transform.TransformPoint(localPoint) - memoryEvent.position).ToPlane().magnitude;

                float utility = timeUtility * timeUtilityScale + distanceUtility * distanceUtilityScale;
                return(utility);
            };
        }
Beispiel #7
0
        // filters by distance from local position
        public FocusFilterStorage(Transform transform, StimuliStorage storage,
                                  Vector2 localPoint, float distanceUtilityScale = 0.0f, float timeUtilityScale = 1.0f, float maxLifetime = float.MaxValue)
            : base(transform)
        {
#if UNITY_EDITOR
            Debug.Assert(storage != null);
#endif

            this.storage       = storage;
            this.measureMethod = (MemoryEvent memoryEvent) =>
            {
                /*if (memoryEvent.elapsedDistance > maxLifetime)
                 *  return float.MaxValue;*/

                float timeUtility     = -memoryEvent.elapsedTime;
                float distanceUtility = -((Vector2)transform.TransformPoint(localPoint) - memoryEvent.position).magnitude;

                float utility = timeUtility * timeUtilityScale + distanceUtility * distanceUtilityScale;
                return(utility);
            };
        }
Beispiel #8
0
        // filters by distance from center
        public FocusFilterStorage(Transform transform, StimuliStorage storage,
                                  float distanceUtilityScale = 0.0f, float timeUtilityScale = 1.0f, float maxLifetime = float.MaxValue)
            : base(transform)
        {
            Debug.Assert(storage != null);

            this.storage       = storage;
            this.measureMethod = (MemoryEvent memoryEvent) =>
            {
                if (memoryEvent.elapsedDistance > maxLifetime)
                {
                    return(float.MinValue);
                }

                float timeUtility     = -memoryEvent.elapsedTime;
                float distanceUtility = -((Vector2)transform.position - memoryEvent.position).magnitude;

                float utility = timeUtility * timeUtilityScale + distanceUtility * distanceUtilityScale;
                return(utility);
            };
        }