public static void Update(SceneView view) { if (instance != null) { if (!EditorApplication.isPlaying && Event.current.capsLock && WaypointDebug.isCreatingPoints()) { if (Event.current.shift) { Debug.Log("STUFS!!!s"); } Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, WaypointSettings.getRange())) { float roundedX = Mathf.Round(hit.point.x * 1000) / 1000; float roundedY = Mathf.Round(hit.point.y * 1000) / 1000; float roundedZ = Mathf.Round(hit.point.z * 1000) / 1000; WaypointDebug.setCurrentLocation(new Vector3(roundedX, roundedY, roundedZ)); GetWindow(typeof(WaypointCreator)).Repaint(); } else { if (WaypointDebug.getCurrentLocation() != Vector3.zero) { WaypointDebug.setCurrentLocation(Vector3.zero); GetWindow(typeof(WaypointCreator)).Repaint(); } } } } }
void OnGUI() { if (instance == null) { instance = this; } GUILayout.Label("Settings", EditorStyles.boldLabel); range = EditorGUILayout.FloatField("Mouse Range", range); }
private static void OnScene(SceneView sceneview) { void BeginCentered(bool area) { if (area) { Handles.BeginGUI(); } if (area) { GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); } if (area) { GUILayout.Space(WaypointSettings.GetInstance().UiPosition == UIPosition.Top ? 5 : Screen.height - 100); } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } void EndCentered(bool area) { GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (area) { GUILayout.EndArea(); } if (area) { Handles.EndGUI(); } } if (Selection.activeObject != null) { if (Selection.activeObject.GetType() != typeof(GameObject)) { return; } var activeObject = Selection.activeGameObject; //non generic method is faster http://chaoscultgames.com/2014/03/unity3d-mythbusting-performance/ _wp = (Waypoint)activeObject.GetComponent(typeof(Waypoint)); _wps = (Runtime.WaypointSystem)activeObject.GetComponent(typeof(Runtime.WaypointSystem)); } //if no system or waypoint is selection if (_wp == null && _wps == null) { BeginCentered(true); if (GUILayout.Button("Create new waypoint sytem")) { //Get a point where to spawn the system Camera sceneCam = SceneView.currentDrawingSceneView.camera; Vector3 spawnPos = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f)); Runtime.WaypointSystem.Create(spawnPos); } EndCentered(true); return; } //if the system is selected if (_wps) { if (_wps.transform.childCount == 0) { _wps.AddNewWayPoint(); Selection.activeObject = _wp.gameObject; } _wp = _wps.StartingWaypoint; } var wpsParent = _wp.GetComponentInParent <WaypointSystem>(); HandleWaypointDeletion(); BeginCentered(true); if (GUILayout.Button("Insert (end)")) { wpsParent.AddNewWayPoint(); } if (GUILayout.Button("Insert (after)")) { var si = _wp.transform.GetSiblingIndex() + 1; wpsParent.AddNewWayPoint(si); } if (GUILayout.Button("Delete all")) { wpsParent.DeleteWaypoints(); } if (GUILayout.Button("Delete selected")) { var si = _wp.transform.GetSiblingIndex(); wpsParent.DeleteWaypoint(si); } if (GUILayout.Button("Delete system")) { wpsParent.DestroySystem(); } EndCentered(false); BeginCentered(false); if (wpsParent.LoopType == LoopType.Loop) { if (GUILayout.Button("Loop")) { wpsParent.SetLoopType(LoopType.PingPong); } } else if (wpsParent.LoopType == LoopType.PingPong) { if (GUILayout.Button("PingPong")) { wpsParent.SetLoopType(LoopType.OneWay); } } else { if (GUILayout.Button("One-way")) { wpsParent.SetLoopType(LoopType.Loop); } } if (GUILayout.Button("Reset waypoints to system default")) { wpsParent.ResetWaypointToDefaultsFromSystem(); } if (GUILayout.Button("Reset system to default")) { wpsParent.ResetSystemToDefault(); } EndCentered(true); }
void OnEnable() { instance = this; }
public static void ShowWindow() { //Show existing window instance. If one doesn't exist, make one. GetWindow(typeof(WaypointSettings), false, "TrafficSimAI"); instance = GetWindow <WaypointSettings>(); }