コード例 #1
0
        void OnTriggerStay(Collider col)
        {
            INPCPerceivable p = col.GetComponent <INPCPerceivable>();

            if (p != null)
            {
                Vector3 diff  = Vector3.Normalize(p.GetTransform().position - transform.position);
                float   angle = Vector3.Dot(transform.forward, diff);
                if (!g_PerceivedObjects.Contains(p) && angle >= g_HalfViewAngle)
                {
                    if (p.GetNPCEntityType() == PERCEIVEABLE_TYPE.NPC)
                    {
                        g_PerceivedNPCAgents.Add(p);
                    }
                    g_PerceivedObjects.Add(p);
                }
                else if (angle < g_HalfViewAngle)
                {
                    g_PerceivedObjects.Remove(p);
                    if (g_PerceivedNPCAgents.Contains(p))
                    {
                        g_PerceivedNPCAgents.Remove(p);
                    }
                }
            }
        }
コード例 #2
0
        public void OnTriggerExit(Collider collider)
        {
            INPCPerceivable c = collider.gameObject.GetComponent <INPCPerceivable>();

            if (c != null)
            {
                c.SetCurrentContext(null);
            }
        }
コード例 #3
0
        void OnTriggerExit(Collider col)
        {
            INPCPerceivable p = col.GetComponent <INPCPerceivable>();

            if (p != null && g_PerceivedObjects.Contains(p))
            {
                g_PerceivedObjects.Remove(p);
                if (p.GetNPCEntityType() == PERCEIVEABLE_TYPE.NPC)
                {
                    g_PerceivedNPCAgents.Remove(p);
                }
            }
        }
コード例 #4
0
        public void InitializePerception()
        {
            g_PerceptionFieldRadius = PerceptionRadius;
            Animator aC = GetComponent <Animator>();

            g_Head       = aC.GetBoneTransform(HumanBodyBones.Head);
            g_Controller = GetComponent <NPCController>();
            g_Perceiving = false;
            g_CurrentlyPerceivedTarget           = null;
            g_PerceivedObjects                   = new HashSet <INPCPerceivable>();
            g_PerceivedNPCAgents                 = new HashSet <INPCPerceivable>();
            g_HalfViewAngle                      = 1f - (ViewAngle / 180f); // 2 for each half, 90 forward to right
            gPerceptionField.transform.position += transform.up;
        }
コード例 #5
0
        public static Vector3 CalculateObjectNormal(INPCPerceivable object1, INPCPerceivable object2)
        {
            Vector3 basicNormal = object2.GetPosition() - object1.GetPosition();

            if (Mathf.Abs(basicNormal.x) > Mathf.Abs(basicNormal.z))
            {
                // west or east
                return(object2.GetPosition().x - object1.GetPosition().x <= 0 ?
                       new Vector3(1f, 0f, 0f) : new Vector3(-1f, 0f, 0f));
            }
            else
            {
                // north or south
                return(object2.GetPosition().z - object1.GetPosition().z <= 0 ?
                       new Vector3(1f, 0f, -1f) : new Vector3(0f, 0f, 1f));
            }
        }
コード例 #6
0
 public bool ReachFor(INPCPerceivable per)
 {
     return(false);
 }
コード例 #7
0
 public bool CanBeReached(INPCPerceivable per)
 {
     return(Vector3.Distance(per.GetTransform().position, RIGHT_HAND.position) <= REACH_DISTANCE);
 }
コード例 #8
0
 public Vector3 CalculateSlidingForce(INPCPerceivable p)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public Vector3 CalculateAgentRepulsionForce(INPCPerceivable p)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public float CalculatePerceptionWeight(INPCPerceivable p)
 {
     return(0f);
 }
コード例 #11
0
        public bool IsEntityPerceived(Transform t)
        {
            INPCPerceivable p = t.GetComponentInParent <INPCPerceivable>();

            return(p != null && PerceivedEntities.Contains(p));
        }
コード例 #12
0
        /// <summary>
        /// Evaluates the instance assertion.
        /// </summary>
        /// <returns>True if succeeded, False otherwise</returns>
        public bool Evaluate()
        {
            bool result = false;
            // Populate evaluation targets
            List <object> targets = new List <object>();

            switch (Target)
            {
            case TARGET.SELF:
                targets.Add(Agent);
                break;

            case TARGET.AGENT:
                foreach (NPCController agent in Agent.PerceivedAgents)
                {
                    targets.Add(agent);
                }
                break;

            case TARGET.OBJECT:
                foreach (INPCPerceivable obj in Agent.PerceivedEntities)
                {
                    if (obj is NPCObject)
                    {
                        targets.Add(obj);
                    }
                }
                break;

            case TARGET.ENTITY:
                foreach (INPCPerceivable obj in Agent.PerceivedEntities)
                {
                    targets.Add(obj);
                }
                break;
            }
            // Perform Evaluation
            foreach (object o in targets)
            {
                switch (Assert)
                {
                case ASSERT.TAG:
                    try {
                        if (o.GetType().GetMethod("HasTag") != null)
                        {
                            INPCPerceivable per = ((INPCPerceivable)o);
                            bool            res = per.HasTag(TargetValue.GetValue().ToString());
                            if (res)
                            {
                                Result = per.GetGameObject();
                                result = true;
                            }
                        }
                    } catch (Exception e) { Debug.LogError(this + " - Error evaluating Tag: " + e.Message); }
                    break;

                case ASSERT.PROPERTY:
                    try {
                        if (o.GetType().GetProperty(Property.Name) != null)
                        {
                            if (Property.PropertyType == typeof(int) || Property.PropertyType == typeof(float) || Property.PropertyType == typeof(long))
                            {
                                bool matched = false;
                                var  val     = Convert.ToSingle(Property.GetValue(o, null));
                                var  val2    = Convert.ToSingle(TargetValue.GetValue());
                                switch (EqualityOperation)
                                {
                                case OPERATION.EQUALS:
                                    matched = val == val2;
                                    break;

                                case OPERATION.GREATER:
                                    matched = val > val2;
                                    break;

                                case OPERATION.LESS:
                                    matched = val < val2;
                                    break;
                                }
                                if (matched)
                                {
                                    Result = ((INPCPerceivable)o).GetGameObject();
                                    result = true;
                                }
                            }
                            else if (Property.PropertyType == typeof(int))
                            {
                                var val  = Convert.ToBoolean(Property.GetValue(o, null));
                                var val2 = Convert.ToBoolean(TargetValue.GetValue());
                                if (val.Equals(val2))
                                {
                                    Result = ((INPCPerceivable)o).GetGameObject();
                                    result = true;
                                }
                            }
                        }
                    } catch (Exception e) { Debug.LogError(this + " - Error evaluating Tag: " + e.Message); }
                    break;

                case ASSERT.TRANSFORM:
                    INPCPerceivable p = o as INPCPerceivable;
                    if (p != null)
                    {
                        Transform t         = p.GetTransform();
                        float     val       = 0;
                        float     targetVal = Convert.ToSingle(TargetValue.GetValue());
                        bool      matched   = false;
                        switch (TransformAssert)
                        {
                        case TRANSFORM_ASSERT.DISTANCE:
                            val = Vector3.Distance(Agent.transform.position, p.GetTransform().position);
                            break;

                        case TRANSFORM_ASSERT.ORIENTATION:
                            val = Vector3.Angle(Agent.transform.forward, p.GetTransform().forward);
                            break;
                        }
                        switch (EqualityOperation)
                        {
                        case OPERATION.EQUALS:
                            matched = val == targetVal;
                            break;

                        case OPERATION.GREATER:
                            matched = val > targetVal;
                            break;

                        case OPERATION.LESS:
                            matched = val < targetVal;
                            break;
                        }
                        if (matched)
                        {
                            Result = ((INPCPerceivable)o).GetGameObject();
                            result = true;
                        }
                    }
                    break;
                }
            }
            return(Negate ? !result : result);
        }