public static bool GetState(MagicCube magicCube) { if (saveData.magicCubes == null) { return(false); } if (saveData.magicCubes.Any(t => t.id == magicCube.name)) { return(saveData.magicCubes.FirstOrDefault(t => t.id == magicCube.name).bRed); } return(false); }
public static MagicCube CreateFromSerializedData(SaveGameSystem.SerializableCubeData data, int individualCubeSizeInWorldUnits, IndividualCubeController individualCubePrefab) { //Generate cube from data var newCube = new MagicCube(data.gameSize, individualCubeSizeInWorldUnits, individualCubePrefab); foreach (var cube in data.cubeData) { var cubego = newCube.CreateSubCube(cube.currentCoordinates.x, cube.currentCoordinates.y, cube.currentCoordinates.z, cube.goalCoordinates); cubego.transform.localRotation = cube.rotation; } return(newCube); }
public static void SetState(MagicCube magicCube, bool bRed) { if (saveData.magicCubes == null) { saveData.magicCubes = new List <MagicCubeData>(); } var magicCubeData = new MagicCubeData() { id = magicCube.name, bRed = bRed }; saveData.magicCubes.RemoveAll(t => t.id == magicCubeData.id); saveData.magicCubes.Add(magicCubeData); }
private static void Create() { if (null == s_MagicCube) { GameObject gameObject = new GameObject(typeof(MagicCube).Name); s_MagicCube = gameObject.AddComponent<MagicCube>(); } s_MagicCube.Generate(s_Id, s_Step, s_Size, s_Space, 0); s_DestCube = s_MagicCube.destCube; List<CubeItem> cubeList = s_MagicCube[s_MagicCube.layer]; CubeItem cube = cubeList[UnityEngine.Random.Range(0, cubeList.Count)]; List<AxisType> axisTypes = new List<AxisType>(cube.itemDict.Keys); int index = UnityEngine.Random.Range(0, axisTypes.Count); AxisType upAxis = axisTypes[index]; axisTypes = new List<AxisType>(Enum.GetValues(typeof(AxisType)) as AxisType[]); axisTypes.Remove(upAxis); axisTypes.Remove((AxisType)(-(int)upAxis)); index = UnityEngine.Random.Range(0, axisTypes.Count); AxisType rightAxis = axisTypes[index]; axisTypes.Remove(rightAxis); axisTypes.Remove((AxisType)(-(int)rightAxis)); index = UnityEngine.Random.Range(0, axisTypes.Count); AxisType forwardAxis = axisTypes[index]; s_SpawnInfo = new SpawnInfo(); s_SpawnInfo.id = cube.id; s_SpawnInfo.right = rightAxis; s_SpawnInfo.up = upAxis; s_SpawnInfo.forward = forwardAxis; Selection.activeGameObject = s_MagicCube.gameObject; }
private void Start() { Application.targetFrameRate = 60; Input.simulateMouseWithTouches = true; //this.ingameUI.FadeIn(); this.cubeHighlighter = GameObject.Instantiate(this.HighlightCubePrefab); this.cubeHighlighter.gameObject.SetActive(false); //Hide the undo button until we start adding rotations. //Delete this if we end up serializing performed rotations at some point ingameUI.HideUndoButton(); System.TimeSpan accumulatedTime = System.TimeSpan.Zero; this.orbitingCamera.SetCameraPosition(cameraStartingPosition.x, cameraStartingPosition.y, cameraStartingPosition.z); switch (PerSessionData.newGameMode) { case PerSessionData.GameModes.Resume: Debug.Log("Loading cube from playerprefs"); SaveGameSystem.LoadGameState( out SaveGameSystem.SerializableCubeData cubeData, out accumulatedTime ); this.magicCube = MagicCube.CreateFromSerializedData(cubeData, 1, this.IndividualCubePrefab); this.inputManager.allowRotations = true; break; case PerSessionData.GameModes.NewGame: Debug.Log("Creating a new game"); this.magicCube = MagicCube.CreateFromNewGame(PerSessionData.CubeSize, 1, this.IndividualCubePrefab); StartCoroutine(this.ScrambleCube()); break; } this.currentGameTimer = new GameTimer(accumulatedTime); RefreshUITimeCounter = StartCoroutine(TimerTick()); }
private void OnEnable() { if (null != s_MagicCube && target != s_MagicCube) { DestroyImmediate(s_MagicCube.gameObject); } s_MagicCube = target as MagicCube; }
//Creates the entire Rubik cube out of smaller cubes that make up a "shell" public static MagicCube CreateFromNewGame(int gameSize, float individualCubeSizeInWorldUnits, IndividualCubeController individualCubePrefab) { Debug.Assert(gameSize > 1); var newCube = new MagicCube(gameSize, individualCubeSizeInWorldUnits, individualCubePrefab); //Possibly this could be refactored into a helper method that creates planes of cubes of a certain side //X plates (full size) for (int j = 0; j < gameSize; j++) { for (int k = 0; k < gameSize; k++) { newCube.CreateSubCube(0, j, k); } } for (int j = 0; j < gameSize; j++) { for (int k = 0; k < gameSize; k++) { newCube.CreateSubCube(gameSize - 1, j, k); } } //Second plates (smaller) //y plates for (int i = 1; i < gameSize - 1; i++) { for (int k = 0; k < gameSize; k++) { newCube.CreateSubCube(i, 0, k); } } for (int i = 1; i < gameSize - 1; i++) { for (int k = 0; k < gameSize; k++) { newCube.CreateSubCube(i, gameSize - 1, k); } } //Z plates for (int i = 1; i < gameSize - 1; i++) { for (int j = 1; j < gameSize - 1; j++) { newCube.CreateSubCube(i, j, 0); } } for (int i = 1; i < gameSize - 1; i++) { for (int j = 1; j < gameSize - 1; j++) { newCube.CreateSubCube(i, j, gameSize - 1); } } // Code for a full cube //for (int i = 0; i<gameSize ; i++) { // for (int j = 0; j<gameSize ; j++) { // for (int k = 0; k<gameSize ; k++) { // var newCube = GameObject.Instantiate(this.individualCubePrefab, cubesParent); // newCube.transform.position = // CubeCoordinatesToWorld(i,j,k); // //Cube was placed, now let's do housekeeping // newCube.goalCoordinates = new Vector3Int(i,j,k); // newCube.currentCoordinates = newCube.goalCoordinates; // allCubes.Add(newCube); // } // } //} return(newCube); }
public void initialize(MagicCube magicCube, int direction) { this.magicCube = magicCube; this.direction = direction; }