Exemple #1
0
        static void AddPoint(SplineBase spline)
        {
            Vector3[] points     = spline.Points;
            string[]  colorNames = spline.Info.colorNames;
            int       i          = spline.ActivePoint;

            if (spline.IsHazard)
            {
                ArrayUtility.Insert(ref colorNames, i, colorNames[i]);
            }
            if (i != 0)
            {
                ArrayUtility.Insert(ref points, i, Vector3.Lerp(points[i], points[i - 1], 0.5f));
                points[i].y     = CourseBase.TerrainHeight(points[i].x, points[i].z);
                points[i - 1].y = CourseBase.TerrainHeight(points[i - 1].x, points[i - 1].z);
            }
            else
            {
                ArrayUtility.Insert(ref points, i, Vector3.Lerp(points[i], points[points.Length - 1], 0.5f));
                points[i].y = CourseBase.TerrainHeight(points[i].x, points[i].z);
                points[points.Length - 1].y = CourseBase.TerrainHeight(points[points.Length - 1].x, points[points.Length - 1].z);
            }

            spline.Points          = points;
            spline.Info.colorNames = colorNames;
            spline.UpdateLine();
            spline.LineChanged();
        }
Exemple #2
0
        void OnPlantUI(IPlant plant, PlantBase.BaseInfo info)
        {
            if (activeInfo != info && LeftMouseDown && IsMouseAround(info.position.ToVector3()))
            {
                Event.current.Use();

                CourseBase.ActivePlant = plant;
                activeInfo             = info;
                firstHit      = CourseBase.CameraTerrainHit;
                originalPoint = info.position.ToVector3();

                if (MainToolUI.SelectedTool != MainToolUI.Tool.PlantTool)
                {
                    MainToolUI.SelectedTool = MainToolUI.Tool.PlantTool;
                }
                return;
            }
            if (info == activeInfo)
            {
                RaycastHit?hit = CourseBase.CameraTerrainHit;
                if (firstHit != null && hit != null)
                {
                    PlatformBase.Editor.RecordObject(plant.Transform.gameObject, "Plant Info Position Change");

                    Vector3 position = (originalPoint + hit.Value.point - firstHit.Value.point);
                    position.y = CourseBase.TerrainHeight(position.x, position.z);

                    plant.Position = position;
                    info.position.Set(position);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Do export step
        /// </summary>
        public static void DoExportTerrainStep()
        {
            if (!exporting)
            {
                return;
            }

            heights[indexX] = CourseBase.MeshLevel(x, z) + CourseBase.Info.geoZ;
            indexX++;


            if (indexX == countX)
            {
                indexX = 0;
                x      = 0;

                byte[] bytes = new byte[heights.Length * sizeof(float)];
                Buffer.BlockCopy(heights, 0, bytes, 0, bytes.Length);

                PlatformBase.IO.AppendBytes(path, bytes);

                z -= step;
                indexY--;
                if (indexY == -1)
                {
                    exporting = false;
                }
            }
            else
            {
                x += step;
            }
        }
Exemple #4
0
 void OnAutoTerrain()
 {
     if (CourseBase.TerrainSelected && CourseBase.TerrainLowered)
     {
         CourseBase.RestoreTerrain();
     }
 }
        public static void Main()
        {
            CurrentPath = SetPath;
            var                dex      = new CreateFullTimeStudent();
            StudentBase        st       = dex.CreateStudent("Rick", new[] { "020" });
            StudentBase        st1      = dex.CreateStudent("Alex", new[] { "6", "9" });
            var                deg      = new CreatePartTimeStudent();
            StudentBase        st2      = deg.CreateStudent("Nick", new[] { "4", "5" });
            List <StudentBase> students = new List <StudentBase> {
                st, st1, st2
            };

            Serialize(students);
            var               c       = new CreateTechCourse();
            CourseBase        co      = c.CreateCourse("Math", new[] { "0" }, new[] { "001", "002" });
            CourseBase        co1     = c.CreateCourse("CS", new[] { "0" }, new[] { "001", "002" });
            List <CourseBase> courses = new List <CourseBase> {
                co, co1
            };

            Serialize(courses);
            var                n        = new CreateFullTimeTeacher();
            TeacherBase        t        = n.CreateTeacher("K", 5, new[] { "001", "002" });
            var                q        = new CreatePartTimeTeacher();
            TeacherBase        t1       = q.CreateTeacher("gfgd", 5, new[] { "009", "005" });
            List <TeacherBase> teachers = new List <TeacherBase> {
                t, t1
            };

            Serialize(teachers);
            Console.ReadKey();
        }
Exemple #6
0
 public static CourseBase Instance() //Singleton
 {
     if (_instance == null)
     {
         _instance = new CourseBase();
     }
     return(_instance);
 }
Exemple #7
0
        void OnScenePins(bool selected)
        {
            List <PinBase> pins = CourseBase.Pins;

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

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

                LineToolUI.DrawPin(pins[i].Position, color);

                if (selected)
                {
                    if (pins[i].PlantInfo == activeInfo)
                    {
                        LineToolUI.DrawBox(pins[i].Position, Red);

                        RaycastHit hit = CourseBase.TerrainHit(pins[i].Position.x, pins[i].Position.z).Value;

                        Vector3 right = Vector3.Cross(Vector3.Cross(Vector3.up, hit.normal).normalized, hit.normal).normalized;
                        float   angle = Vector3.Angle(new Vector3(hit.normal.x, 0, hit.normal.z).normalized, right);
                        if (angle > 10)
                        {
                            angle = 10;
                        }

                        LineToolUI.DrawLine(new Vector3(pins[i].Position.x, pins[i].Position.y + 0.02f, pins[i].Position.z), new Vector3(pins[i].Position.x, pins[i].Position.y + 0.02f, pins[i].Position.z) + right * Mathf.Lerp(0, 1, angle / 10), Black);
                    }
                    else if (IsMouseAround(pins[i].Position))
                    {
                        LineToolUI.DrawBox(pins[i].Position, Yellow);
                    }

                    if (IsPointOnScreen(pins[i].Position))
                    {
                        string text = CourseBase.GetPinName(pins[i].HoleIndex, pins[i].OrderIndex, pins[i].Difficulty);
                        pins[i].gameObject.name = text;

                        Rect rect = ProjectToScreenRect(pins[i].Position + Vector3.up * 1.8f, 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 #8
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();
                    }
                }
            }
        }
        private static CourseBase PrereqsMapCourse(IDataReader reader)
        {
            CourseBase item          = new CourseBase();
            int        startingIndex = 0;

            item.Id         = reader.GetSafeInt32(startingIndex++);
            item.CourseName = reader.GetSafeString(startingIndex++);

            return(item);
        }
Exemple #10
0
        public static void EnablePerform()
        {
            EditorApplication.ExecuteMenuItem("GameObject/Hidden/Course Forge/Platform/Initialize");
            ToolUI.Initialize();

            if (CourseBase.Initialize())
            {
                instance  = new MainToolUI();
                initScene = EditorApplication.currentScene;

                SceneView.onSceneGUIDelegate  = null;
                SceneView.onSceneGUIDelegate += OnScene;
            }
        }
Exemple #11
0
        TeeBase.Info.Type TeeTypeField(TeeBase.Info.Type index, int holeIndex, bool add, float xBoxes)
        {
            string[] names     = CourseBase.FreeTees(holeIndex);
            string   indexName = index.ToString();

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

                    string[] newNames = System.Enum.GetNames(typeof(TeeBase.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(TeeBase.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("Type", namesIndex, names, xBoxes);
            index      = (TeeBase.Info.Type)System.Enum.Parse(typeof(TeeBase.Info.Type), names[namesIndex]);

            return(index);
            //return Iloveyou;
        }
        public Course Get(int id)
        {
            Course course = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Courses_SelectByIdV2",
                                    inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    course = MapCourse(reader);
                }
                else if (set == 1)
                {
                    CourseTag ct = TagMapCourse(reader);
                    if (course.Tags == null)
                    {
                        course.Tags = new List <CourseTag>();
                    }
                    course.Tags.Add(ct);
                }

                else if (set == 2)
                {
                    CourseInstructors imc = InstructorsMapCourse(reader);
                    if (course.Instructors == null)
                    {
                        course.Instructors = new List <CourseInstructors>();
                    }
                    course.Instructors.Add(imc);
                }

                else if (set == 3)
                {
                    CourseBase bc = PrereqsMapCourse(reader);
                    if (course.Prereqs == null)
                    {
                        course.Prereqs = new List <CourseBase>();
                    }
                    course.Prereqs.Add(bc);
                }
            });
            return(course);
        }
Exemple #13
0
        void OnSceneShots(bool selected)
        {
            List <ShotBase> shots = CourseBase.Shots;

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

                if (CourseBase.ActivePlant is ShotBase && shots[i] == (ShotBase)CourseBase.ActivePlant)
                {
                    color = Color.white;
                }

                LineToolUI.DrawShot(shots[i].Position, color);

                if (selected)
                {
                    if (shots[i].PlantInfo == activeInfo)
                    {
                        LineToolUI.DrawBox(shots[i].Position, Red);
                    }
                    else if (IsMouseAround(shots[i].Position))
                    {
                        LineToolUI.DrawBox(shots[i].Position, Yellow);
                    }

                    if (IsPointOnScreen(shots[i].Position))
                    {
                        string text = CourseBase.GetShotName(shots[i].HoleIndex, shots[i].OrderIndex);
                        shots[i].gameObject.name = text;

                        Rect rect = ProjectToScreenRect(shots[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 #14
0
        public Instructors GetInstructors(int id)
        {
            Instructors item = null;

            CourseBase bc = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Instructors_SelectByIdV2"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
                //model binding
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    item = new Instructors();
                    int startingIndex = 0;     // startingOrdinal

                    item.Id            = reader.GetSafeInt32(startingIndex++);
                    item.Name          = reader.GetSafeString(startingIndex++);
                    item.Email         = reader.GetSafeString(startingIndex++);
                    item.Bio           = reader.GetSafeString(startingIndex++);
                    item.LinkedIn      = reader.GetSafeString(startingIndex++);
                    item.CoursesTaught = reader.GetSafeString(startingIndex++);
                    //bc.Id = reader.GetSafeInt32(startingIndex++);
                    //bc.CourseName = reader.GetSafeString(startingIndex++);
                }
                else if (set == 1)
                {
                    bc = new CourseBase();
                    int startingIndex = 0;

                    bc.Id         = reader.GetSafeInt32(startingIndex++);
                    bc.CourseName = reader.GetSafeString(startingIndex++);

                    if (item.Courses == null)
                    {
                        item.Courses = new List <CourseBase>();
                    }
                    item.Courses.Add(bc);
                }
            }
                                    );
            return(item);
        }
Exemple #15
0
        int StrokeIndexField(int holeIndex, TeeBase.Info.Type teeType, int index, bool add, float xBoxes)
        {
            string[] names     = CourseBase.FreeTeesStrokeIndex(holeIndex, teeType);
            string   indexName = index.ToString();

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

                    string[] newNames = CourseBase.HoleNames;
                    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
                {
                    indexName = names[0];
                }
            }

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

            namesIndex = Popup("StrokeIndex", namesIndex, names, xBoxes);
            if (namesIndex >= 0)
            {
                int.TryParse(names[namesIndex], out index);
            }

            return(index);
        }
Exemple #16
0
        void HazardField()
        {
            Background();

            if (HazardDrawing)
            {
                SetColor(Green);
            }
            if (Button(brushTexture))
            {
                HazardDrawing = !HazardDrawing;
                if (HazardDrawing && SplineDrawing)
                {
                    SplineDrawing = false;
                    if (CourseBase.HazardLayers.Count != 0)
                    {
                        LayerName = CourseBase.GetLayer("NoLayerName", CourseBase.HazardLayers).name;
                    }
                }
            }
            SetColor();
        }
Exemple #17
0
        void SplineField()
        {
            Background();

            if (SplineDrawing)
            {
                SetColor(Green);
            }
            if (Button(pencilTexture))
            {
                SplineDrawing = !SplineDrawing;
                if (SplineDrawing && HazardDrawing)
                {
                    HazardDrawing = false;
                    if (CourseBase.SplineLayers.Count != 0)
                    {
                        LayerName = CourseBase.GetLayer("NoLayerName", CourseBase.SplineLayers).name;
                    }
                }
            }
            SetColor();
        }
Exemple #18
0
        void FlyByField()
        {
            Background();

            if (flyByPlanting)
            {
                SetColor(Green);
            }
            if (Button(flyByTexture))
            {
                teePlanting     = false;
                shotPlanting    = false;
                pinPlanting     = false;
                measurePlanting = false;
                flyByPlanting   = !flyByPlanting;

                if (flyByPlanting && CourseBase.FreeFlyBys(holeIndex).Length == 0)
                {
                    flyByPlanting = false;
                }
            }
            SetColor();
        }
Exemple #19
0
        void TeeField()
        {
            Background();

            if (teePlanting)
            {
                SetColor(Green);
            }
            if (Button(teeTexture))
            {
                teePlanting = !teePlanting;
                if (CourseBase.FreeTees(holeIndex).Length == 0)
                {
                    teePlanting = false;
                }

                shotPlanting    = false;
                pinPlanting     = false;
                measurePlanting = false;
                flyByPlanting   = false;
            }
            SetColor();
        }
        private Section MapSection(IDataReader reader)
        {
            Section sec           = new Section();
            int     startingIndex = 0;

            sec.Id                   = reader.GetSafeInt32(startingIndex++);
            sec.CourseId             = reader.GetSafeInt32(startingIndex++);
            sec.DaysOfWeek           = reader.GetSafeInt32(startingIndex++);
            sec.StartDate            = reader.GetSafeDateTime(startingIndex++);
            sec.EndDate              = reader.GetSafeDateTime(startingIndex++);
            sec.RegistrationDeadline = reader.GetSafeDateTime(startingIndex++);
            sec.StartTime            = reader.GetSafeInt32(startingIndex++);
            sec.EndTime              = reader.GetSafeInt32(startingIndex++);
            sec.TimeZone             = reader.GetSafeInt32(startingIndex++);
            sec.Info                 = reader.GetSafeString(startingIndex++);
            sec.Format               = reader.GetSafeInt32(startingIndex++);
            sec.CampusLocation       = reader.GetSafeInt32(startingIndex++);
            sec.RoomNumber           = reader.GetSafeString(startingIndex++);
            sec.Capacity             = reader.GetSafeInt32(startingIndex++);
            sec.CurrentEnrollment    = reader.GetSafeInt32(startingIndex++);
            sec.Status               = reader.GetSafeInt32(startingIndex++);
            sec.Name                 = reader.GetSafeString(startingIndex++);
            CourseBase cb = new CourseBase();

            cb.Id         = reader.GetSafeInt32(startingIndex++);
            cb.CourseName = reader.GetSafeString(startingIndex++);
            sec.Course    = cb;
            Campus campus = new Campus();

            campus.Id   = reader.GetSafeInt32(startingIndex++);
            campus.Name = reader.GetSafeString(startingIndex++);
            sec.Campus  = campus;


            return(sec);
        }
Exemple #21
0
        /// <summary>
        /// Import splines from file
        /// </summary>
        /// <param name="path"></param>
        public static void ImportSplines(string path)
        {
            try
            {
                File file = Utility.JsonRead <File>(PlatformBase.IO.ReadText(path));
                for (int i = 0; i < file.features.Count; ++i)
                {
                    File.Feature feature = file.features[i];
                    if (feature.geometry.type == "Polygon" && feature.geometry.coordinates.GetType() == typeof(Double[][][]))
                    {
                        Double[][][] coordinates = (Double[][][])feature.geometry.coordinates;

                        for (int p = 0; p < coordinates.Length; ++p)
                        {
                            List <Vector3> poly = new List <Vector3>();
                            for (int t = 0; t < coordinates[p].Length; ++t)
                            {
                                poly.Add(new Vector3((float)coordinates[p][t][0] - CourseBase.Info.geoX, 0, (float)coordinates[p][t][1] - CourseBase.Info.geoY));
                            }

                            for (int t = 0; t < poly.Count; ++t)
                            {
                                poly[t] = new Vector3(poly[t].x, CourseBase.TerrainHeight(poly[t].x, poly[t].z), poly[t].z);
                            }

                            if (CourseBase.IsHazard(file.features[i].properties.Layer))
                            {
                                CourseBase.CreateHazard(poly.ToArray(), CourseBase.GetLayer(file.features[i].properties.Layer, CourseBase.HazardLayers), 0, true);
                            }
                            else
                            {
                                CourseBase.CreateSpline(poly.ToArray(), CourseBase.GetLayer(file.features[i].properties.Layer, CourseBase.SplineLayers), 0, true);
                            }
                        }
                    }
                    else if (feature.geometry.type == "Polygon" && feature.geometry.coordinates.GetType() == typeof(object[][]))
                    {
                        object[][] coordinates = (object[][])feature.geometry.coordinates;

                        for (int p = 0; p < coordinates.Length; ++p)
                        {
                            List <Vector3> poly = new List <Vector3>();
                            for (int t = 0; t < coordinates[p].Length; ++t)
                            {
                                float x = 0;
                                float y = 0;
                                if (coordinates[p][t].GetType() == typeof(object[]))
                                {
                                    object[] xy = (object[])coordinates[p][t];
                                    x = System.Convert.ToSingle(xy[0]);
                                    y = System.Convert.ToSingle(xy[1]);
                                }
                                if (coordinates[p][t].GetType() == typeof(double[]))
                                {
                                    double[] xy = (double[])coordinates[p][t];
                                    x = System.Convert.ToSingle(xy[0]);
                                    y = System.Convert.ToSingle(xy[1]);
                                }
                                if (coordinates[p][t].GetType() == typeof(int[]))
                                {
                                    int[] xy = (int[])coordinates[p][t];
                                    x = System.Convert.ToSingle(xy[0]);
                                    y = System.Convert.ToSingle(xy[1]);
                                }
                                poly.Add(new Vector3(x - CourseBase.Info.geoX, 0, y - CourseBase.Info.geoY));
                            }

                            for (int t = 0; t < poly.Count; ++t)
                            {
                                poly[t] = new Vector3(poly[t].x, CourseBase.TerrainHeight(poly[t].x, poly[t].z), poly[t].z);
                            }

                            if (CourseBase.IsHazard(file.features[i].properties.Layer))
                            {
                                CourseBase.CreateHazard(poly.ToArray(), CourseBase.GetLayer(file.features[i].properties.Layer, CourseBase.HazardLayers), 0, true);
                            }
                            else
                            {
                                CourseBase.CreateSpline(poly.ToArray(), CourseBase.GetLayer(file.features[i].properties.Layer, CourseBase.SplineLayers), 0, true);
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Feature " + feature.id + "(" + feature.geometry.coordinates.GetType() + ") is not a Polygon");
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Exemple #22
0
        public override void OnUI(bool selected)
        {
            if (selected == false)
            {
                return;
            }

            BeginUI();
            Move(1, 0);

            Background(4);

            if (MainToolUI.InfoPanel)
            {
                SetColor(Green);
            }
            if (Button(courseInfoTexture))
            {
                MainToolUI.InfoPanel = !MainToolUI.InfoPanel;
            }
            SetColor();
            Move(1, 0);

            if (Button(helpTexture))
            {
                Application.OpenURL("http://perfectparallel.com/documentation");
            }

            #region Version
            Move(0, 0.47f);

            SetColor(Black);
            MovePixels(1, 1);
            Label(CourseBase.version, 1, 1, EditorStyles.boldLabel);
            MovePixels(-1, -1);

            SetColor();
            Label(CourseBase.version, 1, 1, EditorStyles.boldLabel);

            Move(0, -0.47f);
            #endregion

            SetColor();
            Move(1, 0);

            if (Button(androidTexture))
            {
                MainToolUI.AndroidPanel = !MainToolUI.AndroidPanel;
            }
            Move(1, 0);

            EditorGUI.BeginDisabledGroup(!PlatformBase.IO.IsEditor);
            if (PopupToolUI.Count() != 0)
            {
                SetColor(Yellow);
            }
            if (Button(new GUIContent(buildTexture, (PopupToolUI.Count() != 0 ? "Click to build it anyway" : null))))
            {
                if (PopupToolUI.Count() == 0)
                {
                    CheckCourse();
                    if (PopupToolUI.Count() == 0)
                    {
                        CourseBase.BuildCourse((int)Utility.FromName <UnityEditor.BuildTarget>(BuildTarget));
                    }
                }
                else
                {
                    CourseBase.BuildCourse((int)Utility.FromName <UnityEditor.BuildTarget>(BuildTarget));
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(MainToolUI.NormalMode);
            if (!MainToolUI.NormalMode || BuildTarget != UnityEditor.BuildTarget.WebPlayerStreamed.ToString())
            {
                Move(1.3f, 0.35f);
                Background(2.0f, 0.35f);
                Background(2.0f, 0.35f);
                BuildTarget = EditorGUI.EnumPopup(GetRect(2.0f, 1.0f), Utility.FromName <UnityEditor.BuildTarget>(BuildTarget)).ToString();

                Color color = GUI.color;
                SetColor(Black);
                Move(-0.45f, -0.15f);
                MovePixels(1, 1);
                Label("►", 3, 3, EditorStyles.largeLabel);
                MovePixels(-1, -1);
                SetColor();
                GUI.color = color;

                Move(-0.01f, 0.01f);
                Label("►", 3, 3, EditorStyles.largeLabel);
                Move(-0.05f, -0.6f);
            }
            EditorGUI.EndDisabledGroup();

            SetColor();
            Move(1, 0);

            Move(3, 0);

            EditorGUI.BeginDisabledGroup(!PlatformBase.IO.IsEditor);
            if (!MainToolUI.CommunityMode)
            {
                Background(2);

                if (Button(importTexture))
                {
                    string path = PlatformBase.Editor.OpenFileDialog("Load .geojson", PlatformBase.IO.CoursesPath, "geojson");
                    if (!string.IsNullOrEmpty(path))
                    {
                        GeoJSON.ImportSplines(path);
                    }
                }
                Move(1, 0);

                if (Button(exportTexture))
                {
                    string path = PlatformBase.Editor.SaveFileDialog("Save .geojson", PlatformBase.IO.CoursesPath, "", "geojson");
                    if (!string.IsNullOrEmpty(path))
                    {
                        GeoJSON.ExportSplines(path);
                    }
                }
                Move(1, 0);

                Background(4);

                Label("Export Terrain Step", 2.7f);
                Move(0, 0.35f);
                ExportTerrainStep = FloatSlider(ExportTerrainStep, 0.01f, 10.0f, 3.0f, 0.6f);
                Move(0, -0.35f);
                Move(3, 0);

                if (Button(terrainTexture))
                {
                    string path = PlatformBase.Editor.SaveFileDialog("Save .bil", PlatformBase.IO.CoursesPath, "", "bil");
                    if (!string.IsNullOrEmpty(path))
                    {
                        GeoJSON.ExportTerrain(path, ExportTerrainStep);
                    }
                }
                Move(1, 0);
            }
            EditorGUI.EndDisabledGroup();

            EndUI();
        }
Exemple #23
0
        public override void OnUI(bool selected)
        {
            #region Key Events
            if (Event.current.keyCode == KeyCode.Tab && Event.current.type == EventType.keyDown)
            {
                if (EULA == false)
                {
                    EULA = true;
                }
                else if (SceneView.lastActiveSceneView.orthographic)
                {
                    SceneView.lastActiveSceneView.orthographic = false;
                }
                else if (Tools.current != UnityEditor.Tool.View)
                {
                    Tools.current = UnityEditor.Tool.View;
                }
                else if (PlatformBase.IO.IsEditor)
                {
                    if (PlatformBase.Editor.ActiveTransform == null)
                    {
                        PlatformBase.Editor.ActiveTransform = CourseBase.Terrain.transform;
                    }
                    else
                    {
                        PlatformBase.Editor.ActiveTransform = null;
                    }
                }

                Event.current.Use();
            }
            #endregion

            BeginUI();

            MoveToRight();
            Move(-3, 0);
            Background();
            if (Button(xTexture))
            {
                DisablePerform();
            }
            MoveToLeft();

            Background();
            if (!ToolLocked)
            {
                Move(0, 1);
                Background(1, Screen.height / BoxSize - 1);
                Move(0, -1);
            }

            Move(1, 0);
            if (SelectedTool != Tool.None)
            {
                Background(Screen.width / BoxSize - 3);
            }
            Move(-1, 0);

            #region Banner Messages
            if (EULA == false)
            {
                if (Button(wwwTexture))
                {
                    SelectedTool = SelectedTool;
                }

                Move(1, 0);
                SetColor(HalfGreen);
                if (Button("End User License Agreement - Press TAB to agree", 8))
                {
                    EULA = true;
                }
                SetColor();
                Move(-1, 0);

                Move(0, 1);
                Background(Screen.width / BoxSize - 2, Screen.height / BoxSize - 1);
                Background(Screen.width / BoxSize - 2, Screen.height / BoxSize - 1);

                GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
                labelStyle.wordWrap         = true;
                labelStyle.normal.textColor = Color.white;

                Rect scrollViewRect = GetRect(Screen.width / BoxSize - 2, (Screen.height - TopBoxHeight) / BoxSize - 1);

                float textHeight = 0;
                for (int i = 0; i < eulaText.Length; i += 4096)
                {
                    string text = eulaText.Substring(i, Mathf.Min(eulaText.Length - i, 4096));
                    if (text.Contains("\n") && text.Length == 4096)
                    {
                        int index = text.LastIndexOf("\n");
                        text = eulaText.Substring(i, index);
                        i   += index;
                        i   -= 4096;
                    }

                    textHeight += labelStyle.CalcHeight(new GUIContent(text), scrollViewRect.width - 20);
                }

                Rect textRect = new Rect(0, 0, scrollViewRect.width - 20, textHeight);
                eulaScrollPos = GUI.BeginScrollView(scrollViewRect, eulaScrollPos, textRect);

                for (int i = 0; i < eulaText.Length; i += 4096)
                {
                    string text = eulaText.Substring(i, Mathf.Min(eulaText.Length - i, 4096));
                    if (text.Contains("\n") && text.Length == 4096)
                    {
                        int index = text.LastIndexOf("\n");
                        text = eulaText.Substring(i, index);
                        i   += index;
                        i   -= 4096;
                    }

                    textRect.height = labelStyle.CalcHeight(new GUIContent(text), scrollViewRect.width - 20);

                    SetColor(Black);
                    GUI.Label(new Rect(textRect.x + 1, textRect.y + 1, textRect.width, textRect.height), text, labelStyle);
                    SetColor();
                    GUI.Label(textRect, text, labelStyle);

                    textRect.y += textRect.height;
                }

                GUI.EndScrollView();
                Move(0, -1);

                EndUI();
                return;
            }
            else if (SceneView.lastActiveSceneView.orthographic)
            {
                if (Button(wwwTexture))
                {
                    SelectedTool = SelectedTool;
                }

                Move(1, 0);
                SetColor(HalfGreen);
                if (Button("CourseForge has limited functionality in ISO mode, press TAB to switch back", 14))
                {
                    SceneView.lastActiveSceneView.orthographic = false;
                }
                SetColor();
                Move(-1, 0);

                EndUI();
                return;
            }
            else if (Tools.current != UnityEditor.Tool.View)
            {
                if (Button(wwwTexture))
                {
                    SelectedTool = SelectedTool;
                }

                Move(1, 0);
                SetColor(HalfGreen);
                if (Button("CourseForge has limited functionality in this view mode, press TAB to switch back", 14))
                {
                    Tools.current = UnityEditor.Tool.View;
                }
                SetColor();
                Move(-1, 0);

                EndUI();
                return;
            }
            else if (CourseBase.TerrainSelected)
            {
                if (Button(wwwTexture))
                {
                    SelectedTool = SelectedTool;
                }

                Move(1, 0);
                SetColor(HalfGreen);
                if (Button("Terrain Mode - Press TAB to exit", 6))
                {
                    PlatformBase.Editor.ActiveTransform = null;
                }
                SetColor();
                Move(-1, 0);

                EndUI();
                return;
            }
            else if (selected)
            {
                if (ToolButton(Tool.FileTool, wwwTexture))
                {
                    OnCleanup();
                }

                Move(1, 0);
                if (SelectedTool > Tool.FileTool && Button((ToolName.Length > 8 ? ToolName.Substring(0, 8) + "..." : ToolName), 2))
                {
                    GameObject toolObject = GameObject.Find(ToolName);
                    if (toolObject != null)
                    {
                        EditorGUIUtility.PingObject(toolObject);
                        Selection.activeGameObject = toolObject;
                    }
                }
                Move(-1, 0);
            }
            Move(0, 1);
            #endregion

            #region Top
            if (ToolButton(Tool.SplineTool, freehandTexture))
            {
                OnCleanup();
                if (CourseBase.TerrainLowered)
                {
                    CourseBase.RestoreTerrain();
                }
            }
            Move(0, 1);

            if (ToolButton(Tool.PlantTool, plantTexture))
            {
                OnCleanup();
                if (CourseBase.TerrainLowered)
                {
                    CourseBase.RestoreTerrain();
                }
            }
            Move(0, 1);

            if (Button(terrainTexture))
            {
                SelectedTool = Tool.None;
                OnCleanup();

                if (PlatformBase.IO.IsEditor)
                {
                    PlatformBase.Editor.ActiveTransform = CourseBase.Terrain.transform;
                }
            }
            Move(0, 1);

            if (CourseBase.TerrainLowered)
            {
                SetColor(Red);
            }
            if (Button(terrainLoweredTexture))
            {
                SelectedTool = Tool.None;
                OnCleanup();

                if (!CourseBase.TerrainLowered)
                {
                    CourseBase.SaveTerrain();
                    CourseBase.LowerTerrain();
                }
                else
                {
                    CourseBase.RestoreTerrain();
                }
            }
            SetColor();
            Move(0, 1);

            if (Button(updateTexture))
            {
                if (CourseBase.TerrainLowered)
                {
                    CourseBase.RestoreTerrain();
                }
                CourseBase.RefreshCourse();
            }
            Move(0, 1);

            if (Button(buildSplinesTexture))
            {
                if (CourseBase.TerrainLowered)
                {
                    CourseBase.RestoreTerrain();
                }
                PopupToolUI.Clear();
                CourseBase.BakeSplines(true);
            }
            Move(0, 1);
            #endregion

            #region Bottom
            MoveToBottom();
            Move(0, -1);

            if (HideLines)
            {
                SetColor(HalfGrey);
            }
            if (Button(splineEyeTexture))
            {
                HideLines = !HideLines;
            }
            SetColor();
            Move(0, -1);

            if (AutoHide)
            {
                SetColor(HalfGrey);
            }
            if (Button(autoEyeTexture))
            {
                AutoHide = !AutoHide;
            }
            SetColor();
            Move(0, -1);

            if (HideMeshes)
            {
                SetColor(HalfGrey);
            }
            if (Button(eyeTexture))
            {
                AutoHide   = false;
                HideMeshes = !HideMeshes;

                List <SplineBase> splines = CourseBase.Splines;
                for (int i = 0; i < splines.Count; ++i)
                {
                    splines[i].Renderer.UpdateVisibility(splines[i], !HideMeshes);
                }
            }
            SetColor();
            Move(0, -1);

            if (MainToolUI.NormalMode)
            {
                EditorGUI.BeginDisabledGroup(true);
                LayerPanel = false;
            }

            if (LayerPanel)
            {
                SetColor(Green);
            }
            if (Button(layersTexture))
            {
                LayerPanel = !LayerPanel;
            }
            SetColor();
            Move(0, -1);

            if (MainToolUI.NormalMode)
            {
                EditorGUI.EndDisabledGroup();
            }
            #endregion

            EndUI();
        }
Exemple #24
0
 static void HazardStartOutOfBounds()
 {
     startSplineLayer = CourseBase.HazardLayers.Find(x => CourseBase.HazardType(x.name) == HazardBase.Type.Out_of_Bounds);
 }
Exemple #25
0
        public override void OnUI(bool selected)
        {
            #region Sort Layers
            Layer layer = Layer;
            Course.Library.layers = Course.Library.layers.OrderBy(x => x.name).OrderBy(x => Course.IsHazard(x.name)).ToList();
            layerIndex            = Course.Layers.IndexOf(layer);
            #endregion

            List <Layer> layers      = CourseBase.Layers;
            int          layersCount = layers.Count;
            string       libraryName = PlatformBase.IO.GetFileNameWithoutExtension(CourseBase.LibraryName);
            Layer        oldLayer    = new Layer(Layer);


            BeginUI();

            MoveToBottom();
            Move(1, -5.75f);
            MovePixels(1, 0);

            if (layers.GroupBy(x => x.name.ToLower()).Any(y => y.Count() > 1))
            {
                Move(0, -0.8f);
                EditorGUI.HelpBox(GetRect(5, 0.8f), "Multiple layers with the same name detected. Each layer should have it's own unique name. ", MessageType.Warning);
                Move(0, 0.8f);
            }

            Background(5, 1, 0.5f);

            #region Library
            Label("Loaded library ---", 2.5f);
            {
                Move(2.5f, 0);
                MovePixels(1, 1);
                SetColor(Black);
                Label(libraryName + (libraryName == "default" ? " (Read-only)" : ""), 2.5f);
                MovePixels(-1, -1);
                SetColor(Green);
                Label(libraryName + (libraryName == "default" ? " (Read-only)" : ""), 2.5f);
                SetColor();
                Move(-2.5f, 0);
            }
            #endregion

            #region Import/Export
            Move(0, 0.4f);
            EditorGUI.BeginDisabledGroup(!PlatformBase.IO.IsEditor);
            {
                if (Button("load...", 2.5f, 0.6f))
                {
                    try
                    {
                        string path = PlatformBase.Editor.OpenFileDialog("Load Course Library", PlatformBase.IO.LibrariesPath, "cfl");
                        if (path != "")
                        {
                            CourseBase.ImportLibrary(path);
                            Debug.Log("CourseForge {load " + PlatformBase.IO.GetFileNameWithoutExtension(path) + "} " + DateTime.Now.ToString("dd MMM HH:mm:ss"));
                        }
                    }
                    catch (Exception e)
                    {
                        EditorUtility.DisplayDialog("Load error.", e.ToString(), "ok");
                    }
                }
                Move(2.5f, 0);
                if (Button("save as...", 2.5f, 0.6f))
                {
                    try
                    {
                        string path = PlatformBase.Editor.SaveFileDialog("Save Course Library", PlatformBase.IO.LibrariesPath, PlatformBase.IO.GetFileNameWithoutExtension(CourseBase.LibraryName), "cfl");
                        if (path != "")
                        {
                            CourseBase.ExportLibrary(path);
                            Debug.Log("CourseForge {save " + PlatformBase.IO.GetFileNameWithoutExtension(path) + "} " + DateTime.Now.ToString("dd MMM HH:mm:ss"));
                        }
                    }
                    catch (Exception e)
                    {
                        EditorUtility.DisplayDialog("Export error.", e.ToString(), "ok");
                    }
                }
                Move(-2.5f, 0);
            }
            EditorGUI.EndDisabledGroup();
            Move(0, 0.6f);
            MovePixels(0, 2);
            #endregion

            #region Layer Popup
            Background(5, 5.75f, 0.75f);
            Label("Selected layer", 2.5f);

            Move(1.85f, 0);
            if (IsHazardLayer)
            {
                SetColor(Green);
            }
            else
            {
                SetColor(HalfGrey);
            }
            if (Button("H", 0.7f, 0.6f))
            {
                if (IsHazardLayer && CourseBase.SplineLayers.Count != 0)
                {
                    Layer = (Layer)CourseBase.SplineLayers[0];
                }
                else if (!IsHazardLayer && CourseBase.HazardLayers.Count != 0)
                {
                    Layer = (Layer)CourseBase.HazardLayers[0];
                }
                else
                {
                    layerIndex = 0;
                }

                oldLayer = new Layer(Layer);
            }
            SetColor();
            Move(-1.85f, 0);

            Move(0, 0.4f);

            List <string> names = new List <string>(layers.Select(x => (layers.IndexOf(x) + 1) + " " + x.name));
            if (IsSplineLayer)
            {
                names = names.Take(Course.SplineLayers.Count).ToList();
            }

            if (libraryName != "default" && IsSplineLayer)
            {
                names.Add("Clone");
                names.Add("New");
                names.Add("Delete");
            }

            int index = Popup(layerIndex, names.ToArray(), 4, 0.6f);
            if (index == -1 || index >= names.Count)
            {
            }
            else if (names[index] == "Clone")
            {
                layers.Add(new Layer(Layer));
                Layer       = layers[layers.Count - 1];
                Layer.name += " (Clone)";
                oldLayer    = new Layer(Layer);
            }
            else if (names[index] == "New")
            {
                layers.Add(new Layer());
                Layer    = layers[layers.Count - 1];
                oldLayer = new Layer(Layer);
            }
            else if (names[index] == "Delete")
            {
                if (CourseBase.SplineLayers.Count > 1 && PlatformBase.Editor.OkCancelDialog("Layer library", "Are you sure you want to remove (" + Layer.name + ") layer?"))
                {
                    layers.Remove(Layer);
                    Layer    = CourseBase.SplineLayers[0];
                    oldLayer = new Layer(Layer);
                }
            }
            else
            {
                layerIndex = index;
            }
            #endregion

            if (libraryName == "default")
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            #region Clear
            Move(4, 0);
            SetColor(Red);

            if (IsHazardLayer)
            {
                EditorGUI.BeginDisabledGroup(true);
            }
            if (Button("CLR", 1, 0.6f))
            {
                if (PlatformBase.Editor.OkCancelDialog("Layer library", "Are you sure you want to clear (" + Layer.name + ") layer?"))
                {
                    layers[layerIndex] = new Layer();
                    oldLayer           = new Layer(Layer);
                }
            }
            if (IsHazardLayer)
            {
                EditorGUI.EndDisabledGroup();
            }

            SetColor();
            Move(-4, 0.35f);
            MovePixels(0, 1);
            #endregion

            #region Spline Zone
            Label("| Spline Apperance", 3.5f);
            Move(0, 0.5f);
            MovePixels(0, 1);
            Background(5, 1, 0.75f);
            {
                Label("  Name", 2.5f);
                Move(2.5f, 0);
                if (IsHazardLayer)
                {
                    EditorGUI.BeginDisabledGroup(true);
                }
                Layer.name = TextField(Layer.name, 2.5f, 0.6f);
                if (IsHazardLayer)
                {
                    EditorGUI.EndDisabledGroup();
                }
                Move(-2.5f, 0);
            }
            Move(0, 0.4f);
            {
                Label("  Color", 2.5f);
                Move(2.5f, 0);
                Layer.LayerColor = ColorField(Layer.LayerColor, 2.5f, 0.6f);
                Move(-2.5f, 0);
            }
            Move(0, 0.5f);

            Label("| Spline creation", 2.5f);
            Move(0, 0.5f);
            MovePixels(0, 1);
            Background(5, 0.6f, 0.75f);
            {
                Label("  Meters per Point", 2.5f);
                Move(2.5f, 0);
                Layer.metersPerOnePoint = FloatField(Layer.metersPerOnePoint, 2.5f, 0.6f);
                Move(-2.5f, 0);
            }
            Move(0, 0.5f);
            #endregion

            if (IsHazardLayer)
            {
                #region Mesh Zone
                Label("| Mesh creation", 2.5f);
                Move(0, 0.5f);
                MovePixels(0, 1);
                Background(5, 1.1f, 0.75f);

                Move(0, 0.4f);
                {
                    Label("  Points per edge", 2.5f);
                    Move(2.5f, 0);
                    Layer.pointsPerEdge = IntField(Layer.pointsPerEdge, 2.5f, 0.6f);
                    Move(-2.5f, 0);
                }
                Move(0, 0.5f);
                #endregion

                MoveToBottom();
                Move(5, -2.15f);
                MovePixels(1, 0);
                Background(5, 4.75f, 0.5f);

                #region Visual
                Label("| Visual", 2.5f);
                Move(0, 0.5f);
                MovePixels(0, 1);
                Background(5, 11, 0.75f);

                Label("  Hazard Color ", 2.5f);
                Move(2.5f, 0);
                Layer.hazardColor = ColorField(Layer.hazardColor, 2.5f, 0.6f);
                Move(-2.5f, 0);
                Move(0, 0.5f);

                Label("  Post", 2.5f);
                Move(2.5f, 0);
                Layer.HazardPost = ObjectField <GameObject>(Layer.HazardPost, 2.5f, 0.6f);
                Move(-2.5f, 0);
                Move(0, 0.5f);

                Label("  Meters per Post", 2.5f);
                Move(2.5f, 0);
                Layer.metersPerOnePost = FloatField(Layer.metersPerOnePost, 2.5f, 0.6f);
                Move(-2.5f, 0);
                #endregion
            }
            else
            {
                #region Mesh Zone
                Label("| Mesh creation", 2.5f);
                Move(0, 0.5f);
                MovePixels(0, 1);
                Background(5, 1.1f, 0.75f);
                {
                    Move(0.2f, 0);
                    Layer.fillType = (Layer.FillType)Popup((int)Layer.fillType, Utility.EnumNames <Layer.FillType>(), 2.5f, 0.6f);
                    Move(-0.2f, 0);

                    Move(2.5f, 0);
                    Layer.resolution = FloatField(Layer.resolution, 2.5f, 0.6f);
                    Move(-2.5f, 0);
                }
                Move(0, 0.4f);
                {
                    Label("  Points per edge", 2.5f);
                    Move(2.5f, 0);
                    Layer.pointsPerEdge = IntField(Layer.pointsPerEdge, 2.5f, 0.6f);
                    Move(-2.5f, 0);
                }
                Move(0, 0.5f);
                #endregion

                MoveToBottom();
                Move(5, -8.5f);
                MovePixels(1, 0);
                Background(5, 11, 0.5f);

                #region Visual
                Label("| Visual", 2.5f);
                Move(0, 0.5f);
                MovePixels(0, 1);
                Background(5, 11, 0.75f);
                {
                    Move(0, 0);
                    {
                        Label("  Main Color", 2.5f);
                        Move(2.5f, 0);
                        Layer.mainColor = ColorField(Layer.mainColor, 2.5f, 0.6f);
                        Move(-2.5f, 0);
                    }
                    Move(0, 0.5f);
                    {
                        Label("  Specular Color", 2.5f);
                        Move(2.5f, 0);
                        Layer.specularColor = ColorField(Layer.specularColor, 2.5f, 0.6f);
                        Move(-2.5f, 0);
                    }
                    Move(0, 0.5f);
                    {
                        Label("  Texture 1", 2.5f);
                        Move(2.5f, 0);
                        Label("Texture 2", 2.5f);
                        Move(-2.5f, 0);
                        Move(0, 0.3f);

                        Move(0.2f, 0);
                        Layer.diffuse.TileTexture = ObjectField(Layer.diffuse.TileTexture, 2.3f, 2.3f);
                        Move(2.3f, 0);
                        Layer.detail.TileTexture = ObjectField(Layer.detail.TileTexture, 2.3f, 2.3f);
                        Move(-0.2f, 0);
                        Move(-2.3f, 0);
                        Move(0, 2.1f);

                        Move(0.2f, 0);
                        Layer.diffuse.tile = FloatField(Layer.diffuse.tile, 2.3f, 0.6f);
                        Move(2.3f, 0);
                        Layer.detail.tile = FloatField(Layer.detail.tile, 2.3f, 0.6f);
                        Move(-0.2f, 0);
                        Move(-2.3f, 0);

                        Move(0, 0.6f);

                        Label("  Normal 1", 2.5f);
                        Move(2.5f, 0);
                        Label("Normal 2", 2.5f);
                        Move(-2.5f, 0);
                        Move(0, 0.3f);

                        Move(0.2f, 0);
                        Layer.normal.TileTexture = ObjectField(Layer.normal.TileTexture, 2.3f, 2.3f);
                        Move(2.3f, 0);
                        Layer.detailNormal.TileTexture = ObjectField(Layer.detailNormal.TileTexture, 2.3f, 2.3f);
                        Move(-0.2f, 0);
                        Move(-2.3f, 0);
                        Move(0, 2.1f);

                        Move(0.2f, 0);
                        Layer.normal.tile = FloatField(Layer.normal.tile, 2.3f, 0.6f);
                        Move(2.3f, 0);
                        Layer.detailNormal.tile = FloatField(Layer.detailNormal.tile, 2.3f, 0.6f);
                        Move(-0.2f, 0);
                        Move(-2.3f, 0);

                        Move(0, 0.4f);

                        Move(0.2f, 0);
                        Layer.normal.bump = FloatSlider(Layer.normal.bump, 0, 1, 2.3f, 0.6f);
                        Move(2.3f, 0);
                        Layer.detailNormal.bump = FloatSlider(Layer.detailNormal.bump, 0, 1, 2.3f, 0.6f);
                        Move(-0.2f, 0);
                        Move(-2.3f, 0);
                    }
                    Move(0, 0.6f);
                    {
                        Label("  Fresnel Intensity", 2.5f);
                        Move(2.5f, 0);
                        MovePixels(-3, 0);
                        Layer.fresnelIntensity = FloatSlider(Layer.fresnelIntensity, 0.0f, 1, 2.65f, 0.6f);
                        MovePixels(3, 0);
                        Move(-2.5f, 0);
                    }
                }
                #endregion

                MoveToBottom();
                Move(5, -4.75f);
                MovePixels(1, 1);
                Background(5, 4.75f, 0.5f);

                SplineBase.SplinePattern pattern = Layer.pattern;
                #region Shape Zone
                Label("| Mesh shape", 2.5f);
                Move(2.5f, 0);
                Layer.PhysicsMaterial = ObjectField(Layer.PhysicsMaterial, 2.5f, 0.6f);
                Move(-2.5f, 0);
                {
                    Move(0, 0.5f);
                    MovePixels(0, 1);
                    Background(5, 1.0f, 0.75f);
                    {
                        MovePixels(-3, 0);
                        Move(0.2f, 0);
                        if (pattern.transition)
                        {
                            SetColor(Green);
                        }
                        if (Button("Blend", 1.2f, 0.6f))
                        {
                            pattern.transition = !pattern.transition;
                        }
                        SetColor();
                        Move(-0.2f, 0);
                        MovePixels(3, 0);

                        if (pattern.transition)
                        {
                            MovePixels(-3, 0);
                            Label("              Width", 2.5f);
                            Move(2.5f, 0);
                            pattern.transitionLength = FloatSlider(pattern.transitionLength, 0.001f, 1, 2.65f, 0.6f);
                            Move(-2.5f, 0);
                            MovePixels(3, 0);
                        }
                    }
                    Move(0, 0.4f);
                    {
                        if (pattern.transition)
                        {
                            MovePixels(-3, 0);
                            Label("              Depth", 2.5f);
                            Move(2.5f, 0);
                            pattern.transitionDepth = FloatSlider(pattern.transitionDepth, -1, 1, 2.65f, 0.6f);
                            Move(-2.5f, 0);
                            MovePixels(3, 0);
                        }
                    }
                    Move(0, 0.6f);
                    MovePixels(0, 1);
                    MovePixels(0, 1);

                    Background(5, 2.1f, 0.75f);
                    {
                        MovePixels(-3, 0);
                        Move(0.2f, 0);
                        if (pattern.extra)
                        {
                            SetColor(Green);
                        }
                        if (Button("Fringe", 1.2f, 0.6f))
                        {
                            pattern.extra = !pattern.extra;
                        }
                        SetColor();
                        Move(-0.2f, 0);
                        Move(2.5f, 0);
                        if (pattern.extra)
                        {
                            pattern.extraLayerName = LayerPopup(CourseBase.GetLayer(pattern.extraLayerName, CourseBase.SplineLayers), CourseBase.SplineLayers, 2.65f, 0.6f).name;
                        }
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.4f);
                    if (pattern.extra)
                    {
                        MovePixels(-3, 0);
                        Label("              Width", 2.5f);
                        Move(2.5f, 0);
                        pattern.extraLength = FloatSlider(pattern.extraLength, 0.001f, 1, 2.65f, 0.6f);
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.4f);
                    if (pattern.extra)
                    {
                        MovePixels(-3, 0);
                        Label("              Depth", 2.5f);
                        Move(2.5f, 0);
                        pattern.extraDepth = FloatSlider(pattern.extraDepth, -1, 1, 2.65f, 0.6f);
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.4f);
                    if (pattern.extra)
                    {
                        MovePixels(-3, 0);
                        Move(0.2f, 0);
                        if (pattern.extraTransition)
                        {
                            SetColor(Green);
                        }
                        if (Button("Blend", 1.2f, 0.6f))
                        {
                            pattern.extraTransition = !pattern.extraTransition;
                        }
                        SetColor();
                        Move(-0.2f, 0);
                        MovePixels(3, 0);

                        if (pattern.extraTransition)
                        {
                            MovePixels(-3, 0);
                            Label("              Width", 2.5f);
                            Move(2.5f, 0);
                            pattern.extraTransitionLength = FloatSlider(pattern.extraTransitionLength, 0.001f, 1, 2.65f, 0.6f);
                            Move(-2.5f, 0);
                            MovePixels(3, 0);
                        }
                    }
                    Move(0, 0.4f);
                    if (pattern.extra && pattern.extraTransition)
                    {
                        MovePixels(-3, 0);
                        Label("              Depth", 2.5f);
                        Move(2.5f, 0);
                        pattern.extraTransitionDepth = FloatSlider(pattern.extraTransitionDepth, -1, 1, 2.65f, 0.6f);
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.5f);
                    MovePixels(0, 1);
                    MovePixels(0, 1);

                    Background(5, 1.3f, 0.75f);
                    {
                        MovePixels(-3, 0);
                        Move(0.2f, 0);
                        if (pattern.shrink)
                        {
                            SetColor(Green);
                        }
                        if (Button("Shrink", 1.2f, 0.6f))
                        {
                            pattern.shrink = !pattern.shrink;
                        }
                        SetColor();
                        Move(-0.2f, 0);
                        MovePixels(3, 0);
                    }
                    if (pattern.shrink)
                    {
                        MovePixels(-3, 0);
                        Label("              Width", 2.5f);
                        Move(2.5f, 0);
                        pattern.shrinkLength = FloatSlider(pattern.shrinkLength, 0.001f, 1, 2.65f, 0.6f);
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.4f);
                    if (pattern.shrink)
                    {
                        MovePixels(-3, 0);
                        Label("              Depth", 2.5f);
                        Move(2.5f, 0);
                        pattern.shrinkDepth = FloatSlider(pattern.shrinkDepth, -1, 1, 2.65f, 0.6f);
                        Move(-2.5f, 0);
                        MovePixels(3, 0);
                    }
                    Move(0, 0.5f);
                }
                #endregion
            }

            #region Change Sync
            bool materialChanged = false;
            bool layerChanged    = false;

            if (layersCount != CourseBase.Layers.Count)
            {
                layerChanged    = true;
                materialChanged = true;
            }
            if (oldLayer.name != Layer.name)
            {
                layerChanged = true;
            }
            if (oldLayer.LayerColor != Layer.LayerColor)
            {
                materialChanged = true;
            }
            if (oldLayer.mainColor.ToColor() != Layer.mainColor.ToColor())
            {
                materialChanged = true;
            }
            if (oldLayer.specularColor.ToColor() != Layer.specularColor.ToColor())
            {
                materialChanged = true;
            }
            if (oldLayer.hazardColor.ToColor() != Layer.hazardColor.ToColor())
            {
                materialChanged = true;
            }
            if (oldLayer.diffuse.TileTexture != Layer.diffuse.TileTexture)
            {
                materialChanged = true;
            }
            if (oldLayer.detail.TileTexture != Layer.detail.TileTexture)
            {
                materialChanged = true;
            }
            if (oldLayer.normal.TileTexture != Layer.normal.TileTexture)
            {
                materialChanged = true;
            }
            if (oldLayer.detailNormal.TileTexture != Layer.detailNormal.TileTexture)
            {
                materialChanged = true;
            }
            if (oldLayer.fresnelIntensity != Layer.fresnelIntensity)
            {
                materialChanged = true;
            }
            if (oldLayer.diffuse.tile != Layer.diffuse.tile)
            {
                materialChanged = true;
            }
            if (oldLayer.detail.tile != Layer.detail.tile)
            {
                materialChanged = true;
            }
            if (oldLayer.normal.tile != Layer.normal.tile)
            {
                materialChanged = true;
            }
            if (oldLayer.normal.bump != Layer.normal.bump)
            {
                materialChanged = true;
            }
            if (oldLayer.detailNormal.tile != Layer.detailNormal.tile)
            {
                materialChanged = true;
            }
            if (oldLayer.detailNormal.bump != Layer.detailNormal.bump)
            {
                materialChanged = true;
            }
            if (oldLayer.resolution != Layer.resolution)
            {
                layerChanged = true;
            }
            if (oldLayer.PhysicsMaterial != Layer.PhysicsMaterial)
            {
                materialChanged = true;
            }
            if (oldLayer.HazardPost != Layer.HazardPost)
            {
                materialChanged = true;
            }
            if (oldLayer.metersPerOnePoint != Layer.metersPerOnePoint)
            {
                layerChanged = true;
            }
            if (oldLayer.metersPerOnePost != Layer.metersPerOnePost)
            {
                layerChanged = true;
            }
            if (oldLayer.pointsPerEdge != Layer.pointsPerEdge)
            {
                layerChanged = true;
            }

            if (oldLayer.pattern.transition != Layer.pattern.transition)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.transitionLength != Layer.pattern.transitionLength)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.transitionDepth != Layer.pattern.transitionDepth)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extra != Layer.pattern.extra)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraLayerIndex != Layer.pattern.extraLayerIndex)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraLayerName != Layer.pattern.extraLayerName)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraLength != Layer.pattern.extraLength)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraDepth != Layer.pattern.extraDepth)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraTransition != Layer.pattern.extraTransition)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraTransitionLength != Layer.pattern.extraTransitionLength)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.extraTransitionDepth != Layer.pattern.extraTransitionDepth)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.shrink != Layer.pattern.shrink)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.shrinkLength != Layer.pattern.shrinkLength)
            {
                layerChanged = true;
            }
            if (oldLayer.pattern.shrinkDepth != Layer.pattern.shrinkDepth)
            {
                layerChanged = true;
            }

            if (layerChanged)
            {
                CourseBase.OnLayerChange();
            }
            if (materialChanged)
            {
                CourseBase.OnLayerMaterialChange();
            }
            #endregion

            MoveToLeft();
            MoveToBottom();
            Move(1, -5.75f);
            Touch(15, 5.75f);

            if (libraryName == "default")
            {
                EditorGUI.EndDisabledGroup();
            }
            EndUI();
        }
Exemple #26
0
 static void HazardStartLateralWaterHazard()
 {
     startSplineLayer = CourseBase.HazardLayers.Find(x => CourseBase.HazardType(x.name) == HazardBase.Type.Lateral_Water_Hazard);
 }
Exemple #27
0
        void OnMouse()
        {
            if (PointByPoint)
            {
                if (LeftMouseDown)
                {
                    OnMouseDown();
                    Event.current.Use();
                }
                if (LeftDoubleClick)
                {
                    if (points.Length >= 3)
                    {
                        if (HazardDrawing)
                        {
                            CourseBase.CreateHazard(points, CourseBase.GetLayer(LayerName, CourseBase.HazardLayers), FlagsDrawing);
                        }
                        else
                        {
                            CourseBase.CreateSpline(points, CourseBase.GetLayer(LayerName, CourseBase.SplineLayers), FlagsDrawing);
                        }
                    }
                    Event.current.Use();
                    OnCleanupBase();
                }
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    Event.current.Use();
                    OnCleanupBase();
                }
                LineToolUI.DrawLines(boxes, Black);
            }
            else
            {
                if (LeftMouseDown || LeftMouseDrag)
                {
                    drawing = true;
                    Event.current.Use();
                }
                if (drawing && LeftMouseUp)
                {
                    if (points.Length >= 3)
                    {
                        if (HazardDrawing)
                        {
                            CourseBase.CreateHazard(points, CourseBase.GetLayer(LayerName, CourseBase.HazardLayers), FlagsDrawing, true);
                        }
                        else
                        {
                            CourseBase.CreateSpline(points, CourseBase.GetLayer(LayerName, CourseBase.SplineLayers), FlagsDrawing, true);
                        }
                    }
                    Event.current.Use();
                    OnCleanupBase();
                }
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    Event.current.Use();
                    OnCleanupBase();
                }

                if (drawing)
                {
                    OnMouseDown();
                }
            }

            LineToolUI.DrawLines(points, Black);
        }
Exemple #28
0
 static void HazardStartFreeDrop()
 {
     startSplineLayer = CourseBase.HazardLayers.Find(x => CourseBase.HazardType(x.name) == HazardBase.Type.Free_Drop);
 }
Exemple #29
0
        public override void OnUI(bool selected)
        {
            if (selected)
            {
                #region Delete
                if (CourseBase.ActiveSpline && Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown)
                {
                    CourseBase.ActiveSpline.LineChanged();
                    CourseBase.ActiveSpline.Transform.parent = null;
                    if (!CourseBase.ActiveSpline.IsHazard)
                    {
                        CourseBase.ActiveSpline.Transform.DetachChildren();
                    }

                    MonoBehaviour.DestroyImmediate(CourseBase.ActiveSpline.Transform.gameObject);

                    if (CourseBase.ActiveSpline.IsHazard)
                    {
                        CourseBase.Hazards.Remove(CourseBase.ActiveSpline as HazardBase);
                    }
                    else
                    {
                        CourseBase.Splines.Remove(CourseBase.ActiveSpline);
                    }
                    CourseBase.Curves.Remove(CourseBase.ActiveSpline);

                    CourseBase.ActiveSpline = null;

                    Event.current.Use();
                    return;
                }
                #endregion

                BeginUI();
                Move(3, 0);

                if (CourseBase.ActiveSpline != null)
                {
                    SetColor(Green);
                    Move(3, 0);

                    if (!(CourseBase.ActiveSpline is HazardBase))
                    {
                        CourseBase.ActiveSpline.Info.flags = (int)HoleFlagsField((SplineBase.SplineInfo.Flags)CourseBase.ActiveSpline.Info.flags);
                        SetColor(Green);
                    }
                    Move(1, 0);

                    CourseBase.ActiveSpline.Info.flags = (int)SquareField((SplineBase.SplineInfo.Flags)CourseBase.ActiveSpline.Info.flags);
                    Move(1, 0);
                    SetColor(Green);

                    if (CourseBase.ActiveSpline is HazardBase)
                    {
                        Layer layer = CourseBase.ActiveSpline.Layer;

                        CourseBase.ActiveSpline.Layer = LayerPopup("Layer", CourseBase.ActiveSpline.Layer, CourseBase.HazardLayers, 3);
                        Move(3, 0);

                        if (layer != CourseBase.ActiveSpline.Layer)
                        {
                            for (int i = 0; i < CourseBase.ActiveSpline.Info.colorNames.Length; ++i)
                            {
                                CourseBase.ActiveSpline.Info.colorNames[i] = CourseBase.ActiveSpline.Layer.name;
                            }
                        }
                    }
                    else
                    {
                        CourseBase.ActiveSpline.Layer = LayerPopup("Layer", CourseBase.ActiveSpline.Layer, CourseBase.SplineLayers, 3);
                        SetColor();
                        Move(3, 0);

                        CourseBase.ActiveSpline.Info.locked = LockedField(CourseBase.ActiveSpline.Info.locked);
                    }
                    Move(1, 0);
                    SetColor();
                }
                else
                {
                    SplineField();
                    Move(1, 0);

                    HazardField();
                    Move(1, 0);

                    if (SplineDrawing)
                    {
                        PointByPointField();
                        Move(1, 0);

                        FlagsDrawing = HoleFlagsField(FlagsDrawing);
                        Move(1, 0);

                        FlagsDrawing = SquareField(FlagsDrawing);
                        Move(1, 0);

                        LayerName = LayerPopup("Layer", CourseBase.GetLayer(LayerName, CourseBase.SplineLayers), CourseBase.SplineLayers, 3).name;
                        Move(3, 0);
                    }

                    if (HazardDrawing)
                    {
                        PointByPointField();
                        Move(1, 0);

                        FlagsDrawing = HoleFlagsField(FlagsDrawing);
                        Move(1, 0);

                        FlagsDrawing = SquareField(FlagsDrawing);
                        Move(1, 0);

                        LayerName = LayerPopup("Layer", CourseBase.GetLayer(LayerName, CourseBase.HazardLayers), CourseBase.HazardLayers, 3).name;
                        Move(3, 0);
                    }
                }

                EndUI();

                List <SplineBase> splines = CourseBase.Curves;
                for (int i = 0; i < splines.Count; ++i)
                {
                    OnSplineGUI(splines[i], selected);
                }
            }

            if (LeftMouseDown)
            {
                CourseBase.ActiveSpline = null;
            }
            if (selected)
            {
                if (CourseBase.ActiveSpline == null && (SplineDrawing || HazardDrawing))
                {
                    OnMouse();
                }
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.Arrow);
                }
            }
        }
Exemple #30
0
        public static void OnSplineGUI(SplineBase spline, bool selected)
        {
            if (spline.Info.pin)
            {
                return;
            }
            if (spline != CourseBase.ActiveSpline && !IsMouseInside(spline.Lines.MinPoint, spline.Lines.MaxPoint))
            {
                return;
            }

            bool       leftDown   = LeftMouseDown;
            bool       rightDown  = RightMouseDown;
            RaycastHit?currentHit = CourseBase.CameraTerrainHit;

            Vector3[] points = spline.Points;

            if (spline.ActivePoint == -1)
            {
                for (int i = 0; i < points.Length; ++i)
                {
                    if (rightDown && IsMouseAround(points[i]))
                    {
                        if (spline.IsHazard)
                        {
                            if (spline == startSpline && startSplineLayer != null)
                            {
                                if (i == startSplineIndex)
                                {
                                    EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), "CONTEXT/SplineTool/Hazard/Change/", null);
                                }
                                else
                                {
                                    endSplineIndex = i;
                                    EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), "CONTEXT/SplineTool/Hazard/End/", null);
                                }
                            }
                            else
                            {
                                startSpline          = spline;
                                startSplineIndex     = i;
                                startSplineDirection = 1;
                                startSplineLayer     = null;

                                EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), "CONTEXT/SplineTool/Hazard/Start/", null);
                            }
                        }
                        Event.current.Use();
                        break;
                    }
                    if (leftDown && IsMouseAround(points[i]))
                    {
                        CourseBase.ActiveSpline = spline;
                        spline.ActivePoint      = i;
                        firstHit       = currentHit;
                        originalPoints = (Vector3[])points.Clone();
                        Event.current.Use();
                        break;
                    }
                }
            }
            if (spline.ActivePoint != -1)
            {
                Vector3 delta = Vector3.zero;
                if (firstHit != null && currentHit != null)
                {
                    delta = (currentHit.Value.point - firstHit.Value.point);
                }
                bool changed = delta.magnitude > 0.01f;

                if (LeftMouseUp)
                {
                    if (changed)
                    {
                        spline.LineChanged();
                    }
                    spline.ActivePoint = -1;

                    Event.current.Use();
                }
                else if (LeftDoubleClick && !spline.Info.locked)
                {
                    if (Event.current.modifiers == EventModifiers.Shift)
                    {
                        DeletePoint(spline);
                    }
                    else
                    {
                        AddPoint(spline);
                    }
                }
                else if (LeftMouseDrag && changed && !spline.Info.locked)
                {
                    if (Event.current.modifiers == EventModifiers.Shift)
                    {
                        for (int p = 0; p < points.Length; ++p)
                        {
                            points[p]   = originalPoints[p] + delta;
                            points[p].y = CourseBase.TerrainHeight(points[p].x, points[p].z);
                        }
                    }
                    else if (Event.current.modifiers == EventModifiers.Control)
                    {
                        Vector3 center = spline.Lines.MinPoint + (spline.Lines.MaxPoint - spline.Lines.MinPoint) / 2;
                        float   scale  = Mathf.Max(((currentHit.Value.point - center).magnitude / (firstHit.Value.point - center).magnitude), 0);
                        for (int p = 0; p < points.Length; ++p)
                        {
                            points[p]   = center + (originalPoints[p] - center) * scale;
                            points[p].y = CourseBase.TerrainHeight(points[p].x, points[p].z);
                        }
                    }
                    else
                    {
                        int index = spline.ActivePoint;
                        points[index]   = originalPoints[index] + delta;
                        points[index].y = CourseBase.TerrainHeight(points[index].x, points[index].z);
                    }
                    spline.UpdateLine();
                }
            }
        }