Exemple #1
0
        void OnSceneTees(bool selected)
        {
            List <TeeBase> tees = CourseBase.Tees;

            for (int i = 0; i < tees.Count; ++i)
            {
                Color color = new Color(0.15f, 0.75f, 0.15f);

                if (CourseBase.ActivePlant is TeeBase && tees[i] == (TeeBase)CourseBase.ActivePlant)
                {
                    color = White;
                }

                Vector3 forward = Vector3.right;
                if (CourseBase.Holes[tees[i].HoleIndex].pins.Count != 0)
                {
                    forward = (CourseBase.AimPoint(tees[i].Position, tees[i], CourseBase.Holes[tees[i].HoleIndex].shots, CourseBase.Holes[tees[i].HoleIndex].pins[0]) - tees[i].Position).normalized;
                }
                forward.y = 0;

                LineToolUI.DrawTee(tees[i].Position, color);

                if (selected)
                {
                    LineToolUI.DrawBox(tees[i].Position, Black, tees[i].Height, tees[i].Width + Utility.markerOffset * 2, forward);

                    if (tees[i].PlantInfo == activeInfo)
                    {
                        LineToolUI.DrawBox(tees[i].Position, Red);
                        LineToolUI.DrawBox(tees[i].Position, Red, tees[i].Height, tees[i].Width, forward);
                    }
                    else if (IsMouseAround(tees[i].Position))
                    {
                        LineToolUI.DrawBox(tees[i].Position, Yellow);
                        LineToolUI.DrawBox(tees[i].Position, Yellow, tees[i].Height, tees[i].Width, forward);
                    }

                    if (IsPointOnScreen(tees[i].Position))
                    {
                        string text = CourseBase.GetTeeName(tees[i].HoleIndex, tees[i].Type, tees[i].Par, tees[i].StrokeIndex);
                        tees[i].gameObject.name = text;

                        Rect rect = ProjectToScreenRect(tees[i].Position, 16, 16);
                        rect.width = GUI.skin.label.CalcSize(new GUIContent(text)).x;
                        rect.x    -= rect.width / 4;

                        BeginUI();
                        MoveToPixels((int)rect.x, (int)rect.y);
                        SetBoxSize((int)rect.width, (int)rect.height);
                        Background(1, 1, 0.5f);
                        LabelNoOffset(text);
                        EndUI();
                    }
                }
            }
        }
Exemple #2
0
        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;
            }
        }