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 }
/// <summary> /// Draws the target gizmos. /// </summary> /// <param name="_target">_target.</param> private void DrawTargetGizmos(TargetObject _target, Color _target_color, Color _selection_color) { #if UNITY_EDITOR if (_target == null || _target.IsValid == false) { return; } Vector3 _target_pos = _target.TargetPosition; Vector3 _target_direction = _target.TargetDirection; Vector3 _target_pos_offset = _target.TargetOffsetPosition; Vector3 _target_pos_move = _target.TargetMovePosition; float _target_selection_distance = _target.Selectors.SelectionRange; float _target_selection_angle = _target.Selectors.SelectionAngle; Vector3 _target_pos_top = _target_pos; Vector3 _target_pos_bottom = _target_pos; float _level = GetLevel(); _target_pos.y = GetLevel(); _target_pos_offset.y = GetLevel(); _target_pos_move.y = GetLevel(); _target_pos_top.y = GetLevel() + 3; _target_pos_bottom.y = 0; Color _previous_color = Gizmos.color; Gizmos.color = _target_color; UnityEditor.Handles.color = _target_color; // SELECTION RANGE BEGIN /*if( ShowSolidInteractionRange && SolidInteractionAlpha > 0 ) * { * UnityEditor.Handles.color = _selection_color; * UnityEditor.Handles.DrawWireDisc( _target_pos , Vector3.up, _target_selection_distance ); * * Color _selection_color_transparent = _selection_color; * _selection_color_transparent.a = SolidInteractionAlpha; * UnityEditor.Handles.color = _selection_color_transparent; * UnityEditor.Handles.DrawSolidDisc( _target_pos , Vector3.up, _target_selection_distance ); * } * else * { * UnityEditor.Handles.color = _selection_color; * UnityEditor.Handles.DrawWireDisc( _target_pos , Vector3.up, _target_selection_distance ); * }*/ //if( _target_selection_angle > 0 && _target_selection_angle <= 180 ) { if (_target_selection_angle == 0) { _target_selection_angle = 180; } CustomGizmos.ArrowArc(_target.TargetGameObject.transform, _target_selection_distance, CustomGizmos.GetBestDegrees(_target_selection_distance, _target_selection_angle), -_target_selection_angle, _target_selection_angle, _level, true); if (_target_selection_angle < 180) { Transform _target_transform = _target.TargetGameObject.transform; Vector3 _center = _target_transform.position; Vector3 _center_pos = Tools.GetDirectionPosition(_target_transform, 0, _target_selection_distance + (_target_selection_distance / 10)); Vector3 _left_pos = Tools.GetDirectionPosition(_target_transform, -_target_selection_angle, _target_selection_distance - 0.25f); Vector3 _right_pos = Tools.GetDirectionPosition(_target_transform, _target_selection_angle, _target_selection_distance - 0.25f); _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); /**/ } } // SELECTION RANGE END // TARGET ICON BEGIN Gizmos.DrawLine(_target_pos_bottom, _target_pos_top); Gizmos.DrawIcon(_target_pos_top, "ice_waypoint.png"); // TARGET ICON END // TARGET STOP DISTANCE BEGIN if (_target.TargetIgnoreLevelDifference) { CustomGizmos.Circle(_target_pos_move, _target.TargetStopDistance, 5, false); // IGNORES LEVEL DIFFERNCE SO WE DRAW JUST A CIRCLE } else { Gizmos.DrawWireSphere(_target_pos_move, _target.TargetStopDistance); // IF THE LEVEL IS IMPORTANT FOR THE STOP DISTANCE WE DRAW A SPHERE } // TARGET STOP DISTANCE END // MAX AND RANDOM RANGE BEGIN CustomGizmos.Circle(_target_pos_offset, _target.TargetRandomRange, 5, false); // RANDOM RANGE CustomGizmos.Circle(_target_pos_offset, _target.TargetRandomRange + _target.TargetStopDistance, 5, true); // MAX RANGE // MAX AND RANDOM RANGE END // SPECIAL CASES FOR INTERACTOR WHICH COULD HAVE SEVERAL SELECTION RANGES if (_target.Type != TargetType.INTERACTOR) { if (Vector3.Distance(_target_pos_move, _target_pos_offset) <= _target.TargetStopDistance) { CustomGizmos.OffsetPath(_target_pos, 0.0f, _target_pos_offset, _target.TargetStopDistance); } else { Gizmos.DrawLine(_target_pos, _target_pos_offset); } CustomGizmos.OffsetPath(_target_pos_offset, 0.0f, _target_pos_move, _target.TargetStopDistance); // DIRECTION CustomGizmos.Arrow(_target_pos, _target_direction * _target.TargetStopDistance, 0.5f, 20); } BehaviourModeObject _mode = CreatureControl.Creature.Behaviour.GetBehaviourModeByKey(_target.BehaviourModeKey); DrawBehaviourModeGizmos(_target, _mode); // PRIVIOUS COLOR Gizmos.color = _previous_color; UnityEditor.Handles.color = _previous_color; #endif } } /// <summary> /// Pointer object. /// </summary> [System.Serializable] public class PathObject : System.Object { public void NavMeshPath(NavMeshAgent _agent) { /* * GameObject _object = new GameObject(); * _object.transform.parent = _agent.gameObject.transform; * LineRenderer _line = _object.AddComponent<LineRenderer>(); * _line.SetColors(Color.white,Color.white); * _line.SetWidth(0.1f,0.1f); * //Get def material * * _line.gameObject.renderer.material.color = Color.white; * _line.gameObject.renderer.material.shader = Shader.Find("Sprites/Default"); * _line.gameObject.AddComponent<LineScript>(); * _line.SetVertexCount(_agent.path.corners.Length+1); * int i = 0; * foreach(Vector3 v in p.corners) * { * _line.SetPosition(i,v); * //Debug.Log("position agent"+g.transform.position); * //Debug.Log("position corner = "+v); * i++; * } * _line.SetPosition(p.corners.Length,_agent.destination); * _line.gameObject.tag = "ligne";*/ } }
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 }