Exemplo n.º 1
0
        public override void OnCleanup()
        {
            holeIndex       = 0;
            teePlanting     = false;
            shotPlanting    = false;
            pinPlanting     = false;
            measurePlanting = false;
            flyByPlanting   = false;

            teePlanting    = false;
            teeType        = TeeBase.Info.Type.Championship;
            pinDifficulty  = PinBase.Info.Difficulty.Medium;
            teePar         = TeeBase.Info.Par._4;
            teeStrokeIndex = 0;
            teeWidth       = 0;
            teeHeight      = 0;
            flyByType      = FlyByBase.Info.Type.A;
            metersPerNode  = 30.0f;

            play  = false;
            pause = false;
            timer = new Timer();

            drawing       = false;
            points        = new Vector3[0];
            firstHit      = null;
            originalPoint = Vector3.zero;
            activeInfo    = null;
            if (CourseBase.Terrain)
            {
                CourseBase.ActivePlant = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates pin
        /// </summary>
        /// <param name="holeIndex"></param>
        /// <param name="difficulty"></param>
        /// <param name="position"></param>
        public static void CreatePin(int holeIndex, PinBase.Info.Difficulty difficulty, Vector3 position)
        {
            PinBase pin = (PinBase) new GameObject(GetPinName(holeIndex, FreePlantIndex(Pins, holeIndex), difficulty)).AddComponent(Types.GetType("PerfectParallel.CourseForge.Pin", "Assembly-CSharp"));

            pin.Position   = position;
            pin.Difficulty = difficulty;
            pin.HoleIndex  = holeIndex;
            pin.OrderIndex = FreePlantIndex(Pins, holeIndex);

            if (PlatformBase.IO.IsEditor)
            {
                PlatformBase.Editor.RegisterCreatedObjectUndo(pin.gameObject, "Plant tool Creation");
                pin.gameObject.hideFlags = HideFlags.HideInHierarchy;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get name for the pin
 /// </summary>
 /// <param name="holeIndex"></param>
 /// <param name="orderIndex"></param>
 /// <param name="difficulty"></param>
 /// <returns></returns>
 public static string GetPinName(int holeIndex, int orderIndex, PinBase.Info.Difficulty difficulty)
 {
     return("H" + (holeIndex + 1) + "\\" + difficulty + " " + (orderIndex + 1));
 }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
 PinBase.Info.Difficulty DifficultyField(PinBase.Info.Difficulty index, float xBoxes)
 {
     return((PinBase.Info.Difficulty)Popup("Difficulty", (int)index, System.Enum.GetNames(typeof(PinBase.Info.Difficulty)), xBoxes));
 }