Exemple #1
0
 public void ClearSpline()
 {
     if (Spline)
     {
         Spline.Clear();
     }
 }
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(GameObject);

            if (go)
            {
                CurvySpline spl = go.GetComponent <CurvySpline>();
                if (spl)
                {
                    spl.Clear();
                    spl.Refresh();
                }
            }

            Finish();
        }
Exemple #3
0
        void OnGUI()
        {
            // before using the spline, ensure it's initialized and the Controller is available
            if (mSpline == null || !mSpline.IsInitialized || !Controller)
            {
                return;
            }

            var e = Event.current;

            switch (e.type)
            {
            case EventType.MouseDrag:
                // Start a new line?
                if (mResetSpline)
                {
                    mSpline.Clear();        // delete all Control Points
                    addCP(e.mousePosition); // add the first Control Point
                    Controller.gameObject.SetActive(true);
                    Controller.Position  = 0;
                    mLastControlPointPos = e.mousePosition;     // Store current mouse position
                    mResetSpline         = false;
                }
                else
                {
                    // only create a new Control Point if the minimum distance is reached
                    float dist = (e.mousePosition - mLastControlPointPos).magnitude;
                    if (dist >= StepDistance)
                    {
                        mLastControlPointPos = e.mousePosition;
                        addCP(e.mousePosition);
                        if (!Controller.IsPlaying)
                        {
                            Controller.Play();
                        }
                    }
                }

                break;

            case EventType.MouseUp:
                mResetSpline = true;

                break;
            }
        }
        public void DeserializeInto(CurvySpline spline, CurvySerializationSpace space = CurvySerializationSpace.WorldSpline, Action <CurvySplineSegment, string> onDeserializedCP = null)
        {
            if (spline)
            {
#if UNITY_EDITOR
                Undo.RegisterCompleteObjectUndo(spline, "Deserialize");
#endif

                if (!string.IsNullOrEmpty(Name))
                {
                    spline.name = Name;
                }
                spline.Clear();
                if (space == CurvySerializationSpace.Self)
                {
                    spline.transform.localPosition = P;
                    spline.transform.localRotation = Quaternion.Euler(R);
                }
                else
                {
                    spline.transform.position = P;
                    spline.transform.rotation = Quaternion.Euler(R);
                }
                spline.Interpolation      = Interpolation;
                spline.RestrictTo2D       = Keep2D;
                spline.Closed             = Closed;
                spline.AutoEndTangents    = AutoEndTangents;
                spline.Orientation        = Orientation;
                spline.AutoHandleDistance = BzAutoDist;
                spline.CacheDensity       = CacheDensity;
                spline.UsePooling         = Pooling;
                spline.UseThreading       = Threading;
                spline.CheckTransform     = CheckTForm;
                spline.UpdateIn           = UpdateIn;
                CurvySplineSegment cp;
                foreach (var serCP in ControlPoints)
                {
                    cp = serCP.Deserialize(spline, space);
                    if (onDeserializedCP != null)
                    {
                        onDeserializedCP(cp, serCP.Data);
                    }
                }
            }
        }
 // Update is called once per frame
 void Update()
 {
     if (Time.timeSinceLevelLoad - UpdateInterval * 0.001f > mLastUpdateTime)
     {
         mLastUpdateTime = Time.timeSinceLevelLoad;
         ExecTimes.Start();
         if (AlwaysClear)
         {
             mSpline.Clear();
         }
         // Remove old CP
         while (mSpline.ControlPointCount > CPCount)
         {
             mSpline.ControlPoints[0].Delete();
         }
         // Add new CP(s)
         while (mSpline.ControlPointCount <= CPCount)
         {
             addCP();
         }
         mSpline.Refresh();
         ExecTimes.Stop();
     }
 }