Example #1
0
        /// <summary>
        /// Undo-complient version of CurvyUtility.SplitSpline()
        /// </summary>
        /// <param name="firstCP">the first Control Point of the new spline</param>
        /// <returns>the new spline</returns>
        public static CurvySpline UndoSplitSpline(CurvySplineSegment firstCP)
        {
#if OLD_UNDO
            Undo.RegisterSceneUndo("Split Spline");
            return(CurvyUtility.SplitSpline(firstCP));
#else
            CurvySpline old = firstCP.Spline;
            CurvySpline spl = CurvySpline.Create(old);
            Undo.RegisterCreatedObjectUndo(spl.gameObject, "Split Spline");
            spl.name = old.name + "_parted";

            // Move CPs
            var affected = old.ControlPoints.GetRange(firstCP.ControlPointIndex, old.ControlPointCount - firstCP.ControlPointIndex);
            for (int i = 0; i < affected.Count; i++)
            {
                Undo.RecordObject(affected[i].gameObject, "Split Spline");
                Undo.SetTransformParent(affected[i].Transform, spl.Transform, "Split Spline");
                affected[i]._ReSettle();
            }
            old.ControlPoints.Clear();
            old.RefreshImmediately(true, true, false);
            spl._RenameControlPointsByIndex();
            spl.RefreshImmediately(true, true, false);
            return(spl);
#endif
        }
Example #2
0
        static void CreateCurvySpline()
        {
            CurvySpline spl = null;
            // If there's a Default Prefab, use that

            GameObject def = Resources.Load("DefaultCurvySpline") as GameObject;

            if (def)
            {
                GameObject splGO = PrefabUtility.InstantiatePrefab(def) as GameObject;
                if (splGO)
                {
                    PrefabUtility.DisconnectPrefabInstance(splGO);
                    splGO.name = "Curvy Spline";
                    spl        = splGO.GetComponent <CurvySpline>();
                }
            }
            if (spl == null)
            {
                // Otherwise create a spline from scratch
                spl = CurvySpline.Create();
                spl.Interpolation   = CurvyInterpolation.CatmulRom;
                spl.AutoEndTangents = true;
                spl.Closed          = true;
                spl.Add(new Vector3(-2, -1, 0), new Vector3(0, 2, 0), new Vector3(2, -1, 0));
            }
            Selection.activeObject = spl;
            Undo.RegisterCreatedObjectUndo(spl.gameObject, "Create Spline");
        }
Example #3
0
        public Component Create(CGModule module, string context)
        {
            var spl = CurvySpline.Create();

            spl.transform.position = Vector3.zero;
            spl.Closed             = true;
            spl.Add(new Vector3(0, 0, 0), new Vector3(5, 0, 10), new Vector3(-5, 0, 10));
            return(spl);
        }
Example #4
0
    static void CreateCurvySpline()
    {
        CurvySpline spl = CurvySpline.Create();

        spl.Interpolation   = CurvyInterpolation.CatmulRom;
        spl.AutoEndTangents = true;
        spl.Closed          = true;
        spl.Add(new Vector3(-2, -1, 0), new Vector3(0, 2, 0), new Vector3(2, -1, 0));
        Selection.activeObject = spl;
    }
Example #5
0
        public Component Create(CGModule module, string context)
        {
            var spl = CurvySpline.Create();

            spl.transform.position = Vector3.zero;
            spl.RestrictTo2D       = true;
            spl.Closed             = true;
            spl.Orientation        = CurvyOrientation.None;
            spl.gameObject.AddComponent <CSCircle>().Refresh();
            return(spl);
        }
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            CurvySpline spl = CurvySpline.Create();

            spl.Closed          = CloseSpline.Value;
            spl.AutoEndTangents = AutoEndTangents.Value;
            spl.CacheDensity    = CacheDensity.Value;
            spl.Orientation     = Orientation;
            storeObject.Value   = spl.gameObject;
            Finish();
        }
Example #7
0
        CurvySpline getSpline()
        {
            var spl = CurvySpline.Create();

            spl.Interpolation = mInterpolation;
            spl.Orientation   = mOrientation;
            spl.CacheDensity  = mCacheSize;
            spl.UseThreading  = mUseMultiThreads;
            spl.Refresh();
            return(spl);
        }
Example #8
0
 void checkForSpline()
 {
     if (Spline == null)
     {
         Spline = CurvySpline.Create();
         Camera.main.GetComponent <CurvyGLRenderer>().Add(Spline);
         for (int i = 0; i < 4; i++)
         {
             AddCP();
         }
     }
 }
Example #9
0
        public CurvySpline Deserialize(Transform parent = null, CurvySerializationSpace space = CurvySerializationSpace.WorldSpline, Action <CurvySplineSegment, string> onDeserializedCP = null)
        {
            var spl = CurvySpline.Create();

            if (!string.IsNullOrEmpty(Name))
            {
                spl.name = Name;
            }
#if UNITY_EDITOR
            Undo.RegisterCreatedObjectUndo(spl.gameObject, "Deserialize");
#endif
            spl.transform.SetParent(parent);
            DeserializeInto(spl, space, onDeserializedCP);
            return(spl);
        }
Example #10
0
    CurvySpline CreateSpline(CurvyInterpolation type, int points, int granularity)
    {
        CurvySpline spl = CurvySpline.Create();

        spl.Interpolation   = type;
        spl.Granularity     = granularity;
        spl.Closed          = false;
        spl.ShowGizmos      = false;
        spl.AutoEndTangents = true;
        for (int i = 0; i < points; i++)
        {
            spl.Add(null, false).Position = Random.insideUnitCircle * 10;
        }
        spl.RefreshImmediately();
        return(spl);
    }
Example #11
0
        /// <summary>
        /// Splits a spline
        /// </summary>
        /// <param name="firstCP">the first Control Point of the new spline</param>
        /// <returns>the new spline</returns>
        public static CurvySpline SplitSpline(CurvySplineSegment firstCP)
        {
            CurvySpline old = firstCP.Spline;
            CurvySpline spl = CurvySpline.Create(old);

            spl.name = old.name + "_parted";

            // Move CPs
            var affected = old.ControlPoints.GetRange(firstCP.ControlPointIndex, old.ControlPointCount - firstCP.ControlPointIndex);

            for (int i = 0; i < affected.Count; i++)
            {
                affected[i].Transform.parent = spl.Transform;
                affected[i]._ReSettle();
            }
            old.ControlPoints.Clear();
            old.RefreshImmediately(true, true, false);
            spl._RenameControlPointsByIndex();
            spl.RefreshImmediately(true, true, false);
            return(spl);
        }