Example #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;
            }
        }
Example #2
0
        TeeBase.Info.Par ParField(TeeBase.Info.Par par, float xBoxes)
        {
            string[] names = System.Enum.GetNames(typeof(TeeBase.Info.Par));
            for (int i = 0; i < names.Length; ++i)
            {
                names[i] = names[i].Replace("_", "");
            }

            return((TeeBase.Info.Par)Popup("Par", (int)par, names, xBoxes));
        }
Example #3
0
        /// <summary>
        /// Creates tee
        /// </summary>
        /// <param name="holeIndex"></param>
        /// <param name="type"></param>
        /// <param name="par"></param>
        /// <param name="strokeIndex"></param>
        /// <param name="width">random box width</param>
        /// <param name="height">random box height</param>
        public static void CreateTee(int holeIndex, TeeBase.Info.Type type, TeeBase.Info.Par par, int strokeIndex, float width, float height)
        {
            TeeBase tee = (TeeBase) new GameObject(GetTeeName(holeIndex, type, par, strokeIndex)).AddComponent(Types.GetType("PerfectParallel.CourseForge.Tee", "Assembly-CSharp"));

            tee.Position    = CameraTerrainHit.Value.point;
            tee.Type        = type;
            tee.Par         = par;
            tee.StrokeIndex = strokeIndex;
            tee.Width       = width;
            tee.Height      = height;
            tee.HoleIndex   = holeIndex;
            tee.OrderIndex  = FreePlantIndex(Tees, holeIndex);

            if (PlatformBase.IO.IsEditor)
            {
                PlatformBase.Editor.RegisterCreatedObjectUndo(tee.gameObject, "Plant tool Creation");
                tee.gameObject.hideFlags = HideFlags.HideInHierarchy;
            }
        }
Example #4
0
 /// Get name for the tee
 /// </summary>
 /// <param name="holeIndex"></param>
 /// <param name="type"></param>
 /// <param name="par"></param>
 /// <param name="strokeIndex"></param>
 /// <returns></returns>
 public static string GetTeeName(int holeIndex, TeeBase.Info.Type type, TeeBase.Info.Par par, int strokeIndex)
 {
     return("H" + (holeIndex + 1) + "\\" + type.ToString() + " PAR" + par.ToString().Replace("_", "") + " S" + strokeIndex.ToString());
 }
Example #5
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;
            }
        }