Example #1
0
 public void EndActionReinsertTile(List <GameObject> tiles)
 {
     foreach (var tile in tiles)
     {
         collectionHelper.ProcessCubeTile(tile);
     }
 }
Example #2
0
    internal void LoadGame(MagicCubeSaveData savedata)
    {
        bIsLoading = true;
        foreach (var item in cubeTiles)
        {
            UnityEngine.Object.Destroy(item);
        }

        cubeTiles.Clear();
        collectionHelper = new CubeCollectionHelper(0);

        for (int i = 0; i < savedata.positions.Count; i++)
        {
            var temp = GameObject.Instantiate(cubeTileRef,
                                              savedata.positions[i].ToVector3()
                                              , savedata.rotations[i].ToQuaternion());
            collectionHelper.ProcessCubeTile(temp, temp.transform.position);
            temp.transform.SetParent(ownHolder.transform);
            cubeTiles.Add(temp);
            temp.GetComponent <CubeTileInfo>().SetID(savedata.cubeTileIDs[i]);
        }

        actionList.Clear();
        for (int i = 0; i < savedata.undoActions.Count; i++)
        {
            CubeAction        action             = null;
            List <GameObject> cubeTilesForAction = new List <GameObject>();
            foreach (var cubeID in savedata.undoActions[i].cubeCollection)
            {
                cubeTilesForAction.Add(cubeTiles.Find(ct => ct.GetComponent <CubeTileInfo>().GetID() == cubeID));
            }
            switch (savedata.undoActions[i].action)
            {
            case (int)ActionSaveData.ActionType.ZXClock:
                action = new ActionRotateZXClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZXCounterClock:
                action = new ActionRotateZXCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.YXClock:
                action = new ActionRotateYXClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.YXCounterClock:
                action = new ActionRotateYXCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZYClock:
                action = new ActionRotateZYClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZYCounterClock:
                action = new ActionRotateZYCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;
            }
            if (action == null)
            {
                actionList.Clear();
                break;
            }
            action.CompleteActionNoAnimation();
            actionList.Add(action);
        }

        timePassed = savedata.time;
        seconds    = savedata.time;
        updateTime(seconds);
        processUndoRedoPossible(actionList.Count > 0);
        bIsLoading = false;
    }