Exemplo n.º 1
0
    private static void GenerateShapes(Transform boardParent, GeneratorShapePrefs genPrefs)
    {
        // check for invalid input
        if (genPrefs == null || boardParent == null)
        {
            return;
        }

        // Generate list of available slots
        List <int> availableSlots = new List <int>();

        for (int s = 0; s < boardParent.childCount; s++)
        {
            if (boardParent.GetChild(s).GetComponent <GameSlot>() != null)
            {
                availableSlots.Add(s);
            }
        }

        // Generating the shapes
        List <ShapeData> shapesToCreate = genPrefs.GetShapeDataList();
        GameSlot         targetGameSlot = null;
        int targetSlotIndex;

        foreach (ShapeData shapeData in shapesToCreate)
        {
            targetSlotIndex = Random.Range(0, availableSlots.Count - 1);
            targetGameSlot  = boardParent.GetChild(availableSlots[targetSlotIndex]).GetComponent <GameSlot>();

            GameSlotTools.CreateSlotShape(targetGameSlot.transform, shapeData.shapeType, shapeData.shapeColor, genPrefs.targetShapeScale);
            EditorUtility.SetDirty(targetGameSlot);

            availableSlots.RemoveAt(targetSlotIndex);
        }
    }
Exemplo n.º 2
0
    public static void RecreateBoard(Transform boardParent)
    {
        GameSlot  slot;
        Transform shape, slotLock;
        ShapeData shapeData;
        LockData  lockData;

        float shapeSize, lockSize;

        for (int i = 0; i < boardParent.childCount; i++)
        {
            slot = boardParent.GetChild(i).GetComponent <GameSlot>();
            if (slot != null)
            {
                shape     = slot.GetSlotShapeTransform();
                shapeData = slot.GetSlotShape()?.GetShapeData();

                if (shapeData != null)
                {
                    shapeSize = shape.localScale.x;
                    GameObject.DestroyImmediate(shape.gameObject);
                    GameSlotTools.CreateSlotShape(slot.transform, shapeData.shapeType, shapeData.shapeColor, shapeSize);
                }

                slotLock = slot.GetSlotLock()?.transform;
                lockData = slot.GetSlotLock()?.lockData;

                if (lockData != null)
                {
                    lockSize = slotLock.localScale.x;
                    GameObject.DestroyImmediate(slotLock.gameObject);
                    GameSlotTools.CreateSlotLock(slot.transform, lockData.lockType, lockData.lockTimer, lockSize);
                }
            }

            EditorUtility.SetDirty(slot);
        }
    }
Exemplo n.º 3
0
    private void DrawGameShapeOptions(GameSlot slot)
    {
        GameShape shapeData = slot.GetSlotShape();

        if (shapeData != null)
        {
            EditorGUILayout.LabelField($"Shape Info", EditorStyles.boldLabel);
            EditorGUILayout.LabelField($"Shape Color: {shapeData.colorType}");
            EditorGUILayout.LabelField($"Shape Type: {shapeData.GetShapeType()}");
        }
        else
        {
            EditorGUILayout.LabelField("Shape Info: No Shape Available");
        }

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Lock Options", EditorStyles.boldLabel);

        desiredLockType  = (SlotLock.LockType)EditorGUILayout.EnumPopup("Lock Type", desiredLockType);
        desiredLockTimer = EditorGUILayout.IntField("Lock Timer", desiredLockTimer);
        desiredLockSize  = EditorGUILayout.FloatField("Lock Size", desiredLockSize);

        EditorGUILayout.BeginHorizontal();
        if (slot.GetSlotLock() != null)
        {
            if (GUILayout.Button("Edit Lock", GUILayout.MaxWidth(150f)))
            {
                GameSlotTools.EditSlotLock(slot.transform, desiredLockType, desiredLockTimer, desiredLockSize);
                EditorUtility.SetDirty(slot.GetComponent <GameSlot>().GetSlotLock());
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }
        else
        {
            if (GUILayout.Button("Create Lock", GUILayout.MaxWidth(150f)))
            {
                GameSlotTools.CreateSlotLock(slot.transform, desiredLockType, desiredLockTimer, desiredLockSize);
                EditorUtility.SetDirty(slot.GetComponent <GameSlot>().GetSlotLock());
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }

        SlotLock slotLock = slot.GetSlotLock();

        if (slotLock != null && GUILayout.Button("Destroy Lock", GUILayout.Width(150f)))
        {
            DestroyImmediate(slotLock.gameObject);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Shape Options", EditorStyles.boldLabel);

        desiredShapeType  = (GameShape.ShapeType)EditorGUILayout.EnumPopup("Shape Type", desiredShapeType);
        desiredShapeColor = (GameShape.ColorType)EditorGUILayout.EnumPopup("Shape Color", desiredShapeColor);
        desiredShapeSize  = EditorGUILayout.FloatField("Shape Scale", desiredShapeSize);

        EditorGUILayout.BeginHorizontal();
        if (slot.GetSlotShape() != null)
        {
            if (GUILayout.Button("Edit Shape", GUILayout.MaxWidth(150f)))
            {
                GameSlotTools.EditSlotShape(slot.transform, desiredShapeType, desiredShapeColor, desiredShapeSize);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }
        else
        {
            if (GUILayout.Button("Create Shape", GUILayout.MaxWidth(150f)))
            {
                GameSlotTools.CreateSlotShape(slot.transform, desiredShapeType, desiredShapeColor, desiredShapeSize);
                EditorUtility.SetDirty(slot.GetComponent <GameSlot>());
                EditorUtility.SetDirty(slot.GetComponent <GameSlot>().GetSlotShape());
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }

        if (shapeData != null && GUILayout.Button("Destroy Shape", GUILayout.Width(150f)))
        {
            DestroyImmediate(shapeData.gameObject);
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();
    }