void PreInstantiate()
    {
        //Create a new array of spline points
        SplinePoint[] points = new SplinePoint[GameManager.Instance.datas.howManySegmentAtTheBeginning];
        //Set each point's properties
        for (int i = 0; i < points.Length; i++)
        {
            points[i]          = new SplinePoint();
            points[i].position = Vector3.forward * i * GameManager.Instance.datas.distanceBetweenAnchor;
            points[i].normal   = Vector3.up;
            points[i].size     = 1f;
            points[i].color    = Color.white;
            if (i == 0)
            {
                points[i].tangent  = -Vector3.forward * GameManager.Instance.datas.distanceBetweenAnchor / 1.5f + points[i].position;
                points[i].tangent2 = Vector3.forward * GameManager.Instance.datas.distanceBetweenAnchor / 1.5f + points[i].position;
            }
            else
            {
                Vector3 tangentDistance = points[i - 1].tangent2 - points[i].position;
                points[i].tangent  = tangentDistance + points[i].position;
                points[i].tangent2 = -tangentDistance + points[i].position;
            }
        }

        //Write the points to the spline
        spline.SetPoints(points);
    }
    /// <summary>
    /// Method that refresh tentacle spline to start position
    /// </summary>
    void SetStartPoint()
    {
        SplinePoint[] newPoints = new SplinePoint[2];
        newPoints[0].SetPosition(LevelManager.StartPoint);
        newPoints[0].size = START_SIZE;
        newPoints[1].SetPosition(new Vector3(LevelManager.StartPoint.x,
                                             LevelManager.StartPoint.y, LevelManager.StartPoint.z + 0.1f));
        newPoints[1].size = START_SIZE - 0.1f;

        _splineComputer.SetPoints(newPoints); // Erase all Point, and add new.
    }
        void SplitAtPoint(int index)
        {
            RecordUndo("Split Spline");
            SplinePoint[] splitPoints = new SplinePoint[spline.pointCount - index];
            for (int i = 0; i < splitPoints.Length; i++)
            {
                splitPoints[i] = spline.GetPoint(index + i);
            }
            SplineComputer newSpline = CreateNewSpline();

            newSpline.SetPoints(splitPoints);

            HandleNodes(newSpline, index);

            SplineUser[] users = newSpline.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp((double)index / (spline.pointCount - 1), 1.0, users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp((double)index / (spline.pointCount - 1), 1.0, users[i].clipTo);
            }
            splitPoints = new SplinePoint[index + 1];
            for (int i = 0; i <= index; i++)
            {
                splitPoints[i] = spline.GetPoint(i);
            }
            spline.SetPoints(splitPoints);
            users = spline.GetSubscribers();
            for (int i = 0; i < users.Length; i++)
            {
                users[i].clipFrom = DMath.InverseLerp(0.0, ((double)index) / (spline.pointCount - 1), users[i].clipFrom);
                users[i].clipTo   = DMath.InverseLerp(0.0, ((double)index) / (spline.pointCount - 1), users[i].clipTo);
            }
        }
Exemplo n.º 4
0
 private void Awake()
 {
     //Create a new array of spline points
     SplinePoint[] points = new SplinePoint[20];
     //Set each point's properties
     for (int i = 0; i < points.Length; i++)
     {
         points[i]          = new SplinePoint();
         points[i].position = Vector3.forward * i * 20;
         points[i].normal   = Vector3.up;
         points[i].size     = 1f;
         points[i].color    = Color.white;
     }
     //Write the points to the spline
     spline.SetPoints(points);
 }
Exemplo n.º 5
0
            internal SplineComputer CreateSplineComputer(Vector3 position, Quaternion rotation)
            {
                GameObject go = new GameObject(name);

                go.transform.position = position;
                go.transform.rotation = rotation;
                SplineComputer computer = go.AddComponent <SplineComputer>();

#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    computer.ResampleTransform();
                }
#endif
                computer.type = type;
                if (closed)
                {
                    if (points[0].type == SplinePoint.Type.Broken)
                    {
                        points[0].SetTangentPosition(GetLastPoint().tangent2);
                    }
                }
                computer.SetPoints(points.ToArray(), SplineComputer.Space.Local);
                if (closed)
                {
                    computer.Close();
                }
                return(computer);
            }
 public void UpdateSpline()
 {
     if (spline == null)
     {
         return;
     }
     if (!isClosed && spline.isClosed)
     {
         spline.Break();
     }
     else if (spline.isClosed && points.Length < 4)
     {
         spline.Break();
         isClosed = false;
     }
     spline.SetPoints(points);
     if (isClosed && !spline.isClosed)
     {
         spline.Close();
     }
     spline.type       = splineType;
     spline.sampleRate = sampleRate;
     spline.is2D       = is2D;
     spline.EditorUpdateConnectedNodes();
 }
 public virtual void Close()
 {
     if (lastClosed)
     {
         computer.Close();
     }
     else
     {
         computer.Break();
     }
     computer.SetPoints(lastPoints, SplineComputer.Space.Local);
     computer.type = lastType;
 }
Exemplo n.º 8
0
 public void UpdateSplineComputer(SplineComputer comp)
 {
     Generate();
     ApplyOffset();
     comp.type = GetSplineType();
     comp.SetPoints(points, SplineComputer.Space.Local);
     if (closed)
     {
         comp.Close();
     }
     else if (comp.isClosed)
     {
         comp.Break();
     }
 }
Exemplo n.º 9
0
 void PreInstantiate()
 {
     SplinePoint[] points = new SplinePoint[GameManager.Instance.datas.howManySegmentAtTheBeginning];
     for (int i = 0; i < points.Length; i++)
     {
         points[i]          = new SplinePoint();
         points[i].position = Vector3.forward * i * GameManager.Instance.datas.distanceBetweenAnchor;
         points[i].normal   = Vector3.up;
         points[i].size     = 1f;
         points[i].color    = Color.white;
         if (i == 0)
         {
             points[i].tangent  = -Vector3.forward * GameManager.Instance.datas.distanceBetweenAnchor / 2f + points[i].position;
             points[i].tangent2 = Vector3.forward * GameManager.Instance.datas.distanceBetweenAnchor / 2f + points[i].position;
         }
         else
         {
             Vector3 tangentDistance = points[i - 1].tangent2 - points[i].position;
             points[i].tangent  = tangentDistance + points[i].position;
             points[i].tangent2 = -tangentDistance + points[i].position;
         }
     }
     spline.SetPoints(points);
 }
Exemplo n.º 10
0
        public SplineComputer CreateSplineComputer(string name, Vector3 position, Quaternion rotation)
        {
            Generate();
            ApplyOffset();
            GameObject     go   = new GameObject(name);
            SplineComputer comp = go.AddComponent <SplineComputer>();

            comp.SetPoints(points, SplineComputer.Space.Local);
            if (closed)
            {
                comp.Close();
            }
            comp.transform.position = position;
            comp.transform.rotation = rotation;
            return(comp);
        }
Exemplo n.º 11
0
        public SplineComputer CreateSplineComputer(string name, Vector3 position, Quaternion rotation)
        {
            Generate();
            ApplyOffset();
            GameObject     gameObject     = new GameObject(name);
            SplineComputer splineComputer = gameObject.AddComponent <SplineComputer>();

            splineComputer.type = type;
            splineComputer.SetPoints(points, SplineComputer.Space.Local);
            if (closed)
            {
                splineComputer.Close();
            }
            splineComputer.transform.position = position;
            splineComputer.transform.rotation = rotation;
            return(splineComputer);
        }
Exemplo n.º 12
0
        private void RecalculateGrindTriggers(GameObject go)
        {
            foreach (Transform transform in go.GetComponentsInChildren <Transform>())
            {
                if (transform.name.Contains("GrindSpline") && !transform.name.Contains("Colliders"))
                {
                    Transform grindColliders = go.transform.Find(transform.name + "Colliders").transform;

                    Vector3[]     grindPoints  = new Vector3[transform.childCount];
                    SplinePoint[] splinePoints = new SplinePoint[grindPoints.Length];
                    for (int i = 0; i < grindPoints.Length; i++)
                    {
                        grindPoints[i]  = transform.GetChild(i).position;
                        splinePoints[i] = new SplinePoint(grindPoints[i]);
                    }

                    SplineComputer splineComputer = grindColliders.gameObject.GetComponent <SplineComputer>();
                    Vector3[]      grindNormals   = new Vector3[grindPoints.Length];
                    for (int i = 0; i < grindPoints.Length - 1; i++)
                    {
                        GameObject grindCollider = grindColliders.Find("RailCol" + i).gameObject;
                        grindCollider.transform.position = grindPoints[i];
                        grindCollider.transform.LookAt(grindPoints[i + 1]);
                        BoxCollider boxCollider   = grindCollider.GetComponent <BoxCollider>();
                        float       segmentLength = Vector3.Distance(grindPoints[i], grindPoints[i + 1]);
                        boxCollider.size   = new Vector3(0.08f / go.transform.lossyScale.x, 0.08f / go.transform.lossyScale.y, segmentLength);
                        boxCollider.center = Vector3.forward * segmentLength / 2f;
                        grindNormals[i]    = grindCollider.transform.up;
                    }

                    grindNormals[grindNormals.Length - 1] = grindNormals[grindNormals.Length - 2];
                    splineComputer.SetPoints(splinePoints);
                    splineComputer.Evaluate(0.9);
                    for (int i = 0; i < grindPoints.Length; i++)
                    {
                        splineComputer.SetPointNormal(i, splineComputer.GetPointNormal(i, SplineComputer.Space.World) + grindNormals[i], SplineComputer.Space.World);
                    }
                }
                if (transform.name.Contains("GrindCollider"))
                {
                    transform.localScale = new Vector3(1f / go.transform.lossyScale.x, 1f / go.transform.lossyScale.y, 1f);
                }
            }
        }
Exemplo n.º 13
0
        void SplitAtPercent(double percent)
        {
            RecordUndo("Split Spline");
            float pointValue     = (spline.pointCount - 1) * (float)percent;
            int   lastPointIndex = Mathf.FloorToInt(pointValue);
            int   nextPointIndex = Mathf.CeilToInt(pointValue);

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

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

            newSpline.SetPoints(splitPoints);

            HandleNodes(newSpline, lastPointIndex);

            SplineUser[] users = newSpline.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] = spline.GetPoint(i);
            }
            splitPoints[splitPoints.Length - 1] = splitPoint;
            spline.SetPoints(splitPoints);
            users = spline.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);
            }
        }
Exemplo n.º 14
0
    void InstantiateANewAnchor(bool previsualisation, Material material)
    {
        if (previsualisation == false)
        {
            //new point
            SplinePoint lastPoint = spline.GetPoint(spline.pointCount - 1);

            Vector3     newPos   = GetNewPosition(handTransform);
            SplinePoint newPoint = new SplinePoint();
            newPoint.position = newPos;
            newPoint.normal   = curveInstantiator.transform.up;
            newPoint.size     = 0.5f;
            newPoint.color    = Color.white;
            Vector3 distance = lastPoint.tangent2 - newPoint.position;
            newPoint.tangent  = distance / 1.5f + newPoint.position;
            newPoint.tangent2 = -distance / 1.5f + newPoint.position;

            //CreateAPointClampSpline(newPoint);
            CreateAPoint(newPoint);
            spline.RebuildImmediate();
            splineFollower.result.percent = (double)(splineFollower.result.percent / ((double)1 / (double)(double)spline.pointCount
                                                                                      * ((double)(double)spline.pointCount + (double)1)));
            MakeThePathSmaller();
        }
        else
        {
            SplinePoint   lastPoint = spline.GetPoint(spline.pointCount - 1);
            SplinePoint[] points    = new SplinePoint[2];

            points[0] = lastPoint;

            Vector3 newPos = GetNewPosition(handTransform);
            points[1].position = newPos;
            points[1].normal   = curveInstantiator.transform.up;
            points[1].size     = 1f;
            points[1].color    = Color.red;
            Vector3 distance = points[0].tangent2 - points[1].position;
            points[1].tangent  = distance / 1.5f + points[1].position;
            points[1].tangent2 = -distance / 1.5f + points[1].position;
            previsualisationSpline.gameObject.GetComponent <Renderer>().material = material;
            previsualisationSpline.SetPoints(points);
        }
    }
Exemplo n.º 15
0
    public static bool BuildSplineComputer(GrindSegment segment)
    {
        // Create Spline Computer component and settings for GrindSpline Object
        SplineComputer sc = segment.grindRoot.gameObject.AddComponent <SplineComputer>();

        sc.type = Spline.Type.Linear;
        sc.SetPoints(segment.points, SplineComputer.Space.World);
        sc.Evaluate(0.9);

        // Shift normal vectors up a position for spline points points
        segment.normals[segment.normals.Length - 1] = segment.normals[segment.normals.Length - 2];

        // Set point normals
        for (int i = 0; i < segment.points.Length; i++)
        {
            sc.SetPointNormal(i, sc.GetPoint(i, SplineComputer.Space.World).normal + segment.normals[i], SplineComputer.Space.World);
        }

        return(true);
    }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
            internal SplineComputer CreateSplineComputer(Vector3 position, Quaternion rotation)
            {
                GameObject gameObject = new GameObject(name);

                gameObject.transform.position = position;
                gameObject.transform.rotation = rotation;
                SplineComputer splineComputer = gameObject.AddComponent <SplineComputer>();

                splineComputer.type = type;
                if (closed && points[0].type == SplinePoint.Type.Broken)
                {
                    SplinePoint splinePoint = points[0];
                    SplinePoint lastPoint   = GetLastPoint();
                    splinePoint.SetTangentPosition(lastPoint.tangent2);
                }
                splineComputer.SetPoints(points.ToArray(), SplineComputer.Space.Local);
                if (closed)
                {
                    splineComputer.Close();
                }
                return(splineComputer);
            }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
 void InstantiateANewAnchor(bool previsualisation)
 {
     if (previsualisation == false)
     {
         double      percentPrecedent = splineFollower.result.percent;
         double      nbrPoints        = (double)spline.pointCount;
         SplinePoint lastPoint        = spline.GetPoint(spline.pointCount - 1);
         Vector3     posPop           = GetInstanceDotPositionRay();
         SplinePoint newPoint         = new SplinePoint();
         newPoint.position = posPop;
         newPoint.normal   = curveInstantiator.up;
         newPoint.size     = 1f;
         newPoint.color    = Color.white;
         Vector3 distance = lastPoint.tangent2 - newPoint.position;
         newPoint.tangent  = distance / 2f + newPoint.position;
         newPoint.tangent2 = -distance / 2f + newPoint.position;
         CreateAPoint(newPoint);
         spline.RebuildImmediate();
         splineFollower.result.percent = (double)(percentPrecedent / ((double)1 / (double)nbrPoints * ((double)nbrPoints + (double)1)));
     }
     else
     {
         SplinePoint   lastPoint = spline.GetPoint(spline.pointCount - 1);
         SplinePoint[] points    = new SplinePoint[2];
         points[0] = lastPoint;
         Vector3 newPos = GetInstanceDotPositionRay();
         points[1].position = newPos;
         points[1].normal   = curveInstantiator.transform.up;
         points[1].size     = 1f;
         points[1].color    = Color.red;
         Vector3 distance = points[0].tangent2 - points[1].position;
         points[1].tangent  = distance / 1.5f + points[1].position;
         points[1].tangent2 = -distance / 1.5f + points[1].position;
         previsualisationSpline.SetPoints(points);
     }
 }
        private void AddGrindTriggers(GameObject go)
        {
            foreach (Transform transform in go.GetComponentsInChildren <Transform>())
            {
                if (transform.name.Contains("GrindSpline"))
                {
                    Transform grindColliders = new GameObject(transform.name + "Colliders").transform;
                    grindColliders.parent           = go.transform;
                    grindColliders.gameObject.layer = 12;

                    if (transform.name.Contains("Metal"))
                    {
                        transform.tag = "Metal";
                    }
                    if (transform.name.Contains("Wood"))
                    {
                        transform.tag = "Wood";
                    }
                    if (transform.name.Contains("Concrete"))
                    {
                        transform.tag = "Concrete";
                    }

                    Vector3[]     grindPoints  = new Vector3[transform.childCount];
                    SplinePoint[] splinePoints = new SplinePoint[grindPoints.Length];
                    for (int i = 0; i < grindPoints.Length; i++)
                    {
                        grindPoints[i]  = transform.GetChild(i).position;
                        splinePoints[i] = new SplinePoint(grindPoints[i]);
                    }

                    SplineComputer splineComputer = grindColliders.gameObject.AddComponent <SplineComputer>();
                    splineComputer.type = Spline.Type.Linear;
                    Vector3[] grindNormals = new Vector3[grindPoints.Length];
                    for (int i = 0; i < grindPoints.Length - 1; i++)
                    {
                        GameObject grindCollider = new GameObject("RailCol" + i);
                        grindCollider.layer = 12;
                        grindCollider.transform.position = grindPoints[i];
                        grindCollider.transform.LookAt(grindPoints[i + 1]);
                        BoxCollider boxCollider   = grindCollider.AddComponent <BoxCollider>();
                        float       segmentLength = Vector3.Distance(grindPoints[i], grindPoints[i + 1]);
                        boxCollider.size               = new Vector3(0.08f / go.transform.lossyScale.x, 0.08f / go.transform.lossyScale.y, segmentLength);
                        boxCollider.center             = Vector3.forward * segmentLength / 2f;
                        boxCollider.isTrigger          = true;
                        grindCollider.transform.parent = grindColliders;
                        grindNormals[i] = grindCollider.transform.up;

                        if (transform.name.Contains("Metal"))
                        {
                            grindCollider.tag = "Metal";
                        }
                        if (transform.name.Contains("Wood"))
                        {
                            grindCollider.tag = "Wood";
                        }
                        if (transform.name.Contains("Concrete"))
                        {
                            grindCollider.tag = "Concrete";
                        }
                    }

                    grindNormals[grindNormals.Length - 1] = grindNormals[grindNormals.Length - 2];
                    splineComputer.SetPoints(splinePoints);
                    splineComputer.Evaluate(0.9);
                    for (int i = 0; i < grindPoints.Length; i++)
                    {
                        splineComputer.SetPointNormal(i, splineComputer.GetPointNormal(i, SplineComputer.Space.World) + grindNormals[i], SplineComputer.Space.World);
                    }
                }
            }
        }
            /// <summary>
            /// Called by the extrusion sequence after extruding to apply results
            /// </summary>
            public void RuntimeApply()
            {
                if (_error)
                {
                    return;
                }
                if (extrusionSettings.ignore)
                {
                    return;
                }
                if (extrusionSettings.applyRotation)
                {
                    transform.SetPositionAndRotation(targetPosition, targetRotation);
                }
                else
                {
                    transform.position = targetPosition;
                }
                if (extrusionSettings.applyScale)
                {
                    Transform parent = transform.parent;
                    transform.parent      = null;
                    transform.localScale *= scaleMultiplier;
                    transform.parent      = parent;
                }

                if (extrusionSettings.bendMesh)
                {
                    extrudedMesh      = new Mesh();
                    extrudedMesh.name = _originalMesh.name + "_extruded";
                    extrusionMesh.WriteMesh(ref extrudedMesh);
                    MeshFilter filter = transform.GetComponent <MeshFilter>();
                    filter.sharedMesh = extrudedMesh;
                    extrusionMesh.Clear();
                }

                if (extrusionSettings.bendSprite)
                {
                    Sprite   originalSprite   = spriteRenderer.sprite;
                    Material instanceMaterial = spriteRenderer.sharedMaterial;
                    extrudedMesh      = new Mesh();
                    extrudedMesh.name = spriteRenderer.sprite.name + "_mesh";
                    Vector3[] verts     = new Vector3[extrusionSpriteVertices.Length];
                    ushort[]  shortTris = spriteRenderer.sprite.triangles;
                    int[]     tris      = new int[shortTris.Length];
                    for (int i = 0; i < tris.Length; i++)
                    {
                        tris[i] = shortTris[i];
                    }
                    for (int i = 0; i < verts.Length; i++)
                    {
                        verts[i] = extrusionSpriteVertices[i];
                    }
                    extrudedMesh.vertices  = verts;
                    extrudedMesh.uv        = extrusionSpriteUVs;
                    extrudedMesh.triangles = tris;
                    DestroyImmediate(spriteRenderer);
                    MeshRenderer spriteMeshRenderer = transform.gameObject.AddComponent <MeshRenderer>();
                    spriteMeshRenderer.sharedMaterial = instanceMaterial;
                    MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
                    spriteMeshRenderer.GetPropertyBlock(propertyBlock);
                    propertyBlock.SetTexture("_MainTex", originalSprite.texture);
                    spriteMeshRenderer.SetPropertyBlock(propertyBlock);
                    MeshFilter spriteMeshFilter = transform.gameObject.AddComponent <MeshFilter>();
                    spriteMeshFilter.sharedMesh = extrudedMesh;
                }

                switch (extrusionSettings.meshColliderHandling)
                {
                case ExtrusionSettings.MeshColliderHandling.Extrude:
                    extrudedCollisionMesh      = new Mesh();
                    extrudedCollisionMesh.name = _originalCollisionMesh.name + "_extruded";
                    extrusionCollisionMesh.WriteMesh(ref extrudedCollisionMesh);
                    meshCollider.sharedMesh = extrudedCollisionMesh;
                    break;

                case ExtrusionSettings.MeshColliderHandling.Copy:
                    if (meshCollider == null)
                    {
                        meshCollider = transform.gameObject.AddComponent <MeshCollider>();
                    }
                    if (extrudedMesh != null)
                    {
                        meshCollider.sharedMesh = extrudedMesh;
                    }
                    else
                    {
                        meshCollider.sharedMesh = _originalMesh;
                    }
                    break;
                }

#if DREAMTECK_SPLINES
                if (splineComputer != null)
                {
                    splineComputer.ResampleTransform();
                    if (extrusionSettings.bendSpline)
                    {
                        splineComputer.SetPoints(editSplinePoints);
                    }
                }
#endif
            }
Exemplo n.º 22
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);
    }