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
        FlyByBase.Info.Type FlyByTypeField(FlyByBase.Info.Type index, int holeIndex, bool add, float xBoxes)
        {
            string[] names     = CourseBase.FreeFlyBys(holeIndex);
            string   indexName = index.ToString();

            if (!ArrayUtility.Contains(names, indexName))
            {
                if (add)
                {
                    ArrayUtility.Add(ref names, indexName);

                    string[] newNames = System.Enum.GetNames(typeof(FlyByBase.Info.Type));
                    for (int i = 0; i < newNames.Length; ++i)
                    {
                        if (!ArrayUtility.Contains(names, newNames[i]))
                        {
                            ArrayUtility.RemoveAt(ref newNames, i);
                            i = -1;
                            continue;
                        }
                    }
                    names = newNames;
                }
                else
                {
                    string[] newNames = System.Enum.GetNames(typeof(FlyByBase.Info.Type));
                    for (int i = 0; i < newNames.Length; ++i)
                    {
                        if (!ArrayUtility.Contains(names, newNames[i]))
                        {
                            ArrayUtility.RemoveAt(ref newNames, i);
                            i = -1;
                            continue;
                        }
                    }
                    names     = newNames;
                    indexName = names[0];
                }
            }

            int namesIndex = ArrayUtility.IndexOf(names, indexName);

            namesIndex = Popup("Label", namesIndex, names, xBoxes);
            return((FlyByBase.Info.Type)System.Enum.Parse(typeof(FlyByBase.Info.Type), names[namesIndex]));
        }
Example #3
0
        /// <summary>
        /// Creates flyby
        /// </summary>
        /// <param name="holeIndex"></param>
        /// <param name="points"></param>
        /// <param name="type"></param>
        public static void CreateFlyBy(int holeIndex, Vector3[] points, FlyByBase.Info.Type type)
        {
            FlyByBase flyBy = (FlyByBase) new GameObject(GetFlyByName(holeIndex, FreePlantIndex(FlyBys, holeIndex), type)).AddComponent(Types.GetType("PerfectParallel.CourseForge.FlyBy", "Assembly-CSharp"));

            flyBy.HoleIndex  = holeIndex;
            flyBy.OrderIndex = FreePlantIndex(FlyBys, holeIndex);
            flyBy.Type       = type;

            List <FlyByBase.Info.Node> nodes = new List <FlyByBase.Info.Node>();

            for (int i = 0; i < points.Length; ++i)
            {
                FlyByBase.Info.Node node = new FlyByBase.Info.Node();
                node.position.Set(points[i]);

                Vector3 right    = Vector3.right;
                float   distance = 3.0f;

                if (i != points.Length - 1)
                {
                    right    = Vector3.Cross((points[i + 1] - points[i]).normalized, Vector3.up);
                    distance = (points[i + 1] - points[i]).magnitude / 2;
                }

                node.probe.position.Set(node.position.ToVector3() + right * distance);
                nodes.Add(node);
            }

            (flyBy.PlantInfo as FlyByBase.Info).nodes = nodes;
            (flyBy.PlantInfo as FlyByBase.Info).UpdatePoints();

            if (PlatformBase.IO.IsEditor)
            {
                PlatformBase.Editor.RegisterCreatedObjectUndo(flyBy.gameObject, "Plant tool Creation");
                flyBy.gameObject.hideFlags = HideFlags.HideInHierarchy;
            }
        }
Example #4
0
 /// <summary>
 /// Get name for the flyby
 /// </summary>
 /// <param name="holeIndex"></param>
 /// <param name="orderIndex"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string GetFlyByName(int holeIndex, int orderIndex, FlyByBase.Info.Type type)
 {
     return("H" + (holeIndex + 1) + "\\FlyBy " + (orderIndex + 1) + type.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;
            }
        }