Exemple #1
0
        static void CheckSplines()
        {
            List <HazardBase> hazards = Hazards;

            for (int i = 0; i < hazards.Count; ++i)
            {
                HazardBase hazard = hazards[i];

                if (hazard.Info.layerName == "NoLayerName")
                {
                    hazard.Info.layerName = GetLayer(hazard.Info.layerIndex, Layers).name;
                }

                if (hazard.Info.colorNames.Length == 0)
                {
                    hazard.Info.colorNames = new string[hazard.Info.colorIndex.Length];
                    for (int j = 0; j < hazard.Info.colorNames.Length; ++j)
                    {
                        hazard.Info.colorNames[j] = GetLayer(hazard.Info.colorIndex[j], HazardLayers).name;
                    }
                }
            }

            List <SplineBase> splines = Splines;

            for (int i = 0; i < splines.Count; ++i)
            {
                SplineBase spline = splines[i];

                if (spline.Info.pin)
                {
                    MonoBehaviour.DestroyImmediate(spline.gameObject);
                    splines.Remove(spline);
                    i = -1;
                    continue;
                }

                if (spline.Info.layerName == "NoLayerName")
                {
                    spline.Info.layerName = GetLayer(spline.Info.layerIndex, Layers).name;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates hazard
        /// </summary>
        /// <param name="points"></param>
        /// <param name="layer"></param>
        /// <param name="flags"></param>
        /// <param name="rearrange"></param>
        /// <returns></returns>
        public static HazardBase CreateHazard(Vector3[] points, Layer layer, SplineBase.SplineInfo.Flags flags, bool rearrange = false)
        {
            if ((flags & SplineBase.SplineInfo.Flags.Square) == 0 || rearrange)
            {
                points = points.ToList().RearrangePoints(layer.metersPerOnePoint).ToArray();
            }
            if (points.Length < 3)
            {
                return(null);
            }

            int instanceID = FreeSplineInstanceID();

            GameObject gameObject = new GameObject("Hazard " + instanceID.ToString());

            if (PlatformBase.IO.IsEditor)
            {
                PlatformBase.Editor.RegisterCreatedObjectUndo(gameObject, "Spline tool Creation");
                PlatformBase.Editor.SetStaticFlags(gameObject);
                gameObject.hideFlags = HideFlags.HideInHierarchy;
            }

            HazardBase hazard = (HazardBase)gameObject.AddComponent(Types.GetType("PerfectParallel.CourseForge.Hazard", "Assembly-CSharp"));

            hazard.Info.layerName = layer.name;
            hazard.Points         = (Vector3[])points.Clone();

            hazard.Info.colorNames = new string[points.Length];
            for (int i = 0; i < hazard.Info.colorNames.Length; ++i)
            {
                hazard.Info.colorNames[i] = layer.name;
            }

            hazard.Info.flags      = (int)flags;
            hazard.Info.InstanceID = instanceID;

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

            return(hazard);
        }