コード例 #1
0
    void Update()
    {
        var enterList = CreatePathManager.GetSplineComputers(connectingSpline.GetPoints().First().position);

        if (enterList.Count != 0)
        {
            enterRoad = enterList[0];
        }
        else
        {
            if (enterRoad)
            {
                enterRoad = null;
            }
        }

        var exitList = CreatePathManager.GetSplineComputers(connectingSpline.GetPoints().Last().position);

        if (exitList.Count != 0)
        {
            exitRoad = exitList[0];
        }
        else
        {
            if (exitRoad)
            {
                exitRoad = null;
            }
        }
    }
コード例 #2
0
 public void DestroyTheLastX(int numberOfSegment)
 {
     SplinePoint[] actualPoints = spline.GetPoints();
     SplinePoint[] newPoints    = new SplinePoint[actualPoints.Length - numberOfSegment];
     for (int i = 0; i < newPoints.Length; i++)
     {
         newPoints[i] = actualPoints[i];
     }
     spline.SetPoints(newPoints);
     waitForEndOfFrame             = true;
     splineFollower.result.percent = (double)(splineFollower.result.percent * ((double)1 + (double)1 / (double)spline.pointCount));
 }
コード例 #3
0
ファイル: SplineComputerEditor.cs プロジェクト: Wanyea/Galaga
 public void UndoRedoPerformed()
 {
     pathEditor.points = spline.GetPoints();
     pathEditor.UndoRedoPerformed();
     spline.EditorUpdateConnectedNodes();
     spline.Rebuild();
 }
コード例 #4
0
        public static double ScreenPointToSplinePercent(SplineComputer computer, Vector2 screenPoint)
        {
            SplinePoint[] points          = computer.GetPoints();
            float         closestDistance = (screenPoint - HandleUtility.WorldToGUIPoint(points[0].position)).sqrMagnitude;
            double        closestPercent  = 0.0;
            double        add             = computer.moveStep;

            if (computer.type == Spline.Type.Linear)
            {
                add /= 2f;
            }
            int count = 0;

            for (double i = add; i < 1.0; i += add)
            {
                SplineSample result = computer.Evaluate(i);
                Vector2      point  = HandleUtility.WorldToGUIPoint(result.position);
                float        dist   = (point - screenPoint).sqrMagnitude;
                if (dist < closestDistance)
                {
                    closestDistance = dist;
                    closestPercent  = i;
                }
                count++;
            }
            return(closestPercent);
        }
コード例 #5
0
 private void Start()
 {
     points        = splineComputer.GetPoints();
     _planeRigid   = gameObject.GetComponent <Rigidbody>();
     _speed        = 1100;
     checkPointNow = 0;
 }
コード例 #6
0
 public virtual void Init(SplineComputer comp)
 {
     computer   = comp;
     lastClosed = comp.isClosed;
     lastType   = comp.type;
     lastPoints = comp.GetPoints(SplineComputer.Space.Local);
 }
コード例 #7
0
 public void Refresh()
 {
     points     = spline.GetPoints();
     isClosed   = spline.isClosed;
     splineType = spline.type;
     sampleRate = spline.sampleRate;
     is2D       = spline.is2D;
     color      = spline.editorPathColor;
 }
コード例 #8
0
 public void Refresh()
 {
     _matrix    = _transform.localToWorldMatrix;
     points     = spline.GetPoints();
     isClosed   = spline.isClosed;
     splineType = spline.type;
     sampleRate = spline.sampleRate;
     is2D       = spline.is2D;
     color      = spline.editorPathColor;
 }
コード例 #9
0
    private void CreateAPointClampSpline(SplinePoint newPoint)
    {
        SplinePoint[] actualPoints = spline.GetPoints();
        SplinePoint[] newPoints    = new SplinePoint[actualPoints.Length];
        //Set each point's properties
        // on doit parcourir tout le tableau précédent sauf le premier
        for (int i = 1; i < newPoints.Length; i++)
        {
            newPoints[i - 1]          = new SplinePoint();
            newPoints[i - 1].position = actualPoints[i].position;
            newPoints[i - 1].normal   = actualPoints[i].normal;
            newPoints[i - 1].size     = actualPoints[i].size;
            newPoints[i - 1].color    = actualPoints[i].color;
        }
        //on add à la fin de la spline le nvx point
        newPoints[newPoints.Length - 1] = newPoint;

        //Write the points to the spline
        spline.SetPoints(newPoints);
    }
コード例 #10
0
 private void CreateAPoint(SplinePoint newPoint)
 {
     SplinePoint[] actualPoints = spline.GetPoints();
     SplinePoint[] newPoints    = new SplinePoint[actualPoints.Length + 1];
     for (int i = 0; i < actualPoints.Length; i++)
     {
         newPoints[i] = actualPoints[i];
     }
     newPoints[newPoints.Length - 1] = newPoint;
     spline.SetPoints(newPoints);
 }
コード例 #11
0
 // Use this for initialization
 void Start()
 {
     source   = GetComponent <AudioSource>();
     computer = GetComponent <SplineComputer>();
     SplinePoint[] points = computer.GetPoints();
     positions = new Vector3[points.Length];
     for (int i = 0; i < points.Length; i++)
     {
         positions[i] = points[i].position;
     }
     spectrumLerp = new float[points.Length];
 }
コード例 #12
0
    private void SetupFollower(SplineComputer splineComputer)
    {
        _splineFollower        = _player.GetComponent <SplineFollower>();
        _splineFollower.spline = splineComputer;

        //To limit player's path to finish line ( last-1th point ) Last point setted for the path between Finish line and chest.
        var clipToPercent = splineComputer.GetPointPercent(splineComputer.GetPoints().Length - 2);

        _splineFollower.clipTo = clipToPercent;

        _splineFollower.onMotionApplied += OnPlayerMoved;
    }
コード例 #13
0
            public void GetReferences()
            {
                if (transform == null)
                {
                    Debug.LogError("Null transform found for property");
                    return;
                }
                settingsComponent = transform.GetComponent <SegmentObjectSettings>();
                meshFilter        = transform.GetComponent <MeshFilter>();
                spriteRenderer    = transform.GetComponent <SpriteRenderer>();
                if (spriteRenderer == null || spriteRenderer.sprite == null)
                {
                    extrusionSettings.bendSprite = false;
                }
                if (extrusionSettings.bendMesh && meshFilter.sharedMesh == null)
                {
                    extrusionSettings.bendMesh = false;
                }
                colliders = transform.GetComponents <Collider>();
                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i] is MeshCollider)
                    {
                        meshCollider = (MeshCollider)colliders[i];
                        break;
                    }
                }
                localRotation = Quaternion.Inverse(transform.root.rotation) * transform.rotation;
#if DREAMTECK_SPLINES
                if (extrusionSettings.bendSpline)
                {
                    if (!isRoot)
                    {
                        splineComputer = transform.GetComponent <SplineComputer>();
                        if (splineComputer != null)
                        {
                            editSplinePoints = splineComputer.GetPoints();
                        }
                        else
                        {
                            extrusionSettings.bendSpline = false;
                        }
                    }
                    else
                    {
                        extrusionSettings.bendSpline = false;
                    }
                }
#endif
            }
コード例 #14
0
        private void OnDrawGizmosSelected()
        {
            if (_spline == null)
            {
                _spline = GetComponent <SplineComputer>();
            }
            var points = _spline.GetPoints();

            for (var i = 0; i < points.Length; i++)
            {
                var point = _spline.Evaluate(i);
                Gizmos.color = Color.black;
                Gizmos.DrawSphere(point.position, 0.1f);
                if (showUp)
                {
                    Gizmos.color = Color.green;
                    Gizmos.DrawLine(point.position, point.position + point.normal * _length);
                }
                if (showForward)
                {
                    Gizmos.color = Color.blue;
                    Gizmos.DrawLine(point.position, point.position + point.direction * _length);
                }
                if (showRight)
                {
                    Gizmos.color = Color.red;
                    Gizmos.DrawLine(point.position, point.position + point.right * _length);
                    if (showXz)
                    {
                        var r = point.right;
                        r.y = 0f;
                        Gizmos.DrawLine(point.position, point.position + r * _length);
                    }
                }
                if (i > 0)
                {
                    var point2 = _spline.Evaluate(i - 1);
                    if (showUp)
                    {
                        Gizmos.color = Color.green;
                        Gizmos.DrawLine(point2.position + point2.normal * _length, point.position + point.normal * _length);
                    }
                    if (showRight)
                    {
                        Gizmos.color = Color.red;
                        Gizmos.DrawLine(point2.position + point2.right * _length, point.position + point.right * _length);
                    }
                }
            }
        }
コード例 #15
0
        Vector3 GetOrigin(SplineComputer comp)
        {
            Vector3 avg = Vector3.zero;

            SplinePoint[] points = comp.GetPoints(SplineComputer.Space.Local);
            for (int i = 0; i < comp.pointCount; i++)
            {
                avg += points[i].position;
            }
            if (points.Length > 0)
            {
                avg /= points.Length;
            }
            return(avg);
        }
コード例 #16
0
    /// <summary>
    /// Sets up all protected parameters.
    /// </summary>
    /// <param name="parent"> Object in the scene (called RuntimeRows) that is a parent to all generated rows of elements. </param>
    protected void SetupNet(Transform parent)
    {
        knotClone = GameObject.Find("KnotForNet");
        UpdateKnot();

        knotClone.transform.parent = parent;
        knotClone.tag   = "knotrow";
        knotClone.layer = 9;

        splineComputer    = knotClone.GetComponent <SplineComputer>();
        basePoints        = splineComputer.GetPoints();
        basePointCount    = basePoints.Length;
        currentPointCount = basePointCount;
        point_size        = splineComputer.GetPointSize(0);
        updateValues      = false;
    }
コード例 #17
0
        public CSV(SplineComputer computer)
        {
            Spline spline = new Spline(computer.type, computer.sampleRate);

            spline.points = computer.GetPoints();
            if (spline.type != Spline.Type.Bezier && spline.type != Spline.Type.Linear)
            {
                spline.CatToBezierTangents();
            }
            if (computer.isClosed)
            {
                spline.Close();
            }
            buffer   = new SplineDefinition(computer.name, spline);
            fileName = computer.name;
            columns.Add(ColumnType.Position);
            columns.Add(ColumnType.Tangent);
            columns.Add(ColumnType.Tangent2);
        }
コード例 #18
0
        // Update is called once per frame
        void Update()
        {
            float[] left  = new float[samples];
            float[] right = new float[samples];
            source.GetSpectrumData(left, 0, FFTWindow.Hanning);
            source.GetSpectrumData(right, 1, FFTWindow.Hanning);
            float[] spectrum = new float[left.Length];
            for (int i = 0; i < spectrum.Length; i++)
            {
                spectrum[i] = (left[i] + right[i]) / 2f;
            }
            SplinePoint[] points = computer.GetPoints();
            if (spectrumPercent > 1f)
            {
                spectrumPercent = 1f;
            }
            int samplesPerPoint = Mathf.FloorToInt((spectrum.Length / points.Length) * spectrumPercent);

            for (int i = 0; i < points.Length; i++)
            {
                float avg = 0f;
                for (int n = samplesPerPoint * i; n < samplesPerPoint * i + samplesPerPoint; n++)
                {
                    avg += spectrum[n];
                }
                avg /= samplesPerPoint;
                if (avg > spectrumLerp[i])
                {
                    spectrumLerp[i] = Mathf.Lerp(spectrumLerp[i], avg, Time.deltaTime * increaseSpeed);
                }
                else
                {
                    spectrumLerp[i] = Mathf.Lerp(spectrumLerp[i], avg, Time.deltaTime * decreaseSpeed);
                }

                float percent = (float)i / (points.Length - 1);
                points[i].position = positions[i] + Vector3.up * maxOffset * spectrumLerp[i] * spectrumMultiply.Evaluate(percent);
            }
            computer.SetPoints(points);
        }
コード例 #19
0
 void ReversePointOrder(SplineComputer spline)
 {
     SplinePoint[] points = spline.GetPoints();
     for (int i = 0; i < Mathf.FloorToInt(points.Length / 2); i++)
     {
         SplinePoint temp = points[i];
         points[i] = points[(points.Length - 1) - i];
         Vector3 tempTan = points[i].tangent;
         points[i].tangent  = points[i].tangent2;
         points[i].tangent2 = tempTan;
         int opposideIndex = (points.Length - 1) - i;
         points[opposideIndex] = temp;
         tempTan = points[opposideIndex].tangent;
         points[opposideIndex].tangent  = points[opposideIndex].tangent2;
         points[opposideIndex].tangent2 = tempTan;
     }
     if (points.Length % 2 != 0)
     {
         Vector3 tempTan = points[Mathf.CeilToInt(points.Length / 2)].tangent;
         points[Mathf.CeilToInt(points.Length / 2)].tangent  = points[Mathf.CeilToInt(points.Length / 2)].tangent2;
         points[Mathf.CeilToInt(points.Length / 2)].tangent2 = tempTan;
     }
     spline.SetPoints(points);
 }
コード例 #20
0
    /// <summary>
    /// Coroutine invokes when tentacle catch human
    /// </summary>
    IEnumerator TentacleCoroutineDecrease(GameObject human)

    {
        while (human.transform.position != LevelManager.StartPoint)
        {
            SplinePoint[] points     = _splineComputer.GetPoints();
            SplinePoint[] newPoints  = new SplinePoint[_splineComputer.pointCount - 1];
            Vector3       humanPoint = new Vector3();
            for (int i = 0; i < newPoints.Length; i++)
            {
                newPoints[i] = points[i];
                if (i == newPoints.Length - 1)
                {
                    humanPoint = (newPoints[i].position);
                }
            }

            human.transform.position = humanPoint;
            _splineComputer.SetPoints(newPoints);

            if (Vector3.Distance(human.transform.position, LevelManager.StartPoint) < 1f)
            {
                DeathVFX();
                _levelManager.DestroyHumans(human);
                Destroy(human);
                SetStartPoint();
                StopAllCoroutines();
                _humansKilled++;
                if (_humansKilled == Level.HumansCount)
                {
                    _levelManager.MissionComplete();
                }
            }
            yield return(new WaitForSeconds(_tentacleSpeedBack));
        }
    }
コード例 #21
0
        public static void DrawSplineComputer(SplineComputer comp, double fromPercent = 0.0, double toPercent = 1.0, float alpha = 1f)
        {
            if (comp == null)
            {
                return;
            }
            Color prevColor   = Handles.color;
            Color orange      = new Color(1f, 0.564f, 0f);
            Color handleColor = comp.editorPathColor;

            handleColor.a = alpha;
            Handles.color = handleColor;
            if (comp.pointCount < 2)
            {
                return;
            }

            if (comp.type == Spline.Type.BSpline && comp.pointCount > 1)
            {
                SplinePoint[] compPoints = comp.GetPoints();
                Handles.color = new Color(handleColor.r, handleColor.g, handleColor.b, 0.5f * alpha);
                for (int i = 0; i < compPoints.Length - 1; i++)
                {
                    Handles.DrawLine(compPoints[i].position, compPoints[i + 1].position);
                }
                Handles.color = handleColor;
            }

            if (!comp.drawThinckness)
            {
                if (positions.Length != comp.sampleCount * 2)
                {
                    positions = new Vector3[comp.sampleCount * 2];
                }
                Vector3 prevPoint  = comp.EvaluatePosition(fromPercent);
                int     pointIndex = 0;
                for (int i = 1; i < comp.sampleCount; i++)
                {
                    positions[pointIndex] = prevPoint;
                    pointIndex++;
                    positions[pointIndex] = comp.samples[i].position;
                    pointIndex++;
                    prevPoint = positions[pointIndex - 1];
                }
                Handles.DrawLines(positions);
            }
            else
            {
                Transform editorCamera = SceneView.currentDrawingSceneView.camera.transform;
                if (positions.Length != comp.sampleCount * 6)
                {
                    positions = new Vector3[comp.sampleCount * 6];
                }
                SplineSample prevResult = comp.Evaluate(fromPercent);
                Vector3      prevNormal = prevResult.normal;
                if (comp.billboardThickness)
                {
                    prevNormal = (editorCamera.position - prevResult.position).normalized;
                }
                Vector3 prevRight  = Vector3.Cross(prevResult.direction, prevNormal).normalized *prevResult.size * 0.5f;
                int     pointIndex = 0;
                for (int i = 1; i < comp.sampleCount; i++)
                {
                    SplineSample newResult = comp.samples[i];
                    Vector3      newNormal = newResult.normal;
                    if (comp.billboardThickness)
                    {
                        newNormal = (editorCamera.position - newResult.position).normalized;
                    }
                    Vector3 newRight = Vector3.Cross(newResult.direction, newNormal).normalized *newResult.size * 0.5f;

                    positions[pointIndex] = prevResult.position + prevRight;
                    positions[pointIndex + comp.sampleCount * 2] = prevResult.position - prevRight;
                    positions[pointIndex + comp.sampleCount * 4] = newResult.position - newRight;
                    pointIndex++;
                    positions[pointIndex] = newResult.position + newRight;
                    positions[pointIndex + comp.sampleCount * 2] = newResult.position - newRight;
                    positions[pointIndex + comp.sampleCount * 4] = newResult.position + newRight;
                    pointIndex++;
                    prevResult = newResult;
                    prevRight  = newRight;
                    prevNormal = newNormal;
                }
                Handles.DrawLines(positions);
            }
            Handles.color = prevColor;
        }
コード例 #22
0
ファイル: NodeEditor.cs プロジェクト: Tim-dev-hub/Road-puzzle
        protected virtual void OnSceneGUI()
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            for (int i = 0; i < connections.Length; i++)
            {
                DSSplineDrawer.DrawSplineComputer(connections[i].spline, 0.0, 1.0, 0.5f);
            }

            bool update = false;

            if (position != node.transform.position)
            {
                position = node.transform.position;
                update   = true;
            }
            if (scale != node.transform.localScale)
            {
                scale  = node.transform.localScale;
                update = true;
            }
            if (rotation != node.transform.rotation)
            {
                rotation = node.transform.rotation;
                update   = true;
            }
            if (update)
            {
                node.UpdateConnectedComputers();
            }

            if (addComp == null)
            {
                if (connections.Length > 0)
                {
                    bool bezier = false;
                    for (int i = 0; i < connections.Length; i++)
                    {
                        if (connections[i].spline == null)
                        {
                            continue;
                        }
                        if (connections[i].spline.type == Spline.Type.Bezier)
                        {
                            bezier = true;
                            continue;
                        }
                    }
                    if (bezier && node.type == Node.Type.Smooth)
                    {
                        if (connections[0].spline != null)
                        {
                            SplinePoint point = node.GetPoint(0, true);
                            Handles.DrawDottedLine(node.transform.position, point.tangent, 6f);
                            Handles.DrawDottedLine(node.transform.position, point.tangent2, 6f);
                            Vector3 lastPos  = point.tangent;
                            bool    setPoint = false;
                            point.SetTangentPosition(Handles.PositionHandle(point.tangent, node.transform.rotation));
                            if (lastPos != point.tangent)
                            {
                                setPoint = true;
                            }
                            lastPos = point.tangent2;
                            point.SetTangent2Position(Handles.PositionHandle(point.tangent2, node.transform.rotation));
                            if (lastPos != point.tangent2)
                            {
                                setPoint = true;
                            }

                            if (setPoint)
                            {
                                node.SetPoint(0, point, true);
                                node.UpdateConnectedComputers();
                            }
                        }
                    }
                }
                return;
            }
            SplinePoint[] points       = addComp.GetPoints();
            Transform     camTransform = SceneView.currentDrawingSceneView.camera.transform;

            DSSplineDrawer.DrawSplineComputer(addComp, 0.0, 1.0, 0.5f);
            TextAnchor originalAlignment = GUI.skin.label.alignment;
            Color      originalColor     = GUI.skin.label.normal.textColor;

            GUI.skin.label.alignment        = TextAnchor.MiddleCenter;
            GUI.skin.label.normal.textColor = addComp.editorPathColor;
            for (int i = 0; i < availablePoints.Length; i++)
            {
                if (addComp.isClosed && i == points.Length - 1)
                {
                    break;
                }

                Handles.Label(points[i].position + Camera.current.transform.up * HandleUtility.GetHandleSize(points[i].position) * 0.3f, (i + 1).ToString());
                if (SplineEditorHandles.CircleButton(points[availablePoints[i]].position, Quaternion.LookRotation(-camTransform.forward, camTransform.up), HandleUtility.GetHandleSize(points[availablePoints[i]].position) * 0.1f, 2f, addComp.editorPathColor))
                {
                    AddConnection(addComp, availablePoints[i]);
                    break;
                }
            }
            GUI.skin.label.alignment        = originalAlignment;
            GUI.skin.label.normal.textColor = originalColor;
        }
コード例 #23
0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text.RegularExpressions;

namespace Dreamteck.Splines.IO
{
    public class CSV : SplineParser
    {
        public enum ColumnType { Position, Tangent, Tangent2, Normal, Size, Color }
        public List<ColumnType> columns = new List<ColumnType>();

        private System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
        private System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Any;

        public CSV(SplineComputer computer)
        {
            Spline spline = new Spline(computer.type, computer.sampleRate);
            spline.points = computer.GetPoints();
            if (spline.type != Spline.Type.Bezier && spline.type != Spline.Type.Linear) spline.CatToBezierTangents();
            if (computer.isClosed) spline.Close();
            buffer = new SplineDefinition(computer.name, spline);
            fileName = computer.name;
            columns.Add(ColumnType.Position);
            columns.Add(ColumnType.Tangent);
            columns.Add(ColumnType.Tangent2);
        }

        public CSV(string filePath, List<ColumnType> customColumns = null)
        {
            if (File.Exists(filePath))
            {
                string ext = Path.GetExtension(filePath).ToLower();
                fileName = Path.GetFileNameWithoutExtension(filePath);
                if (ext != ".csv")
                {
                    Debug.LogError("CSV Parsing ERROR: Wrong format. Please use SVG or XML");
                    return;
                }
                string[] lines = File.ReadAllLines(filePath);
                if (customColumns == null)
                {
                    columns.Add(ColumnType.Position);
                    columns.Add(ColumnType.Tangent);
                    columns.Add(ColumnType.Tangent2);
                    columns.Add(ColumnType.Normal);
                    columns.Add(ColumnType.Size);
                    columns.Add(ColumnType.Color);
                } else columns = new List<ColumnType>(customColumns);
                buffer = new SplineDefinition(fileName, Spline.Type.CatmullRom);
                Read(lines);
            }
        }

        void Read(string[] lines)
        {
            int expectedElementCount = 0;
            foreach (ColumnType col in columns)
            {
                switch (col)
                {
                    case ColumnType.Position: expectedElementCount +=3; break;
                    case ColumnType.Tangent: expectedElementCount += 3; break;
                    case ColumnType.Tangent2: expectedElementCount += 3; break;
                    case ColumnType.Normal: expectedElementCount += 3; break;
                    case ColumnType.Size: expectedElementCount ++; break;
                    case ColumnType.Color: expectedElementCount += 4; break;
                }
            }
            for (int i = 1; i < lines.Length; i++)
            {
                lines[i] = Regex.Replace(lines[i], @"\s+", "");
                string[] elements = lines[i].Split(',');
                if(elements.Length != expectedElementCount)
                {
                    Debug.LogError("Unexpected element count on row " + i + ". Expected " + expectedElementCount +  " found " + elements.Length + " Please make sure that all values exist and the column order is correct.");
                    continue;
                }
                float[] values = new float[elements.Length];
                for (int j = 0; j < elements.Length; j++)
                {
                    float.TryParse(elements[j], style, culture, out values[j]);
                }
                int currentValue = 0;
                foreach (ColumnType col in columns)
                {
                    switch (col)
                    {
                        case ColumnType.Position: buffer.position = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Tangent: buffer.tangent = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Tangent2: buffer.tangent2 = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Normal: buffer.normal = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Size: buffer.size = values[currentValue++]; break;
                        case ColumnType.Color: buffer.color = new Color(values[currentValue++], values[currentValue++], values[currentValue++], values[currentValue++]); break;
                    }
                }
                buffer.CreateSmooth();
            }
        }

        public SplineComputer CreateSplineComputer(Vector3 position, Quaternion rotation)
        {
            return buffer.CreateSplineComputer(position, rotation);
        }

        public Spline CreateSpline()
        {
            return buffer.CreateSpline();
        }


        public void FlatX()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.x = 0f;
                p.tangent.x = 0f;
                p.tangent2.x = 0f;
                p.normal = Vector3.right;
                buffer.points[i] = p;
            }
        }

        public void FlatY()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.y = 0f;
                p.tangent.y = 0f;
                p.tangent2.y = 0f;
                p.normal = Vector3.up;
                buffer.points[i] = p;
            }
        }

        public void FlatZ()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.z = 0f;
                p.tangent.z = 0f;
                p.tangent2.z = 0f;
                p.normal = Vector3.back;
                buffer.points[i] = p;
            }
        }

        void AddTitle(ref string[] content, string title)
        {
            if (!string.IsNullOrEmpty(content[0])) content[0] += ",";
            content[0] += title;
        }

        void AddVector3Title(ref string[] content, string prefix)
        {
            AddTitle(ref content, prefix + "X," + prefix + "Y," + prefix + "Z");
        }

        void AddColorTitle(ref string[] content, string prefix)
        {
            AddTitle(ref content, prefix + "R," + prefix + "G," + prefix + "B" + prefix + "A");
        }

        void AddVector3(ref string[] content, int index, Vector3 vector)
        {
            AddFloat(ref content, index, vector.x);
            AddFloat(ref content, index, vector.y);
            AddFloat(ref content, index, vector.z);
        }

        void AddColor(ref string[] content, int index, Color color)
        {
            AddFloat(ref content, index, color.r);
            AddFloat(ref content, index, color.g);
            AddFloat(ref content, index, color.b);
            AddFloat(ref content, index, color.a);
        }

        void AddFloat(ref string[] content, int index, float value)
        {
            if (!string.IsNullOrEmpty(content[index])) content[index] += ",";
            content[index] += value.ToString();
        }

        public void Write(string filePath)
        {
            if (!Directory.Exists(Path.GetDirectoryName(filePath)))  throw new DirectoryNotFoundException("The file is being saved to a non-existing directory.");
            List<SplinePoint> csvPoints = buffer.points;
            string[] content = new string[csvPoints.Count+1];
            //Add the column titles
            foreach(ColumnType col in columns)
            {
                switch (col)
                {
                    case ColumnType.Position: AddVector3Title(ref content, "Position"); break;
                    case ColumnType.Tangent: AddVector3Title(ref content, "Tangent"); break;
                    case ColumnType.Tangent2: AddVector3Title(ref content, "Tangent2"); break;
                    case ColumnType.Normal: AddVector3Title(ref content, "Normal"); break;
                    case ColumnType.Size: AddTitle(ref content, "Size"); break;
                    case ColumnType.Color: AddColorTitle(ref content, "Color"); break;
                }
            }
            //Add the content for each column
            foreach (ColumnType col in columns)
            {
                for (int i = 1; i <= csvPoints.Count; i++)
                {
                    int index = i - 1;
                    switch (col)
                    {
                        case ColumnType.Position: AddVector3(ref content, i, csvPoints[index].position); break;
                        case ColumnType.Tangent: AddVector3(ref content, i, csvPoints[index].tangent); break;
                        case ColumnType.Tangent2: AddVector3(ref content, i, csvPoints[index].tangent2); break;
                        case ColumnType.Normal: AddVector3(ref content, i, csvPoints[index].normal); break;
                        case ColumnType.Size: AddFloat(ref content, i, csvPoints[index].size); break;
                        case ColumnType.Color: AddColor(ref content, i, csvPoints[index].color); break;
                    }
                }
            }
            File.WriteAllLines(filePath, content);
        }
    }
}
コード例 #24
0
    void Start()
    {
        Constants.gameOver = false;
        if (Constants.difficulty == Constants.Difficulty.HARD || Constants.difficulty == Constants.Difficulty.IMPOSSIBLE)
        {
            Constants.numSections = 3;
        }
        else
        {
            Constants.numSections = 2;
        }
        Time.timeScale   = 1;
        inv              = Inventory.Instance;
        activeBuildZones = new List <BuildZone>();
        List <SplinePoint> splinePoints = new List <SplinePoint>();

        splinePoints.AddRange(masterSpline.GetPoints());

        for (int i = 0; i <= Constants.numSections; i++)
        {
            GameObject current = null;
            if (i == Constants.numSections)
            {
                current = Instantiate(sections[0], new Vector3(19.2f + (38.4f * i), sections[0].transform.position.y, 0), Quaternion.identity);
            }
            else
            {
                int ind = Random.Range(1, sections.Length);
                current = Instantiate(sections[ind], new Vector3(28.8f + (38.4f * i), sections[ind].transform.position.y, 0), Quaternion.identity);
                Section currentSection = current.GetComponent <Section>();
                activeBuildZones.AddRange(currentSection.SetupBuildZones());
            }

            SplineComputer currentSpline = current.GetComponentInChildren <SplineComputer>();
            splinePoints.AddRange(currentSpline.GetPoints().Skip(1).ToArray());
            currentSpline.gameObject.SetActive(false);
        }

        masterSpline.SetPoints(splinePoints.ToArray());
        masterSpline.Rebuild();
        masterSpline.GetComponent <SplineRenderer>().color = Constants.trackColor;


        if (Constants.unlimitedInventory)    // set inventory unlimited
        {
            inv.SetUnlimited();
        }
        else    // distribute inventory
        {
            foreach (BuildZone bz in activeBuildZones)
            {
                foreach (FractionTools.Fraction f in bz.GetGapComponents())
                {
                    inv.Increase((Constants.PieceLength)f.denominator, 1);
                }
            }
        }

        numBuildZones = activeBuildZones.Count;
        if (numBuildZones != 0)
        {
            lastInteractedBuildZone = activeBuildZones[0];
            lastInteractedBuildZone.Activate();
        }

        /* Start the coaster */
        CoasterManager.Instance.StartCoasterAlongSpline(masterSpline);
    }
コード例 #25
0
        void Merge(int index, MergeSide mergingSide)
        {
            RecordUndo("Merge Splines");
            SplineComputer mergedSpline = availableMergeComputers[index];

            SplinePoint[]      mergedPoints = mergedSpline.GetPoints();
            SplinePoint[]      original     = spline.GetPoints();
            List <SplinePoint> pointsList   = new List <SplinePoint>();

            SplinePoint[] points;
            if (!mergeEndpoints)
            {
                points = new SplinePoint[mergedPoints.Length + original.Length];
            }
            else
            {
                points = new SplinePoint[mergedPoints.Length + original.Length - 1];
            }

            if (mergeSide == MergeSide.End)
            {
                if (mergingSide == MergeSide.Start)
                {
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                    for (int i = mergeEndpoints ? 1 : 0; i < mergedPoints.Length; i++)
                    {
                        pointsList.Add(mergedPoints[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                    for (int i = 0; i < mergedPoints.Length - (mergeEndpoints ? 1 : 0); i++)
                    {
                        pointsList.Add(mergedPoints[(mergedPoints.Length - 1) - i]);
                    }
                }
            }
            else
            {
                if (mergingSide == MergeSide.Start)
                {
                    for (int i = 0; i < mergedPoints.Length - (mergeEndpoints ? 1 : 0); i++)
                    {
                        pointsList.Add(mergedPoints[(mergedPoints.Length - 1) - i]);
                    }
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                }
                else
                {
                    for (int i = mergeEndpoints ? 1 : 0; i < mergedPoints.Length; i++)
                    {
                        pointsList.Add(mergedPoints[i]);
                    }
                    for (int i = 0; i < original.Length; i++)
                    {
                        pointsList.Add(original[i]);
                    }
                }
            }
            points = pointsList.ToArray();
            double mergedPercent = (double)(mergedPoints.Length - 1) / (points.Length - 1);
            double from          = 0.0;
            double to            = 1.0;

            if (mergeSide == MergeSide.End)
            {
                from = 1.0 - mergedPercent;
                to   = 1.0;
            }
            else
            {
                from = 0.0;
                to   = mergedPercent;
            }


            List <Node> mergedNodes   = new List <Node>();
            List <int>  mergedIndices = new List <int>();

            for (int i = 0; i < mergedSpline.pointCount; i++)
            {
                Node node = mergedSpline.GetNode(i);
                if (node != null)
                {
                    mergedNodes.Add(node);
                    mergedIndices.Add(i);
                    Undo.RecordObject(node, "Disconnect Node");
                    mergedSpline.DisconnectNode(i);
                    i--;
                }
            }

            SplineUser[] subs = mergedSpline.GetSubscribers();
            for (int i = 0; i < subs.Length; i++)
            {
                mergedSpline.Unsubscribe(subs[i]);
                subs[i].spline   = spline;
                subs[i].clipFrom = DMath.Lerp(from, to, subs[i].clipFrom);
                subs[i].clipTo   = DMath.Lerp(from, to, subs[i].clipTo);
            }
            spline.SetPoints(points);

            if (mergeSide == MergeSide.Start)
            {
                spline.ShiftNodes(0, spline.pointCount - 1, mergedSpline.pointCount);
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    spline.ConnectNode(mergedNodes[i], mergedIndices[i]);
                }
            }
            else
            {
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    int connectIndex = mergedIndices[i] + original.Length;
                    if (mergeEndpoints)
                    {
                        connectIndex--;
                    }
                    spline.ConnectNode(mergedNodes[i], connectIndex);
                }
            }
            if (EditorUtility.DisplayDialog("Keep merged computer's GameObject?", "Do you want to keep the merged computer's game object?", "Yes", "No"))
            {
                Undo.DestroyObjectImmediate(mergedSpline);
            }
            else
            {
                for (int i = 0; i < mergedNodes.Count; i++)
                {
                    if (TransformUtility.IsParent(mergedNodes[i].transform, mergedSpline.transform))
                    {
                        Undo.SetTransformParent(mergedNodes[i].transform, mergedSpline.transform.parent, "Reparent Node");
                    }
                }
                Undo.DestroyObjectImmediate(mergedSpline.gameObject);
            }

            FindAvailableComputers();
        }