Beispiel #1
0
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
            //寄主势力
            Individual.Power masterPower = gameObject.GetComponent <Individual>().power;
            //计算出对应的敌对势力
            Individual.Power enemyPower = Individual.Power.Neutral;
            switch (masterPower)
            {
            case Individual.Power.Monster: enemyPower = Individual.Power.Human; break;

            case Individual.Power.Human: enemyPower = Individual.Power.Monster; break;
            }

            if (usePhysics2D)
            {
                //单个目标对象来筛选敌对目标
                if (targetObject.IsShared)
                {
                    if (targetObject.Value)
                    {
                        objectInSight.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
                    }
                }
                //个体层+敌对势力来筛选敌对目标
                else
                {
                    objectInSight.Value = ExtendedMovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, enemyPower);
                }
            }
            else
            {
                //单个目标对象来筛选敌对目标
                if (targetObject.IsShared)
                {
                    if (targetObject.Value)
                    {
                        objectInSight.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
                    }
                }
                //个体层+敌对势力来筛选敌对目标
                else
                {
                    objectInSight.Value = ExtendedMovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, enemyPower);
                }
            }

            if (objectInSight.Value != null)
            {
                // Return success if an object was found
                return(TaskStatus.Success);
            }
            // An object is not within sight so return failure
            return(TaskStatus.Failure);
        }
Beispiel #2
0
        /// <summary>
        ///  检测对应layer且对应势力的对象
        /// </summary>
        /// <param name="transform"></param>
        /// <param name="positionOffset"></param>
        /// <param name="fieldOfViewAngle"></param>
        /// <param name="viewDistance"></param>
        /// <param name="objectLayerMask"></param>
        /// <param name="势力"></param>
        /// <returns></returns>
        public static Transform WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask, Individual.Power power)
        {
            Transform objectFound  = null;
            var       hitColliders = Physics.OverlapSphere(transform.position, viewDistance, objectLayerMask);

            if (hitColliders != null)
            {
                for (int i = 0; i < hitColliders.Length; ++i)
                {
                    Transform obj;
                    //检测势力是否一致
                    if (hitColliders[i].gameObject.GetComponent <Individual>().power != power)
                    {
                        continue;
                    }
                    // Call the WithinSight function to determine if this specific object is within sight
                    if ((obj = MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, hitColliders[i].transform)) != null)
                    {
                        objectFound = obj;
                    }
                }
            }
            return(objectFound);
        }