Ejemplo n.º 1
0
        void SplitAtPoint(int index, ref SplinePoint[] points)
        {
            Undo.RecordObject(computer, "Split At Point " + index);
            EditorUtility.SetDirty(computer);
            SplinePoint[] splitPoints = new SplinePoint[computer.pointCount - index];
            for (int i = 0; i < splitPoints.Length; i++)
            {
                splitPoints[i] = computer.GetPoint(index + i);
            }
            SplineComputer spline = CreateNewSpline();

            spline.SetPoints(splitPoints);

            SplineUser[] users = spline.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp((double)index / (computer.pointCount - 1), 1.0, users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp((double)index / (computer.pointCount - 1), 1.0, users[i].clipTo);
            }
            splitPoints = new SplinePoint[index + 1];
            for (int i = 0; i <= index; i++)
            {
                splitPoints[i] = computer.GetPoint(i);
            }
            points = splitPoints;
            users  = computer.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp(0.0, ((double)index) / (computer.pointCount - 1), users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp(0.0, ((double)index) / (computer.pointCount - 1), users[i].clipTo);
            }
            HandleNodes(spline, index);
        }
Ejemplo n.º 2
0
 void MergeComputer(SplineComputer from, double mapFrom, double mapTo)
 {
     SplineUser[] subs = from.GetSubscribers();
     for (int i = 0; i < subs.Length; i++)
     {
         from.Unsubscribe(subs[i]);
         subs[i].computer = computer;
         subs[i].clipFrom = DMath.Lerp(mapFrom, mapTo, subs[i].clipFrom);
         subs[i].clipTo   = DMath.Lerp(mapFrom, mapTo, subs[i].clipTo);
     }
     if (EditorUtility.DisplayDialog("Keep merged computer's GameObject?", "Do you want to keep the merged computer's game object? This will transfer all subscribed users to the current computer.", "Yes", "No"))
     {
         GameObject.DestroyImmediate(from);
     }
     else
     {
         GameObject.DestroyImmediate(from.gameObject);
     }
 }
Ejemplo n.º 3
0
        void SplitAtPercent(double percent, ref SplinePoint[] points)
        {
            Undo.RecordObject(computer, "Split At Percent ");
            EditorUtility.SetDirty(computer);
            float pointValue     = (computer.pointCount - 1) * (float)percent;
            int   lastPointIndex = Mathf.FloorToInt(pointValue);
            int   nextPointIndex = Mathf.CeilToInt(pointValue);

            SplinePoint[] splitPoints = new SplinePoint[computer.pointCount - lastPointIndex];
            float         lerpPercent = Mathf.InverseLerp(lastPointIndex, nextPointIndex, pointValue);
            SplinePoint   splitPoint  = SplinePoint.Lerp(computer.GetPoint(lastPointIndex), computer.GetPoint(nextPointIndex), lerpPercent);

            splitPoint.SetPosition(computer.EvaluatePosition(percent));
            splitPoints[0] = splitPoint;
            for (int i = 1; i < splitPoints.Length; i++)
            {
                splitPoints[i] = computer.GetPoint(lastPointIndex + i);
            }
            SplineComputer spline = CreateNewSpline();

            spline.SetPoints(splitPoints);
            SplineUser[] users = spline.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp(percent, 1.0, users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp(percent, 1.0, users[i].clipTo);
            }
            splitPoints = new SplinePoint[lastPointIndex + 2];
            for (int i = 0; i <= lastPointIndex; i++)
            {
                splitPoints[i] = computer.GetPoint(i);
            }
            splitPoints[splitPoints.Length - 1] = splitPoint;
            points = splitPoints;
            users  = computer.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp(0.0, percent, users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp(0.0, percent, users[i].clipTo);
            }
            HandleNodes(spline, lastPointIndex);
        }