예제 #1
0
        bool FindNearestObstade(RayAgentData data, Vector3 target, out RayAgentHitInfo hitInfo, float distance, bool onlyCenter)
        {
            hitInfo = null;
            bool    hasHit      = false;
            float   minDistance = Vector3.Distance(data.Position, target);
            Vector3 direction   = target - data.Position;

            data.SetDirection(direction);

            Vector3[]  anchors = data.Anchors;
            RaycastHit hit;

            for (int i = 0; i < anchors.Length; i++)
            {
                if (onlyCenter)
                {
                    if (i != (int)RayAgentPos.Center)
                    {
                        continue;
                    }
                }

                if (Physics.Raycast(anchors[i], direction, out hit, distance, layerMask.value))
                {
                    if (hit.transform == _target)
                    {
                        continue;
                    }
                    ObstacleBox obstacle = hit.transform.GetComponent <ObstacleBox>();
                    if (obstacle != null)
                    {
                        if (hit.distance < minDistance)
                        {
                            minDistance = hit.distance;

                            if (hitInfo == null)
                            {
                                hitInfo = new RayAgentHitInfo();
                            }
                            hitInfo.hit      = hit;
                            hitInfo.obstacle = obstacle;
                            hitInfo.pos      = (RayAgentPos)i;
                            hitInfo.hitpoint = hit.point;
                            if (hitInfo.pos == RayAgentPos.Right)
                            {
                                hitInfo.hitpoint += (data.Position - data.Right).normalized * data.radius;
                            }
                            else if (hitInfo.pos == RayAgentPos.Right)
                            {
                                hitInfo.hitpoint += (data.Position - data.Left).normalized * data.radius;
                            }
                            hasHit = true;
                        }
                    }
                }
            }

            return(hasHit);
        }
예제 #2
0
 public void RemoveObstacleBox(ObstacleBox obstacleBox)
 {
     obstacleBox.change -= OnChange;
     list.Remove(obstacleBox);
     isChange = true;
 }
예제 #3
0
 void OnChange(ObstacleBox obstacleBox)
 {
     isChange = true;
 }
예제 #4
0
 public void AddObstacleBox(ObstacleBox obstacleBox)
 {
     obstacleBox.change += OnChange;
     list.Add(obstacleBox);
     isChange = true;
 }