Ejemplo n.º 1
0
    private void Update()
    {
        if (filters != null)
        {
            Random.InitState(seed);
            WormholeSettings holeSettings = (WormholeSettings)settings;

            RingTransform lastRing      = new RingTransform();
            Transform     lastTransform = transform;

            for (int i = 0; i < filters.Length; i++)
            {
                float noiseOffset = noiseStartOffset + holeSettings.NoiseSampleInterval * holeSettings.Length * i;

                filters[i].transform.localPosition = lastTransform.TransformPoint(lastRing.Pos);

                Random.InitState(seed);
                WormholeResult wormhole = WormholeMeshGenerator.GetWormhole(holeSettings, noiseOffset, true, lastRing.Rot, filters[i].transform);
                filters[i].mesh = wormhole.Mesh;
                lastRing        = wormhole.Rings[wormhole.Rings.Count - 1];

                lastTransform = filters[i].transform;
            }
        }
    }
    private void GenerateSegment(bool takeFromPool = true)
    {
        MeshFilter filter = takeFromPool
            ? filters.Dequeue()
            : Instantiate(filterTemplate, transform);

        WormholeSettings holeSettings = (WormholeSettings)settings;
        float            noiseOffset  = noiseStartOffset + holeSettings.NoiseSampleInterval * holeSettings.Length * i;

        Vector3 globalPos = rings.Count > 0
            ? rings[rings.Count - 1].GlobalPos
            : Vector3.zero;

        Quaternion rot = rings.Count > 0
            ? rings[rings.Count - 1].Rot
            : Quaternion.identity;

        filter.transform.position = globalPos;

        UnityEngine.Random.InitState(seed);
        WormholeResult wormholeResult = WormholeMeshGenerator.GetWormhole(holeSettings, noiseOffset, true, rot, filter.transform);

        filter.mesh = wormholeResult.Mesh;

        i++;
        filters.Enqueue(filter);

        for (int i = 0; i < wormholeResult.Rings.Count - 1; i++)
        {
            Transform colliderTransform = takeFromPool
                ? GetCapsuleFromPool().transform
                : CreateNewCapsule(holeSettings).transform;

            colliderTransform.parent = filter.transform;
            RingTransform ring = wormholeResult.Rings[i];
            colliderTransform.position = ring.GlobalPos;
            colliderTransform.rotation = ring.GlobalRot;
        }

        rings.AddRange(wormholeResult.Rings);
        rings.RemoveAt(rings.Count - holeSettings.Length);

        if (takeFromPool)
        {
            rings.RemoveRange(0, holeSettings.Length - 1);
        }
    }