Beispiel #1
0
 public void Setup(Color col, DotData upper, DotData lower, DotData right, DotData left, int x, int y)
 {
     this.gameObject.GetComponent <SpriteRenderer>().color = col;
     color         = col;
     upperNeighbor = upper;
     lowerNeighbor = lower;
     rightNeighbor = right;
     leftNeighbor  = left;
     xLoc          = x;
     yLoc          = y;
 }
Beispiel #2
0
 public Directions IsNeighbor(DotData other)
 {
     if (other == upperNeighbor)
     {
         return(Directions.Up);
     }
     else if (other == lowerNeighbor)
     {
         return(Directions.Down);
     }
     else if (other == leftNeighbor)
     {
         return(Directions.Left);
     }
     else if (other == rightNeighbor)
     {
         return(Directions.Right);
     }
     else
     {
         return(Directions.NaN);
     }
 }
    void Start()
    {
        //yatteikou

        _num = _numX * _numY;

        _cubeDataBuffer = new ComputeBuffer(_num, Marshal.SizeOf(typeof(DotData)));
        _argsBuffer     = new ComputeBuffer(1, _args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);

        var dataArr = new DotData[_num];

        //float width = 10f;
        float height = width * (float)_numY / _numX;

        int idx = 0;

        for (int i = 0; i < _numX; ++i)
        {
            for (int j = 0; j < _numY; ++j)
            {
                float rx = (float)i / (_numX - 1);
                float ry = (float)j / (_numY - 1);
                dataArr[idx]          = new DotData();
                dataArr[idx].position = new Vector3(
                    (rx - 0.5f) * width,
                    (ry - 0.5f) * height,
                    0
                    );
                dataArr[idx].scale   = Vector3.one;
                dataArr[idx].basePos = new Vector3(
                    (rx - 0.5f) * width,
                    (ry - 0.5f) * height,
                    0
                    );
                dataArr[idx].velocity = new Vector3(
                    0.01f * (Random.value - 0.5f),
                    0.01f * (Random.value - 0.5f),
                    0.01f * (Random.value - 0.5f)
                    );

                dataArr[idx].time = Random.value * 2f;

                //dataArr[idx].rotation = Vector3.zero;

                dataArr[idx].color = new Vector4(
                    0,
                    0,
                    0,
                    1f
                    );

                dataArr[idx].uv = new Vector2(
                    (float)i / (_numX),
                    (float)j / (_numY)
                    );
                idx++;
            }
        }
        _cubeDataBuffer.SetData(dataArr);

        _positions = new Vector4[3000];
    }
Beispiel #4
0
    void Init()
    {
        if (mIsInit)
        {
            return;
        }

        //generate labels
        mLabelNumberHorz = new Text[barHorizontalCount];

        //horizontal
        float x    = 0f;
        float xOfs = barHorizontal.rect.width / (barHorizontalCount - 1);

        for (int i = 0; i < barHorizontalCount; i++)
        {
            if (i > 0 && i < barHorizontalCount - 1)
            {
                var newGridVert = Instantiate(gridVerticalTemplate);
                newGridVert.SetParent(gridVerticalTemplate.parent);
                newGridVert.anchorMin        = new Vector2(0f, 0f);
                newGridVert.anchorMax        = new Vector2(0f, 1f);
                newGridVert.sizeDelta        = new Vector2(1f, 0f);
                newGridVert.anchoredPosition = new Vector2(x, 0f);
            }

            var newLabel   = Instantiate(labelHorizontalTemplate);
            var newLabelRT = newLabel.rectTransform;

            newLabelRT.SetParent(barHorizontal);
            newLabelRT.anchoredPosition = new Vector2(x, 0f);

            mLabelNumberHorz[i] = newLabel;

            x += xOfs;
        }

        labelHorizontalTemplate.gameObject.SetActive(false);
        gridVerticalTemplate.gameObject.SetActive(false);
        //

        //vertical
        mLabelNumberVert = new Text[barVerticalCount];

        float y    = 0f;
        float yOfs = barVertical.rect.height / (barVerticalCount - 1);

        for (int i = 0; i < barVerticalCount; i++)
        {
            if (i > 0 && i < barVerticalCount - 1)
            {
                var newGridHorz = Instantiate(gridHorizontalTemplate);
                newGridHorz.SetParent(gridHorizontalTemplate.parent);
                newGridHorz.anchorMin        = new Vector2(0f, 0f);
                newGridHorz.anchorMax        = new Vector2(1f, 0f);
                newGridHorz.sizeDelta        = new Vector2(0f, 1f);
                newGridHorz.anchoredPosition = new Vector2(0f, y);
            }

            var newLabel   = Instantiate(labelVerticalTemplate);
            var newLabelRT = newLabel.rectTransform;

            newLabelRT.SetParent(barVertical);
            newLabelRT.anchoredPosition = new Vector2(0f, y);

            mLabelNumberVert[i] = newLabel;

            y += yOfs;
        }

        labelVerticalTemplate.gameObject.SetActive(false);
        gridHorizontalTemplate.gameObject.SetActive(false);
        //

        //setup caches
        mDots      = new M8.CacheList <DotData>(dotCapacity);
        mDotsCache = new M8.CacheList <DotData>(dotCapacity);

        for (int i = 0; i < dotCapacity; i++)
        {
            var newDot = Instantiate(dotTemplate);
            newDot.SetParent(dotArea);

            var newDotDat = new DotData(newDot);

            newDot.gameObject.SetActive(false);

            mDotsCache.Add(newDotDat);
        }

        dotTemplate.gameObject.SetActive(false);

        mLines      = new M8.CacheList <RectTransform>(lineCapacity);
        mLinesCache = new M8.CacheList <RectTransform>(lineCapacity);

        for (int i = 0; i < lineCapacity; i++)
        {
            var newLine = Instantiate(lineTemplate);
            newLine.SetParent(lineArea);
            newLine.gameObject.SetActive(false);
            mLines.Add(newLine);
        }

        lineTemplate.gameObject.SetActive(false);

        mIsInit = true;
    }
    public void ResolveClick(DotData clicked)
    {
        if (prevClicked)
        {
            if (clicked != prevClicked)
            {
                clicked.gameObject.GetComponent <DotData>().dotScaleMod = 1.0f;
                if (clicked.upperNeighbor)
                {
                    clicked.upperNeighbor.dotScaleMod = 1.0f;
                }
                if (clicked.lowerNeighbor)
                {
                    clicked.lowerNeighbor.dotScaleMod = 1.0f;
                }
                if (clicked.leftNeighbor)
                {
                    clicked.leftNeighbor.dotScaleMod = 1.0f;
                }
                if (clicked.rightNeighbor)
                {
                    clicked.rightNeighbor.dotScaleMod = 1.0f;
                }

                prevClicked.gameObject.GetComponent <DotData>().dotScaleMod = 1.0f;
                if (prevClicked.upperNeighbor)
                {
                    prevClicked.upperNeighbor.dotScaleMod = 1.0f;
                }
                if (prevClicked.lowerNeighbor)
                {
                    prevClicked.lowerNeighbor.dotScaleMod = 1.0f;
                }
                if (prevClicked.leftNeighbor)
                {
                    prevClicked.leftNeighbor.dotScaleMod = 1.0f;
                }
                if (prevClicked.rightNeighbor)
                {
                    prevClicked.rightNeighbor.dotScaleMod = 1.0f;
                }

                switch (prevClicked.IsNeighbor(clicked))
                {
                case Directions.Up:
                    prevClicked.Slide(Directions.Up);
                    clicked.Slide(Directions.Down);
                    prevClicked = null;
                    break;

                case Directions.Down:
                    prevClicked.Slide(Directions.Down);
                    clicked.Slide(Directions.Up);
                    prevClicked = null;
                    break;

                case Directions.Left:
                    prevClicked.Slide(Directions.Left);
                    clicked.Slide(Directions.Right);
                    prevClicked = null;
                    break;

                case Directions.Right:
                    prevClicked.Slide(Directions.Right);
                    clicked.Slide(Directions.Left);
                    prevClicked = null;
                    break;

                default:
                    prevClicked = clicked;
                    clicked.gameObject.GetComponent <DotData>().dotScaleMod = 2.0f;
                    if (clicked.upperNeighbor)
                    {
                        clicked.upperNeighbor.dotScaleMod = 1.5f;
                    }
                    if (clicked.lowerNeighbor)
                    {
                        clicked.lowerNeighbor.dotScaleMod = 1.5f;
                    }
                    if (clicked.leftNeighbor)
                    {
                        clicked.leftNeighbor.dotScaleMod = 1.5f;
                    }
                    if (clicked.rightNeighbor)
                    {
                        clicked.rightNeighbor.dotScaleMod = 1.5f;
                    }
                    break;
                }
            }
        }
        else
        {
            clicked.gameObject.GetComponent <DotData>().dotScaleMod = 2.0f;
            if (clicked.upperNeighbor)
            {
                clicked.upperNeighbor.dotScaleMod = 1.5f;
            }
            if (clicked.lowerNeighbor)
            {
                clicked.lowerNeighbor.dotScaleMod = 1.5f;
            }
            if (clicked.leftNeighbor)
            {
                clicked.leftNeighbor.dotScaleMod = 1.5f;
            }
            if (clicked.rightNeighbor)
            {
                clicked.rightNeighbor.dotScaleMod = 1.5f;
            }
            prevClicked = clicked;
        }
    }
Beispiel #6
0
    void Start()
    {
        //yatteikou

        //頂点の数ぶん、やって見るテスト


        _num = _numX * _numY;

        _cubeDataBuffer = new ComputeBuffer(_num, Marshal.SizeOf(typeof(DotData)));
        _argsBuffer     = new ComputeBuffer(1, _args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);

        var dataArr = new DotData[_num];

        //float width = 10f;
        float height = width * (float)_numY / _numX;

        int idx = 0;

        for (int i = 0; i < _numX; ++i)
        {
            for (int j = 0; j < _numY; ++j)
            {
                float rx = (float)i / (_numX - 1);
                float ry = (float)j / (_numY - 1);
                dataArr[idx]          = new DotData();
                dataArr[idx].position = new Vector3(
                    (rx - 0.5f) * width,
                    (ry - 0.5f) * height,
                    0
                    );
                dataArr[idx].scale   = Vector3.one;
                dataArr[idx].basePos = new Vector3(
                    (rx - 0.5f) * width,
                    (ry - 0.5f) * height,
                    0
                    );
                dataArr[idx].velocity = new Vector3(
                    0.01f * (Random.value - 0.5f),
                    0.01f * (Random.value - 0.5f),
                    0.01f * (Random.value - 0.5f)
                    );

                dataArr[idx].time = Random.value;

                //dataArr[idx].rotation = Vector3.zero;

                dataArr[idx].color = new Vector4(
                    0,
                    0,
                    0,
                    1f
                    );

                dataArr[idx].uv = new Vector2(
                    (float)i / (_numX),
                    (float)j / (_numY)
                    );
                idx++;
            }
        }
        _cubeDataBuffer.SetData(dataArr);

        _positions = new Vector4[2000];
        _uvs       = new Vector4[2000];

        //meshを取得する
        for (int i = 0; i < _positions.Length; i++)
        {
            //int ii = Mathf.FloorToInt( _posMesh.vertexCount * Random.value );
            //Vector3 vv = _posMesh.vertices[ii];

            //Vector3 vv = Utils.RandomPointOnMesh.Sample( _posMesh );
            var d = Utils.RandomPointOnMesh.Sample2(_posMesh);

            _positions[i] = new Vector4(
                d.v.x, d.v.y, d.v.z,
                Random.value - 0.5f
                );
            _uvs[i] = new Vector4(
                d.uv.x,
                d.uv.y, 0, 0
                );
        }
    }