示例#1
0
        /// <summary>
        /// Raycast against all hazards
        /// </summary>
        /// <param name="ray"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static HazardHit RaycastHazards(Ray ray, float distance = 10)
        {
            ray.direction = new Vector3(ray.direction.x, 0, ray.direction.z).normalized;

            HazardHit hit       = new HazardHit();
            bool      hitted    = false;
            bool      insideOOB = false;

            List <HazardBase> hazards = Hazards;

            for (int i = 0; i < hazards.Count; ++i)
            {
                HazardHit temp = new HazardHit();
                if (hazards[i].Raycast(ray, temp, distance))
                {
                    switch (temp.type)
                    {
                    case HazardBase.Type.Out_of_Bounds:
                        insideOOB = true;
                        break;

                    default:
                        hitted = true;
                        hit    = temp;
                        break;
                    }
                }
            }

            if (hitted)
            {
                return(hit);
            }
            else
            {
                if (insideOOB)
                {
                    return(hit);
                }
                else
                {
                    Layer layer = CourseBase.GetLayer(Utility.GetName(HazardBase.Type.Out_of_Bounds), CourseBase.HazardLayers);
                    if (Hazards.Find(x => x.Layer == layer))
                    {
                        hit.type       = HazardBase.Type.Out_of_Bounds;
                        hit.InstanceID = Hazards.Find(x => x.Layer == layer).Info.InstanceID;
                        return(hit);
                    }
                    else
                    {
                        hit.type = HazardBase.Type.Out_of_Bounds;
                        return(hit);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates spline
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static SplineBase CreateSpline(SplineBase.SplineInfo info)
        {
            SplineBase spline = CreateSpline(info.points.ToVector3(), CourseBase.GetLayer(info.layerName, SplineLayers), (SplineBase.SplineInfo.Flags)info.flags, info.InstanceID);

            spline.Info.pin = info.pin;

            spline.UpdateLine();
            splines.Add(spline);
            spline.LineChanged();

            return(spline);
        }
示例#3
0
        /// <summary>
        /// Update the lines
        /// </summary>
        /// <param name="spline"></param>
        public void UpdateLines(SplineBase spline)
        {
            if (spline.IsSquare)
            {
                List <Vector3> temp = editorPoints.ToList();
                temp.Add(temp[0]);
                editorLinesPoints = temp.ToArray();
            }
            else
            {
                editorLinesPoints = editorPoints.CatmullRom(spline.Layer.pointsPerEdge, true).ToArray();
            }
            if (spline.IsHazard)
            {
                editorLinesColors = new Color[editorLinesPoints.Length];

                string[] colorNames = spline.Info.colorNames;
                editorColors = new Color[colorNames.Length];
                for (int i = 0; i < colorNames.Length; ++i)
                {
                    editorColors[i] = CourseBase.GetLayer(colorNames[i], CourseBase.HazardLayers).hazardColor;
                }

                int step = (int)(editorLinesPoints.Length / editorPoints.Length);

                int index   = 0;
                int counter = 0;
                for (int i = 0; i < editorLinesPoints.Length; ++i)
                {
                    try
                    {
                        editorLinesColors[i] = editorColors[index];
                        counter++;
                        if (counter == step)
                        {
                            counter = 0;
                            if (index != editorPoints.Length - 1)
                            {
                                index++;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(editorColors.Length + "[" + index + "]");
                        Debug.LogException(e);
                    }
                }
            }

            editorBoxesPoints = new Vector3[editorPoints.Length * 9];
            for (int i = 0; i < editorPoints.Length; ++i)
            {
                editorBoxesPoints[i * 9 + 0].Set(editorPoints[i].x - Utility.squareHalf, editorPoints[i].y, editorPoints[i].z - Utility.squareHalf);
                editorBoxesPoints[i * 9 + 1].Set(editorPoints[i].x + Utility.squareHalf, editorPoints[i].y, editorPoints[i].z - Utility.squareHalf);
                editorBoxesPoints[i * 9 + 2].Set(editorPoints[i].x - Utility.squareHalf, editorPoints[i].y, editorPoints[i].z - Utility.squareHalf);
                editorBoxesPoints[i * 9 + 3].Set(editorPoints[i].x - Utility.squareHalf, editorPoints[i].y, editorPoints[i].z + Utility.squareHalf);
                editorBoxesPoints[i * 9 + 4].Set(editorPoints[i].x - Utility.squareHalf, editorPoints[i].y, editorPoints[i].z + Utility.squareHalf);
                editorBoxesPoints[i * 9 + 5].Set(editorPoints[i].x + Utility.squareHalf, editorPoints[i].y, editorPoints[i].z + Utility.squareHalf);
                editorBoxesPoints[i * 9 + 6].Set(editorPoints[i].x + Utility.squareHalf, editorPoints[i].y, editorPoints[i].z - Utility.squareHalf);
                editorBoxesPoints[i * 9 + 7].Set(editorPoints[i].x + Utility.squareHalf, editorPoints[i].y, editorPoints[i].z + Utility.squareHalf);
                editorBoxesPoints[i * 9 + 8].Set(0, float.PositiveInfinity, 0);
            }

            editorMin = editorLinesPoints[0];
            editorMax = editorLinesPoints[0];
            for (int i = 0; i < editorLinesPoints.Length; ++i)
            {
                if (editorLinesPoints[i].x < editorMin.x)
                {
                    editorMin.x = editorLinesPoints[i].x;
                }
                if (editorLinesPoints[i].y < editorMin.y)
                {
                    editorMin.y = editorLinesPoints[i].y;
                }
                if (editorLinesPoints[i].z < editorMin.z)
                {
                    editorMin.z = editorLinesPoints[i].z;
                }

                if (editorLinesPoints[i].x > editorMax.x)
                {
                    editorMax.x = editorLinesPoints[i].x;
                }
                if (editorLinesPoints[i].y > editorMax.y)
                {
                    editorMax.y = editorLinesPoints[i].y;
                }
                if (editorLinesPoints[i].z > editorMax.z)
                {
                    editorMax.z = editorLinesPoints[i].z;
                }
            }
            editorMin /= 1.01f;
            editorMax *= 1.01f;
        }