Ejemplo n.º 1
0
    public static void EditSlotShape(Transform slot, GameShape.ShapeType shapeType, GameShape.ColorType shapeColor, float shapeSize)
    {
        GameShape newShape = slot.GetComponent <GameSlot>().GetSlotShapeTransform().GetComponent <GameShape>();

        newShape.transform.localScale = new Vector3(shapeSize, shapeSize);

        GameShape shapeRef = newShape.GetComponent <GameShape>();

        shapeRef.SetShapeColor(shapeColor);
        shapeRef.SetShapeType(shapeType);
        EditorUtility.SetDirty(shapeRef);

        EditorUtility.SetDirty(shapeRef.GetComponent <Image>());
        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    }
Ejemplo n.º 2
0
    private void ConstructBoard(BoardData data, Transform boardParent)
    {
        // Getting board parents
        //GameObject shapePrefab = GameManager.manager.shapePrefab;
        float cellSize   = boardParent.GetComponent <GridLayoutGroup>().cellSize.y;
        float shapeSize  = 2.25f * (cellSize / 384);
        int   boardCount = data.boardSize.x * data.boardSize.y;

        boardManager.shapeSize = shapeSize;

        // Declaring Tracker Variables
        GameSlot         slot;
        GameShape        shape;
        SlotLock         slotLock;
        ShapeTransformer shapeTransformer;

        // Loop through the board and set the board state to the data
        for (int i = 0; i < boardCount; i++)
        {
            // Getting the Game Slot/Shape Reference
            slot             = boardParent.GetChild(i).GetComponent <GameSlot>();
            shape            = slot?.GetSlotShape();
            slotLock         = slot?.GetSlotLock();
            shapeTransformer = boardParent.GetChild(i).GetComponent <ShapeTransformer>();

            #region Generating Slot Shape
            if (shape != null)
            {
                // Checking if a shape doesn't exist on the passed in data
                if (data.shapes[i] == null || data.shapes[i].shapeType == GameShape.ShapeType.None)
                {
                    Destroy(shape.gameObject);
                }
                else if (shape.GetShapeData() != data.shapes[i])
                {
                    // Shape does exist but doesn't match the shape in the data, set them to be equivalent
                    shape.SetShapeColor(data.shapes[i].shapeColor);
                    shape.SetShapeType(data.shapes[i].shapeType);
                }
            }
            else
            {
                // Checking to see if a shape exists in the data at the given spot, if so create a new one
                if (data.shapes[i] != null && data.shapes[i].shapeType != GameShape.ShapeType.None)
                {
                    // Creating the shape
                    GameObject newShape = Instantiate(shapePrefab, slot.transform);
                    newShape.transform.localPosition = new Vector3(0.5f, -0.5f, 0f);
                    newShape.transform.localScale    = new Vector3(shapeSize, shapeSize, 0f);

                    // Getting the GameShape reference and setting it equal to the shape in the data
                    GameShape shapeRef = newShape.GetComponent <GameShape>();
                    shapeRef.SetShapeColor(data.shapes[i].shapeColor);
                    shapeRef.SetShapeType(data.shapes[i].shapeType);

                    slot.SetSlotShapeReference(shapeRef.transform);
                }
            }
            #endregion

            #region Generating Slot Lock
            if (slotLock != null)
            {
                LockData lockData = data.locks[i];
                if (lockData != null)
                {
                    Debug.Log($"Generating Slot Lock at Index {i} of type {lockData.lockType} with {lockData.lockTimer} move(s) left");

                    // Active
                    if (lockData.lockTimer > 0)
                    {
                        if (slotLock.GetLockCounter() <= 0)
                        {
                            slotLock.SetLockToActive();
                        }

                        slotLock.SetLockSettings(lockData.lockType, lockData.lockTimer);
                        slot.LockGameSlot();
                    }
                    else if (slotLock.GetLockCounter() > 0)
                    {
                        slotLock.SetLockToDestruct();
                    }
                }
            }
            else
            {
                LockData lockData = data.locks[i];
                if (lockData != null && lockData.lockType != SlotLock.LockType.None)
                {
                    GameObject newLock = Instantiate(slotLockPrefab, slot.transform);
                    newLock.transform.localPosition = new Vector3(0f, -cellSize / 2f, 0f);
                    newLock.transform.localScale    = new Vector3(cellSize / 384f, cellSize / 384f);

                    slotLock = newLock.GetComponent <SlotLock>();
                    slotLock.SetLockSettings(lockData.lockType, lockData.lockTimer);

                    slot.GetComponent <GameSlot>().SetSlotLock(slotLock);
                }
            }
            #endregion

            #region Generate Shape Transformers
            if (shapeTransformer != null)
            {
                shapeTransformer.SetTransformerData(data.transformers[i]);
            }
            #endregion
        }
    }