예제 #1
0
    public static SpiralPos GetSpiralPos(int n)
    {
        int x = 0, z = 0;

        if (--n >= 0)
        {
            int v = (int)Mathf.Floor(Mathf.Sqrt(n + 0.25f) - 0.5f);
            int spiralBaseIndex = v * (v + 1);
            int flipFlop        = ((v & 1) << 1) - 1;
            int offset          = flipFlop * ((v + 1) >> 1);
            x += offset; z += offset;

            int cornerIndex = spiralBaseIndex + (v + 1);
            if (n < cornerIndex)
            {
                x -= flipFlop * (n - spiralBaseIndex + 1);
            }
            else
            {
                x -= flipFlop * (v + 1);
                z -= flipFlop * (n - cornerIndex + 1);
            }
        }

        SpiralPos result = new SpiralPos();

        result.x = x;
        result.z = z;

        return(result);
    }
예제 #2
0
        SpectrumWrapper InitChannel(int channel, int spectrumSize, Transform parent)
        {
            SpectrumWrapper result = new SpectrumWrapper();

            result.channel          = channel;
            result.spectrumBuff     = new float[spectrumSize];
            result.transforms       = new Transform[spectrumSize];
            result.currentSpectrums = new NativeArray <float>(spectrumSize, Allocator.Persistent);
            result.prevSpectrums    = new NativeArray <float>(spectrumSize, Allocator.Persistent);
            result.origins          = new NativeArray <Vector3>(spectrumSize, Allocator.Persistent);

            for (int index = 0;
                 index < spectrumSize;
                 ++index)
            {
                GameObject obj = Object.Instantiate(cubePrefab);

                SpiralPos pos = Utils.GetSpiralPos(index);

                obj.transform.parent        = parent;
                obj.transform.localPosition = new Vector3(pos.x, 0, pos.z);

                result.transforms[index] = obj.transform;
                result.origins[index]    = obj.transform.localPosition;
            }

            result.transformsAccess = new TransformAccessArray(result.transforms);

            return(result);
        }
        protected override void OnUpdate()
        {
            if (isFirstTime)
            {
                int spectrumSize = settings.spectrumSize;
                for (int index = 0;
                     index < totalCubeCount;
                     ++index)
                {
                    int xOffset;
                    int groupIndex = index;
                    if (index < spectrumSize)
                    {
                        xOffset = -35;

                        SpiralPos pos      = Utils.GetSpiralPos(groupIndex);
                        Position  position = leftGroup.positions[groupIndex];
                        position.Value = new float3(pos.x + xOffset, 0, pos.z);
                        leftGroup.positions[groupIndex] = position;

                        Origin origin = leftGroup.origins[groupIndex];
                        origin.Value = position.Value;
                        leftGroup.origins[groupIndex] = origin;
                    }
                    else
                    {
                        xOffset     = 35;
                        groupIndex -= spectrumSize;

                        SpiralPos pos      = Utils.GetSpiralPos(groupIndex);
                        Position  position = rightGroup.positions[groupIndex];
                        position.Value = new float3(pos.x + xOffset, 0, pos.z);
                        rightGroup.positions[groupIndex] = position;

                        Origin origin = rightGroup.origins[groupIndex];
                        origin.Value = position.Value;
                        rightGroup.origins[groupIndex] = origin;
                    }
                }
            }

            isFirstTime = false;
        }
예제 #4
0
        void Start()
        {
            int spectrumSize = settings.spectrumSize;

            spectrumBuff     = new float[spectrumSize];
            prevSpectrumBuff = new float[spectrumSize];
            cubes            = new GameObject[spectrumSize];

            for (int index = 0;
                 index < spectrumSize;
                 ++index)
            {
                GameObject obj = Object.Instantiate(cubePrefab);

                SpiralPos pos = Utils.GetSpiralPos(index);
                obj.transform.position = new Vector3(pos.x, 0, pos.z);
                obj.transform.parent   = this.transform;
                cubes[index]           = obj;
            }
        }