public void DrawOwnerGizmos() { #if UNITY_EDITOR Vector3 _owner_pos = m_Owner.transform.position; _owner_pos.y = GetLevel(); CustomGizmos.Triangle(_owner_pos, m_Owner.transform.forward, 2, 35); if (m_creature_control.Creature.Move.FieldOfView > 0) { float _angle = m_creature_control.Creature.Move.FieldOfView; float _distance = m_creature_control.Creature.Move.VisualRange; if (_distance == 0) { _distance = 1.5f; } float _degree = CustomGizmos.GetBestDegrees(_distance, _angle); CustomGizmos.ArrowArc(m_Owner.transform, _distance, _degree, -_angle, _angle, GetLevel()); if (_angle < 180) { Vector3 _left_pos = Tools.GetDirectionPosition(m_Owner.transform, -_angle, _distance); Vector3 _right_pos = Tools.GetDirectionPosition(m_Owner.transform, _angle, _distance); CustomGizmos.OffsetPath(m_Owner.transform.position, 2, _left_pos, 1); CustomGizmos.OffsetPath(m_Owner.transform.position, 2, _right_pos, 1); } } if (m_creature_control.Creature.Move.GroundOrientation == GroundOrientationType.NONE || m_creature_control.Creature.Move.GroundOrientation == GroundOrientationType.QUADRUPED) { if (m_creature_control.Creature.Move.GroundOrientationPlus) { UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.FrontLeftPositionGround, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.BackLeftPositionGround, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.FrontRightPositionGround, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.BackRightPositionGround, m_Owner.transform.rotation, 0.1f); Gizmos.DrawLine(m_creature_control.Creature.Move.FrontLeftPositionGround, m_creature_control.Creature.Move.FrontLeftPosition); Gizmos.DrawLine(m_creature_control.Creature.Move.BackLeftPositionGround, m_creature_control.Creature.Move.BackLeftPosition); Gizmos.DrawLine(m_creature_control.Creature.Move.FrontRightPositionGround, m_creature_control.Creature.Move.FrontRightPosition); Gizmos.DrawLine(m_creature_control.Creature.Move.BackRightPositionGround, m_creature_control.Creature.Move.BackRightPosition); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.FrontLeftPosition, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.BackLeftPosition, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.FrontRightPosition, m_Owner.transform.rotation, 0.1f); UnityEditor.Handles.CubeCap(0, m_creature_control.Creature.Move.BackRightPosition, m_Owner.transform.rotation, 0.1f); } } #endif }
public void DrawMoveGizmos() { #if UNITY_EDITOR if (m_Owner == null || m_creature_control.Creature.Move.CurrentTarget == null) { return; } TargetObject _target = m_creature_control.Creature.Move.CurrentTarget; Vector3 _move_position = m_creature_control.Creature.Move.MovePosition; Vector3 _target_move_position = _target.TargetMovePosition; float _move_stop_distance = m_creature_control.Creature.Move.CurrentMove.MoveStopDistance; float _move_lateral_variance = m_creature_control.Creature.Move.CurrentMove.MoveLateralVariance; Vector3 _owner_pos = m_Owner.transform.position; _owner_pos.y = GetLevel(); _move_position.y = GetLevel(); _target_move_position.y = GetLevel(); CustomGizmos.OffsetPath(_owner_pos, 2, _move_position, _move_stop_distance); // PATH FROM CREATURE TO NEXT MOVE POSITION CustomGizmos.Circle(_move_position, _move_stop_distance, 5, false); // STOP DISTANCE RANGE if (m_creature_control.Creature.Move.CurrentMove.Type != MoveType.ESCAPE) { CustomGizmos.OffsetPath(_move_position, _move_stop_distance, _target_move_position, _target.TargetStopDistance); // PATH NEXT MOVE POSITION TO TARGET MOVE POSITION } if (_move_lateral_variance > 0) { float _max_range = _move_stop_distance + _move_lateral_variance; CustomGizmos.ZickZackCircle(_move_position, _move_lateral_variance, "", false); // RANDOM RANGE CustomGizmos.Circle(_move_position, _max_range, 5, true); // MAX MOVE RANGE } #endif }
/// <summary> /// Draws the interaction. /// </summary> public void DrawInteraction() { if (CreatureControl.Creature.Interaction.Interactors.Count == 0 || ShowInteractor == false) { return; } for (int i = 0; i < CreatureControl.Creature.Interaction.Interactors.Count; i++) { InteractorObject _interactor = CreatureControl.Creature.Interaction.Interactors[i]; if (!_interactor.Enabled) { continue; } List <GameObject> _target_game_objects = GetCreaturesByName(_interactor.Name); if (_target_game_objects != null && _target_game_objects.Count > 0) { foreach (GameObject _target_game_object in _target_game_objects) { Vector3 _interactor_pos = _target_game_object.transform.position; TargetObject _target = new TargetObject(TargetType.INTERACTOR); _target.TargetGameObject = _target_game_object; _target.BehaviourModeKey = _interactor.BehaviourModeKey; _target.Selectors.Copy(_interactor.Selectors); _target.UpdateOffset(_interactor.DefaultOffset); _target.TargetStopDistance = _interactor.DefaultStopDistance; _target.TargetRandomRange = _interactor.DefaultRandomRange; _target.TargetSmoothingMultiplier = 0; //_interactor.DefaultSmoothingMultiplier; // TODO:REWORK TargetSmoothingMultiplier _target.TargetIgnoreLevelDifference = _interactor.DefaultIgnoreLevelDifference; DrawTargetGizmos(_target); // DIRECTION CustomGizmos.Arrow(_target.TargetPosition, _target.TargetDirection * _target.TargetStopDistance, 0.5f, 20); Vector3 _last_move_position = _target.TargetMovePosition; float _last_stop_distance = _target.TargetStopDistance; _last_move_position.y = GetLevel(); Color _default_color = Gizmos.color; Color _target_color = (_target.Active?ActiveTargetColor:TargetColor); foreach (InteractorRuleObject _rule in _interactor.Rules) { if (!_rule.Enabled) { continue; } _target = new TargetObject(TargetType.INTERACTOR); _target.TargetGameObject = _target_game_object; _target.BehaviourModeKey = _rule.BehaviourModeKey; _target.Selectors.Copy(_rule.Selectors); _target.UpdateOffset(_interactor.DefaultOffset); _target.TargetStopDistance = _interactor.DefaultStopDistance; _target.TargetRandomRange = _interactor.DefaultRandomRange; _target.TargetSmoothingMultiplier = 0; //_interactor.DefaultSmoothingMultiplier; // TODO:REWORK TargetSmoothingMultiplier _target.TargetIgnoreLevelDifference = _interactor.DefaultIgnoreLevelDifference; if (_rule.OverrideTargetMovePosition) { _target.UpdateOffset(_rule.Offset); _target.TargetStopDistance = _rule.StopDistance; _target.TargetRandomRange = _rule.RandomRange; _target.TargetSmoothingMultiplier = 0; _target.TargetIgnoreLevelDifference = _rule.IgnoreLevelDifference; } DrawTargetGizmos(_target); Vector3 _move_position = _target.TargetMovePosition; _move_position.y = GetLevel(); Gizmos.color = _target_color; if (_last_move_position != Vector3.zero) { CustomGizmos.OffsetPath(_last_move_position, _last_stop_distance, _move_position, _target.TargetStopDistance, true); } _last_stop_distance = _target.TargetStopDistance; _last_move_position = _move_position; } Gizmos.color = _target_color; if (_last_move_position != Vector3.zero) { CustomGizmos.OffsetPath(_last_move_position, _last_stop_distance, _interactor_pos, 0, false); } Gizmos.color = _default_color; //CustomGizmos.OffsetPath( _default_data.OffsetPosition, _default_data.StopDistance, _interactor_pos, 0 ); } } } }
private void DrawBehaviourModeRuleGizmos(TargetObject _target, BehaviourModeRuleObject _rule) { #if UNITY_EDITOR if (_target == null || _target.IsValid == false || _rule == null) { return; } Vector3 _owner_position = m_Owner.transform.position; Vector3 _target_pos = _target.TargetPosition; Vector3 _target_move_position = _target.TargetMovePosition; float _target_stop_distance = _target.TargetStopDistance; float _target_selection_range = _target.Selectors.SelectionRange; //float _target_selection_angle = _target.Selectors.SelectionAngle; DrawOwnerGizmos(); if (Application.isPlaying) { DrawPathGizmos(); DrawMoveGizmos(); } float _level = GetLevel(); _owner_position.y = _level; _target_pos.y = _level; _target_move_position.y = _level; if (_rule.Move.Type == MoveType.DEFAULT) { } else if (_rule.Move.Type == MoveType.AVOID) { MoveContainer _move = _rule.Move; //float _radius = _target_selection_range + 0.25f;// _move.Avoid.MaxAvoidDistance;//( _target_selection_range / 2 ) + 0.25f; //float _angle = _move.Avoid.MaxDirectionAngle; Gizmos.color = MoveAvoidColor; UnityEditor.Handles.color = Gizmos.color; //DrawDirectionAngle( m_Owner.transform, _radius, _angle ); //DrawDirectionAngle( _target.TargetGameObject.transform, _radius, _angle ); Vector3 _right = Vector3.Cross(_target.TargetGameObject.transform.up, _target.TargetGameObject.transform.forward); Vector3 _avoid_pos_right = _target_pos + (_right * _move.Avoid.AvoidDistance); Vector3 _avoid_pos_left = _target_pos + (_right * -_move.Avoid.AvoidDistance); CustomGizmos.OffsetPath(_target_pos, 0, _avoid_pos_right, _move.MoveStopDistance); CustomGizmos.DottedCircle(_avoid_pos_right, _move.MoveStopDistance, 5, 2); CustomGizmos.OffsetPath(_target_pos, 0, _avoid_pos_left, _move.MoveStopDistance); CustomGizmos.DottedCircle(_avoid_pos_left, _move.MoveStopDistance, 5, 2); if (Application.isPlaying) { /* * Gizmos.color = Color.blue; * Gizmos.DrawLine( _target_pos, CreatureControl.Creature.Move.AvoidMovePosition ); * Gizmos.color = Color.red; * Gizmos.DrawLine( _target_pos, CreatureControl.Creature.Move.MovePosition ); */ } } else if (_rule.Move.Type == MoveType.ESCAPE) { MoveContainer _move = _rule.Move; float _inner_radius = (_target_selection_range / 2) + 0.25f; float _outer_radius = _inner_radius + _rule.Move.MoveSegmentLength; float _outer_radius_max = _inner_radius + _rule.Move.MoveSegmentLengthMax; float _outer_radius_min = _inner_radius + _rule.Move.MoveSegmentLengthMin; float _inner_angle = 0; float _outer_angle = _inner_angle + _move.Escape.RandomEscapeAngle; Gizmos.color = MoveEscapeColor; Vector3 _left_inner_pos = Tools.GetDirectionPosition(_target.TargetGameObject.transform, -_inner_angle, _inner_radius); Vector3 _right_inner_pos = Tools.GetDirectionPosition(_target.TargetGameObject.transform, _inner_angle, _inner_radius); Vector3 _left_outer_pos = Tools.GetDirectionPosition(_target.TargetGameObject.transform, -_outer_angle, _outer_radius); Vector3 _right_outer_pos = Tools.GetDirectionPosition(_target.TargetGameObject.transform, _outer_angle, _outer_radius); _target_pos.y = _level; _left_inner_pos.y = _level; _right_inner_pos.y = _level; _left_outer_pos.y = _level; _right_outer_pos.y = _level; Gizmos.DrawLine(_target_pos, _left_inner_pos); Gizmos.DrawLine(_target_pos, _right_inner_pos); Gizmos.DrawLine(_left_inner_pos, _left_outer_pos); Gizmos.DrawLine(_right_inner_pos, _right_outer_pos); CustomGizmos.Arc(_target.TargetGameObject.transform, _inner_radius, 1, -_inner_angle, _inner_angle, _level, false); CustomGizmos.Arc(_target.TargetGameObject.transform, _outer_radius, 1, -_outer_angle, _outer_angle, _level, false); CustomGizmos.Arc(_target.TargetGameObject.transform, _outer_radius_min, 1, -_outer_angle, _outer_angle, _level, true); CustomGizmos.Arc(_target.TargetGameObject.transform, _outer_radius_max, 1, -_outer_angle, _outer_angle, _level, true); // DENGER ZONE BEGIN _inner_radius += 0.25f; float _degree = CustomGizmos.GetBestDegrees(_inner_radius, _inner_angle); CustomGizmos.ArrowArc(_target.TargetGameObject.transform, _inner_radius, _degree, -_inner_angle, _inner_angle, _level); Transform _target_transform = _target.TargetGameObject.transform; Vector3 _center = _target_transform.position; Vector3 _center_pos = Tools.GetDirectionPosition(_target_transform, 0, _inner_radius + (_inner_radius / 10)); Vector3 _left_pos = Tools.GetDirectionPosition(_target_transform, -_inner_angle, _inner_radius); Vector3 _right_pos = Tools.GetDirectionPosition(_target_transform, _inner_angle, _inner_radius); _center.y = _level; _center_pos.y = _level; _left_pos.y = _level; _right_pos.y = _level; Gizmos.DrawLine(_center, _center_pos); Gizmos.DrawLine(_center, _left_pos); Gizmos.DrawLine(_center, _right_pos); } else if (_rule.Move.Type == MoveType.ORBIT) { MoveContainer _move = _rule.Move; float _degrees = CreatureControl.Creature.Move.OrbitDegrees; float _radius = _move.Orbit.Radius; if (Application.isPlaying) { _move = CreatureControl.Creature.Move.CurrentMove; _radius = CreatureControl.Creature.Move.OrbitRadius; } Gizmos.color = MoveOrbitColor; CustomGizmos.Orbit(m_Owner.transform.position, _target_move_position, _radius, _degrees, _move.Orbit.RadiusShift, _move.Orbit.MinDistance, _move.Orbit.MaxDistance, _level); } else if (_rule.Move.Type == MoveType.DETOUR) { Vector3 _detour_pos = _rule.Move.Detour.Position; _detour_pos.y = _level; Gizmos.color = MoveDetourColor; CustomGizmos.OffsetPath(_detour_pos, _rule.Move.MoveStopDistance, _target_move_position, _target_stop_distance); CustomGizmos.Circle(_detour_pos, _rule.Move.MoveStopDistance, 5, false); // STOP DISTANCE RANGE //DrawMoveGizmos( Vector3 _initial_position, Vector3 _move_position, float _stop_distance, float _random_range, Vector3 _target_position, float _target_stop_distance ) } #endif }
/// <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); } } }