FlyByBase.Info.Node.Target TargetField(FlyByBase.Info.Node.Target target, FlyByBase.Info.Node node, float xBoxes) { target = (FlyByBase.Info.Node.Target)Popup("Target", (int)target, System.Enum.GetNames(typeof(FlyByBase.Info.Node.Target)), xBoxes); Move(1, 0); if (target == FlyByBase.Info.Node.Target.GameObject) { node.CameraTarget = (Transform)ObjectField(node.CameraTarget, 1, 0.6f); } Move(-1, 0); return(target); }
public override void OnUI(bool selected) { List <MeasureBase> measures = CourseBase.Measures; List <PinBase> pins = CourseBase.Pins; List <ShotBase> shots = CourseBase.Shots; List <TeeBase> tees = CourseBase.Tees; List <FlyByBase> flyBys = CourseBase.FlyBys; if (selected) { #region Delete if (CourseBase.ActivePlant != null && Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown) { Event.current.Use(); MonoBehaviour.DestroyImmediate(CourseBase.ActivePlant.Transform.gameObject); return; } #endregion if (CourseBase.ActivePlant != null) { BeginUI(); Move(3, 0); SetColor(Green); if (!(CourseBase.ActivePlant is MeasureBase)) { SetColor(Red); Popup("Hole", CourseBase.ActivePlant.HoleIndex, CourseBase.HoleNames, 1); SetColor(); Move(1, 0); } if (CourseBase.ActivePlant is TeeBase) { TeeBase tee = (CourseBase.ActivePlant as TeeBase); tee.Type = TeeTypeField(tee.Type, tee.HoleIndex, true, 2); Move(2, 0); tee.Par = ParField(tee.Par, 2); Move(2, 0); tee.StrokeIndex = StrokeIndexField(tee.HoleIndex, tee.Type, tee.StrokeIndex, true, 2); Move(2, 0); tee.TeeInfo.width = LengthSlider(tee.TeeInfo.width, "Width", 0.0f, 10, 0, 4); Move(4, 0); tee.TeeInfo.height = LengthSlider(tee.TeeInfo.height, "Height", 0.0f, 10, 0, 4); Move(4, 0); if (tee.TestLeft && tee.TestRight) { if (Button("Remove Marker", 4)) { if (tee.TestLeft != null) { MonoBehaviour.DestroyImmediate(tee.TestLeft); } if (tee.TestRight != null) { MonoBehaviour.DestroyImmediate(tee.TestRight); } } } else { if (Button("Test Tee Marker", 4)) { Vector3 forward = Vector3.right; if (CourseBase.Holes[tee.HoleIndex].pins.Count != 0) { forward = (CourseBase.AimPoint(tee.Position, tee, CourseBase.Holes[tee.HoleIndex].shots, CourseBase.Holes[tee.HoleIndex].pins[0]) - tee.Position).normalized; } forward.y = 0; Vector3 right = Vector3.Cross(forward, Vector3.up); Vector3 teePosition = tee.Position + forward * tee.Height / 2 * Random.insideUnitCircle.x + right * tee.Width / 2 * Random.insideUnitCircle.x; teePosition.y = CourseBase.MeshHeight(teePosition.x, teePosition.z); GameObject courseTeeMarker = CourseBase.GetTeeMarker(tee.Type); if (courseTeeMarker) { tee.TestLeft = (GameObject)GameObject.Instantiate(courseTeeMarker, teePosition - right * Utility.markerOffset, Quaternion.identity); tee.TestRight = (GameObject)GameObject.Instantiate(courseTeeMarker, teePosition + right * Utility.markerOffset, Quaternion.identity); tee.TestLeft.transform.forward = forward; tee.TestRight.transform.forward = forward; } } } Move(4, 0); } else if (CourseBase.ActivePlant is ShotBase) { } else if (CourseBase.ActivePlant is PinBase) { (CourseBase.ActivePlant as PinBase).Difficulty = DifficultyField((CourseBase.ActivePlant as PinBase).Difficulty, 2); Move(2, 0); } else if (CourseBase.ActivePlant is MeasureBase) { } else if (CourseBase.ActivePlant is FlyByBase) { FlyByBase flyby = (CourseBase.ActivePlant as FlyByBase); FlyByBase.Info.Node node = (activeInfo as FlyByBase.Info.Node); flyby.Type = FlyByTypeField(flyby.Type, flyby.HoleIndex, true, 1); Move(1, 0); if (node != null) { node.target = TargetField(node.target, node, 2); } Move(2, 0); node.velocity = VelocityField("Velocity", node.velocity, 15.0f, 3); Move(3, 0); node.RotationCurve = CurveField("Rotation Step", node.RotationCurve, AnimationCurve.Linear(0, 0, 1, 1), 3); Move(3, 0); FlyByBase flyBy = CourseBase.ActivePlant as FlyByBase; float originalTime = timer.Elapsed; float time = originalTime; VideoSlider(ref time, 3); Move(3, 0); if (node == (CourseBase.ActivePlant as FlyByBase).Nodes[0] || node == (CourseBase.ActivePlant as FlyByBase).Nodes[1] || node == (CourseBase.ActivePlant as FlyByBase).Nodes[2]) { SetColor(Green); node.position.Set(VectorField("Position", node.position.ToVector3(), 5)); Move(5, 0); SetColor(); } if (play) { if (time == timer.MaxTime) { time = 0; timer.Stop(); pause = false; play = false; } else if (time != originalTime) { timer.MoveToTime(time / timer.MaxTime); if (!pause) { timer.Resume(); } } HandleUtility.Repaint(); Camera.main.transform.position = (CourseBase.ActivePlant as FlyByBase).GetPosition(timer.Elapsed); Camera.main.transform.LookAt((CourseBase.ActivePlant as FlyByBase).GetTargetPosition(timer.Elapsed, Vector3.zero, Vector3.zero, Vector3.zero)); } else { if (time != originalTime) { play = true; pause = true; timer.Start((CourseBase.ActivePlant as FlyByBase).Time); timer.MoveToTime(time / timer.MaxTime); HandleUtility.Repaint(); } Camera.main.transform.position = node.position; Camera.main.transform.LookAt(node.TargetPosition(flyBy.HoleIndex, flyBy.Nodes, Vector3.zero, Vector3.zero, Vector3.zero)); } if (Event.current.type == EventType.Repaint && Camera.main) { Selection.activeTransform = Camera.main.transform; } } SetColor(); EndUI(); } else { BeginUI(); Move(3, 0); holeIndex = Popup("Hole", holeIndex, CourseBase.HoleNames, 1); Move(1, 0); TeeField(); Move(1, 0); if (teePlanting && CourseBase.FreeTees(holeIndex).Length == 0) { teePlanting = false; } if (teePlanting) { teeType = TeeTypeField(teeType, holeIndex, false, 2); Move(2, 0); teePar = ParField(teePar, 2); Move(2, 0); teeStrokeIndex = StrokeIndexField(holeIndex, teeType, teeStrokeIndex, false, 2); Move(2, 0); teeWidth = LengthSlider(teeWidth, "Width", 0.0f, 10, 0, 4); Move(4, 0); teeHeight = LengthSlider(teeHeight, "Height", 0.0f, 10, 0, 4); Move(4, 0); } ShotField(); Move(1, 0); PinField(); Move(1, 0); if (pinPlanting) { pinDifficulty = DifficultyField(pinDifficulty, 2); Move(2, 0); } MeasureField(); Move(1, 0); FlyByField(); Move(1, 0); if (flyByPlanting) { flyByType = FlyByTypeField(flyByType, holeIndex, false, 2); Move(2, 0); } SetColor(); EndUI(); } } #region UnClick if (activeInfo != null && LeftMouseUp && !(activeInfo is FlyByBase.Info.Node)) { Event.current.Use(); activeInfo = null; return; } #endregion if (selected) { for (int i = 0; i < pins.Count; ++i) { OnPlantUI(pins[i], pins[i].PlantInfo); } for (int i = 0; i < shots.Count; ++i) { OnPlantUI(shots[i], shots[i].PlantInfo); } for (int i = 0; i < tees.Count; ++i) { OnPlantUI(tees[i], tees[i].PlantInfo); } for (int i = 0; i < flyBys.Count; ++i) { for (int n = 0; n < flyBys[i].Nodes.Count; ++n) { OnFlyByUI(flyBys[i], flyBys[i].Nodes[n]); } } } for (int i = 0; i < measures.Count; ++i) { OnPlantUI(measures[i], measures[i].StartInfo); OnPlantUI(measures[i], measures[i].EndInfo); } if (selected) { OnMouse(); if (Event.current.type == EventType.Repaint) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.Arrow); } } if (CourseBase.ActivePlant != null && LeftMouseDown) { Event.current.Use(); CourseBase.ActivePlant = null; activeInfo = null; } }
void OnFlyByUI(IPlant plant, PlantBase.BaseInfo info) { FlyByBase flyBy = (plant as FlyByBase); FlyByBase.Info.Node infoNode = (info as FlyByBase.Info.Node); if (LeftMouseDown && IsMouseAround(info.position) || (infoNode.target == FlyByBase.Info.Node.Target.Probe && IsMouseAround(infoNode.probe.position))) { if (LeftDoubleClick) { if (Event.current.modifiers == EventModifiers.Shift) { if (flyBy.Nodes.Count > 3) { if (activeInfo == info) { CourseBase.ActivePlant = null; activeInfo = null; } flyBy.Nodes.Remove((FlyByBase.Info.Node)infoNode); flyBy.UpdateFlyBy(); Event.current.Use(); } } else { FlyByBase.Info.Node prev = info as FlyByBase.Info.Node; FlyByBase.Info.Node next = (info as FlyByBase.Info.Node).GetNext(flyBy.Nodes); FlyByBase.Info.Node node = new FlyByBase.Info.Node(); node.position = prev.position + (next.position.ToVector3() - prev.position) / 2; Vector3 right = Vector3.right; float distance = 3.0f; right = Vector3.Cross((next.position.ToVector3() - prev.position).normalized, Vector3.up); distance = (next.position.ToVector3() - prev.position).magnitude / 2; node.probe.position = node.position.ToVector3() + right * distance; flyBy.Nodes.Insert(flyBy.Nodes.IndexOf((FlyByBase.Info.Node)prev) + 1, (FlyByBase.Info.Node)node); flyBy.UpdateFlyBy(); Event.current.Use(); } return; } else if (activeInfo != info) { CourseBase.ActivePlant = plant; activeInfo = info; Event.current.Use(); } } if (info == activeInfo) { Vector3 delta = Vector3.zero; FlyByBase.Info.Node node = (info as FlyByBase.Info.Node); if (node.target == FlyByBase.Info.Node.Target.Probe) { delta = node.probe.position; node.probe.position = Handles.PositionHandle(node.probe.position, Quaternion.identity); delta -= node.probe.position; if (Event.current.modifiers == EventModifiers.Shift) { for (int i = 0; i < flyBy.Nodes.Count; ++i) { if (flyBy.Nodes[i].probe == info) { continue; } flyBy.Nodes[i].probe.position = flyBy.Nodes[i].probe.position - delta; } } } delta = info.position; info.position = Handles.PositionHandle(info.position.ToVector3(), Quaternion.identity); delta -= info.position; if (Event.current.modifiers == EventModifiers.Shift) { for (int i = 0; i < flyBy.Nodes.Count; ++i) { if (flyBy.Nodes[i] == info) { continue; } flyBy.Nodes[i].position = flyBy.Nodes[i].position.ToVector3() - delta; } } flyBy.UpdateFlyBy(); } }