Example #1
0
    private void CreateDisplayObjects()
    {
        //Find display center index
        displayCenter = new Vector2Int((displaysAcross - 1) / 2, (displaysWide - 1) / 2);

        for (int j = 0; j < displaysAcross; j++)
        {
            List <GameObject> row = new List <GameObject>();

            for (int i = 0; i < displaysWide; i++)
            {
                //Make new display node, and position it correctly
                GameObject newParent = new GameObject("Display (" + j + ", " + i + ")");
                newParent.transform.parent = parent;
                TranslateDisplay(i, j, newParent.transform);

                //Make new display view
                GameObject  newDisplay = Instantiate(displayTemplate, newParent.transform);
                DisplayData newData    = newDisplay.GetComponent <DisplayData>();

                //Set initial targets/position for new display object
                newData.SetTranslation();
                CentreDisplay(newData);
                newData.SetRotation(-45f);

                //record keeping
                newData.coord = new Vector2Int(j, i);

                //initialize builder.
                newData.builder = new MomentDisplayBuilder(pool, newData.centeringTransform);

                //If parent is on the bounds of the display, it is hidden
                if ((i < 2) || (j < 2) || (i > (displaysAcross - 3)) || (j > (displaysAcross - 3)))
                {
                    newParent.SetActive(false);
                }

                //add parent to array
                row.Add(newParent);
            }

            displays.Add(row);
        }
    }
Example #2
0
    //Default is Shift Horizontally right (move area left)
    //SwapXY = shift down
    //SwapLR = shift area left
    //Both = shift up
    private void Shift(bool swapXY, bool swapLR)
    {
        List <List <LevelMoment> > moments = LevelData.Instance.moments;

        Vector2Int bounds = new Vector2Int
        {
            x = 0,
            y = ((swapXY) ? moments.Count : moments[0].Count) - 1
        };

        //Chane which center value is checked base on X or Y shift
        int center = (swapXY)? displayObjects.centerIndex.y: displayObjects.centerIndex.x;

        //If shifting left and at the start, do not shift
        if (swapLR && (center == bounds.x))
        {
            return;
        }
        //If shifting right and at the start, do not shift
        if (!swapLR && (center == bounds.y))
        {
            return;
        }

        //Signale particles to animate
        particles.BumpSpeed();
        List <List <GameObject> > grid = displayObjects.displays;

        Vector2Int centerChange = Vector2Int.zero;

        //4 = -1 (mod 5) (same for things not 5)
        Vector2Int previous = Vector2Int.zero;
        Vector2Int m        = new Vector2Int(grid[0].Count, grid.Count);

        if (swapXY)
        {
            if (swapLR)
            {
                previous.x     = 1;
                centerChange.y = -1;
            }
            //previous = (-1,0);
            else
            {
                previous.x     = m.y - 1;
                centerChange.y = 1;
            }
        }
        else
        {
            //previous = (1,0);
            if (swapLR)
            {
                previous.y     = 1;
                centerChange.x = -1;
            }
            //previous = (-1,0);
            else
            {
                previous.y     = m.y - 1;
                centerChange.x = 1;
            }
        }

        //Shift parents to move display views
        //Update display objects
        for (int i = 0; i < grid.Count; i++)
        {
            List <GameObject> row = grid[i];

            for (int j = 0; j < row.Count; j++)
            {
                //Calculate index of next parent object
                Vector2Int k = new Vector2Int
                {
                    x = (i + previous.x) % m.x,
                    y = (j + previous.y) % m.y
                };

                Transform   newParent = grid[k.x][k.y].transform;
                DisplayData data      = grid[i][j].GetComponentInChildren <DisplayData>();

                data.translationTransform.parent = newParent;
                data.SetTranslation();
            }
        }

        //Update the index of the moment in center display
        Vector2Int oldIndex = displayObjects.centerIndex;

        displayObjects.MoveCenter(centerChange);

        //If focus has changed call event (probaly in wrong place)
        if (oldIndex != displayObjects.centerIndex)
        {
            Vector2Int  i        = displayObjects.centerIndex;
            LevelMoment newFocus = LevelData.Instance.moments[i.y][i.x];

            if (MomentDisplayChangeEvent != null)
            {
                MomentDisplayChangeEvent(newFocus);
            }
        }
    }