public void CreatePegasusFromPath() { //Exit if nothing to do if (m_path.Count == 0) { return; } GameObject pegasusGo = new GameObject("Pegasus Manager"); PegasusManager pegasus = pegasusGo.AddComponent <PegasusManager>(); pegasus.SetDefaults(); pegasus.m_heightCheckType = PegasusConstants.HeightCheckType.None; pegasus.m_minHeightAboveTerrain = 0.1f; pegasus.m_flythroughType = PegasusConstants.FlythroughType.SingleShot; PegasusPoint p = null; for (int i = 0; i < m_path.Count; i++) { p = m_path[i]; pegasus.AddPOI(p.m_location, p.m_location + Quaternion.Euler(p.m_rotationEuler) * (Vector3.forward * 2f)); } pegasus.SetSpeed(m_defaultSpeed); #if UNITY_EDITOR Selection.activeObject = pegasusGo; #endif }
/// <summary> /// Detect and handle events for current spawner /// </summary> void OnSceneGUI() { //Exit if we dont have a manager if (m_manager == null) { return; } if (Event.current == null) { return; } if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint) { return; } //Scroll wheel - pan back and forward along the line if (Event.current.control == true && Event.current.type == EventType.scrollWheel) { GUIUtility.hotControl = m_editor_control_id; if (Event.current.delta.y < 0f) { m_manager.StepTargetBackward(Event.current.delta.y * -1f); } else { m_manager.StepTargetForward(Event.current.delta.y); } Event.current.Use(); GUIUtility.hotControl = 0; return; } //Check for the ctrl + left mouse button event - spawn if (Event.current.control == true && Event.current.isMouse == true) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { GUIUtility.hotControl = m_editor_control_id; Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 10000f)) { if (m_manager.m_poiList.Count == 0) { if (!(hitInfo.collider is TerrainCollider)) //Lets assume we arent in an environment that uses terrains { m_manager.m_heightCheckType = PegasusConstants.HeightCheckType.Collision; } } Vector3 newPoint = m_manager.GetValidatedPoiPosition(hitInfo.point); if (newPoint != m_lastHitPoint) { m_lastHitPoint = newPoint; m_manager.AddPOI(m_lastHitPoint, m_lastHitPoint); } } else { if (SceneView.lastActiveSceneView != null) { float dist = Vector3.Distance(ray.origin, SceneView.lastActiveSceneView.pivot); m_lastHitPoint = Vector3.MoveTowards(ray.origin, SceneView.lastActiveSceneView.pivot, dist / 2f); } else { m_lastHitPoint = ray.origin; } if (m_manager.m_poiList.Count == 0) //Lets assume we are in space { m_manager.m_heightCheckType = PegasusConstants.HeightCheckType.None; } m_manager.AddPOI(m_lastHitPoint, m_lastHitPoint); } SceneView.RepaintAll(); } else if (GUIUtility.hotControl == m_editor_control_id && Event.current.type == EventType.MouseUp && Event.current.button == 0) { GUIUtility.hotControl = 0; } return; } }