public IEnumerator SwitchShapes(GameSlot slot1, GameSlot slot2) { // Setting the parents Transform shape1 = slot1.GetSlotShapeTransform(); Transform shape2 = slot2.GetSlotShapeTransform(); shape1.SetParent(slot2.transform); shape2.SetParent(slot1.transform); slot1.SetSlotShapeReference(shape2); slot2.SetSlotShapeReference(shape1); onShapeSwap?.Invoke(); while (locksAnimating > 0) { yield return(null); } // Triggering Shape Destruction(s) int destroyedShapes = 0; destroyedShapes += TriggerShapeDestruction(slot1.GetSlotIndex(), gameBoardParent); destroyedShapes += TriggerShapeDestruction(slot2.GetSlotIndex(), gameBoardParent); while (shapesBeingDestroyed > 0) { yield return(null); } onShapeDestroy?.Invoke(destroyedShapes); while (locksAnimating > 0) { yield return(null); } // Reset each slot slot1.ResetSlotState(); slot2.ResetSlotState(); if (shapesBeingDestroyed == 0) { gameManager.CheckGameState(); } gameManager.MarkSwitchingAsComplete(); }
public static void CreateSlotShape(Transform slot, GameShape.ShapeType shapeType, GameShape.ColorType shapeColor, float shapeSize) { GameObject shapePrefab = Resources.Load <GameObject>("Prefabs/GameShape"); GameObject newShape = PrefabUtility.InstantiatePrefab(shapePrefab, slot) as GameObject; newShape.transform.localPosition = Vector3.zero; newShape.transform.localScale = new Vector3(shapeSize, shapeSize); GameShape shapeRef = newShape.GetComponent <GameShape>(); shapeRef.ConfigureShape(shapeType, shapeColor); GameSlot slotRef = slot.GetComponent <GameSlot>(); slotRef.SetSlotShapeReference(newShape.transform); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }