Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- namespace Core
- {
- namespace WaypointEditor
- {
- [CustomEditor(typeof(BasicPatrolState))]
- public class EnemyAIPathDrawer : Editor
- {
- BasicPatrolState m_AIcomponent;
- float size = 1f;
- int emptyobjectcounter;
- void OnEnable()
- {
- m_AIcomponent = (BasicPatrolState)target;
- }
- void OnSceneGUI()
- {
- Handles.color = Color.green;
- List<Transform> m_waypoints = m_AIcomponent.Path;
- if (m_waypoints.Count > 0)
- {
- for (int trwp = 0; trwp < m_waypoints.Count; trwp++)
- {
- if (m_waypoints[trwp] != null)
- {
- Handles.color = Color.black;
- Handles.Label(new Vector3(m_waypoints[trwp].transform.position.x + 0.5f, m_waypoints[trwp].transform.position.y
- , m_waypoints[trwp].transform.position.z + 1.5f), "P_" + trwp, new GUIStyle() { fontSize = 12 });
- Handles.color = Color.red;
- EditorGUI.BeginChangeCheck();
- Vector3 newposition = Handles.FreeMoveHandle(m_waypoints[trwp].transform.position, Quaternion.identity, size, Vector3.one * 0.5f, Handles.SphereHandleCap);
- if (EditorGUI.EndChangeCheck())
- {
- Undo.RecordObject(m_waypoints[trwp], "Change waypoint position");
- m_waypoints[trwp].transform.position = newposition;
- }
- }
- }
- Handles.color = Color.green;
- if (m_AIcomponent.LoopPath == true)
- {
- for (int wp = 1; wp < m_waypoints.Count + 1; wp++)
- {
- if (m_waypoints[wp - 1] != null)
- {
- Transform previouswaypoint = m_waypoints[wp - 1];
- Transform currentwaypoint = m_waypoints[wp % m_waypoints.Count];
- Handles.DrawLine(previouswaypoint.position, currentwaypoint.position);
- }
- }
- }
- else
- {
- for (int wp = 1; wp < m_waypoints.Count + 1; wp++)
- {
- if (m_waypoints[wp - 1] != null)
- {
- Transform previouswaypoint = m_waypoints[wp - 1];
- Transform currentwaypoint = m_waypoints[wp % m_waypoints.Count];
- if (wp != m_waypoints.Count)
- Handles.DrawLine(previouswaypoint.position, currentwaypoint.position);
- }
- }
- }
- }
- Handles.color = Color.white;
- HandleUtility.Repaint();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement