예제 #1
0
        public WaypointObject GetWaypointByPosition(Vector3 _position)
        {
            WaypointObject new_waypoint       = null;
            int            new_waypoint_index = m_WaypointIndex;
            float          distance           = Mathf.Infinity;

            List <WaypointObject> _waypoints = GetEnabledWaypoints();

            for (int i = 0; i < _waypoints.Count; i++)
            {
                float tmp_distance = PositionTools.Distance(_position, _waypoints[i].TargetOffsetPosition);
                if (tmp_distance < distance)
                {
                    new_waypoint_index = i;
                    new_waypoint       = _waypoints[new_waypoint_index];
                    distance           = tmp_distance;
                }
            }

            if (new_waypoint != null)
            {
                m_LastWaypoint  = m_Waypoint;
                m_Waypoint      = new_waypoint;
                m_WaypointIndex = new_waypoint_index;
            }

            return(m_Waypoint);
        }
예제 #2
0
        public WaypointObject GetLastValidWaypoint()
        {
            WaypointObject _last_waypoint = null;

            foreach (WaypointObject _waypoint in m_Waypoints)
            {
                if (_waypoint.TargetGameObject != null && _waypoint.Enabled)
                {
                    _last_waypoint = _waypoint;
                }
            }

            return(_last_waypoint);
        }
예제 #3
0
        public void Copy(WaypointObject _object)
        {
            if (_object == null)
            {
                return;
            }

            base.Copy(_object);

            WaypointFoldout    = _object.WaypointFoldout;
            BehaviourFoldout   = _object.BehaviourFoldout;
            UseCustomBehaviour = _object.UseCustomBehaviour;
            DurationOfStay     = _object.DurationOfStay;
            IsTransitPoint     = _object.IsTransitPoint;

            BehaviourModeTravel     = _object.BehaviourModeTravel;
            BehaviourModePatrol     = _object.BehaviourModePatrol;
            BehaviourModeLeisure    = _object.BehaviourModeLeisure;
            BehaviourModeRendezvous = _object.BehaviourModeRendezvous;
        }
예제 #4
0
 public WaypointObject(WaypointObject _object) : base(TargetType.WAYPOINT)
 {
     Copy(_object);
 }
예제 #5
0
        public WaypointObject GetNextWaypoint()
        {
            List <WaypointObject> _waypoints = GetEnabledWaypoints();

            if (_waypoints.Count == 0)
            {
                return(null);
            }

            WaypointObject new_waypoint       = null;
            int            new_waypoint_index = m_WaypointIndex;

            if (_waypoints.Count == 1)
            {
                new_waypoint_index = 0;
                new_waypoint       = _waypoints[new_waypoint_index];
            }
            else if (Order == WaypointOrderType.RANDOM)
            {
                new_waypoint_index = Random.Range(0, _waypoints.Count);
                new_waypoint       = _waypoints[new_waypoint_index];
            }
            else
            {
                if (Order == WaypointOrderType.PINGPONG)
                {
                    if (Ascending && new_waypoint_index + 1 >= _waypoints.Count)
                    {
                        Ascending = false;
                    }
                    else if (!Ascending && new_waypoint_index - 1 < 0)
                    {
                        Ascending = true;
                    }
                }

                if (Ascending)
                {
                    new_waypoint_index++;

                    if (new_waypoint_index >= _waypoints.Count)
                    {
                        new_waypoint_index = 0;
                    }
                }
                else
                {
                    new_waypoint_index--;

                    if (new_waypoint_index < 0)
                    {
                        new_waypoint_index = _waypoints.Count - 1;
                    }
                }

                new_waypoint = _waypoints[new_waypoint_index];
            }


            if (new_waypoint != null)
            {
                m_LastWaypoint  = m_Waypoint;
                m_Waypoint      = new_waypoint;
                m_WaypointIndex = new_waypoint_index;
            }

            return(m_Waypoint);
        }
예제 #6
0
        /// <summary>
        /// Draws the patrol.
        /// </summary>
        public void DrawPatrol()
        {
            if (!CreatureControl.Creature.Missions.Patrol.TargetReady() || ShowPatrol == false)
            {
                return;
            }

            TargetObject _target = null;
            Vector3      _target_move_position = Vector3.zero;
            float        _target_stop_distance = 0;

            WaypointObject _last_waypoint_target = CreatureControl.Creature.Missions.Patrol.Waypoints.GetLastValidWaypoint();

            Vector3 _last_target_move_position = Vector3.zero;
            float   _last_target_stop_distance = 0;

            if (_last_waypoint_target != null)
            {
                _last_target_move_position   = _last_waypoint_target.TargetMovePosition;
                _last_target_move_position.y = GetLevel();
                _last_target_stop_distance   = _last_waypoint_target.TargetStopDistance;
            }

            for (int i = 0; i < CreatureControl.Creature.Missions.Patrol.Waypoints.Waypoints.Count; i++)
            {
                _target = (TargetObject)CreatureControl.Creature.Missions.Patrol.Waypoints.Waypoints[i];

                if (_target.IsValid == false)
                {
                    continue;
                }

                _target_move_position   = _target.TargetMovePosition;
                _target_move_position.y = GetLevel();
                _target_stop_distance   = _target.TargetStopDistance;

                if (CreatureControl.Creature.Missions.Patrol.Waypoints.Waypoints[i].Enabled)
                {
                    DrawTargetGizmos(_target);

                    Color _default_color = Gizmos.color;
                    Gizmos.color = MoveProjectedPathColor;
                    CustomGizmos.OffsetPath(_last_target_move_position, _last_target_stop_distance, _target_move_position, _target_stop_distance);
                    Gizmos.color = _default_color;

                    _last_target_move_position = _target_move_position;
                    _last_target_stop_distance = _target_stop_distance;
                }
                else
                {
                    Color _color = TargetColor;
                    _color.a = 0.25f;
                    DrawTargetGizmos(_target, _color);
                }

                if (!Application.isPlaying)
                {
                    BehaviourModeObject _mode = null;
                    _mode = CreatureControl.Creature.Behaviour.GetBehaviourModeByKey(CreatureControl.Creature.Missions.Patrol.GetBehaviourModeTravelByIndex(i));
                    DrawBehaviourModeGizmos(_target, _mode);

                    _mode = CreatureControl.Creature.Behaviour.GetBehaviourModeByKey(CreatureControl.Creature.Missions.Patrol.GetBehaviourModePatrolByIndex(i));
                    DrawBehaviourModeGizmos(_target, _mode);

                    _mode = CreatureControl.Creature.Behaviour.GetBehaviourModeByKey(CreatureControl.Creature.Missions.Patrol.GetBehaviourModeLeisureByIndex(i));
                    DrawBehaviourModeGizmos(_target, _mode);

                    _mode = CreatureControl.Creature.Behaviour.GetBehaviourModeByKey(CreatureControl.Creature.Missions.Patrol.GetBehaviourModeRendezvousByIndex(i));
                    DrawBehaviourModeGizmos(_target, _mode);
                }
            }
        }