public override void OnTitleSetState(UIState state) { if ((int)state >= 2) { saveSlotContents = new Battle.BattleData[3]; allSlotsEmpty = true; for (int i = 0; i < saveSlotContents.Length; i++) { try { FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, i.ToString()), FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); Debug.Log(stream.Length); object deserialized = formatter.Deserialize(stream); stream.Close(); saveSlotContents[i] = (Battle.BattleData)deserialized; allSlotsEmpty = false; } catch { saveSlotContents[i] = new Battle.BattleData(); } } } }
public void ClearSlot(int slot) { saveSlotContents[slot] = new Battle.BattleData(); BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(Path.Combine(Application.persistentDataPath, slot.ToString()), FileMode.Create); formatter.Serialize(stream, 0); stream.Close(); }
void OnEnable() { if (boundTo.CheckSlot(managedSlot)) { Destroy(pixelParent); pixelParent = new GameObject("Pixel Parent"); pixelParent.transform.SetParent(transform, false); pixelParent.transform.SetAsLastSibling(); Battle.BattleData data = boundTo.saveSlotContents[managedSlot]; for (int player = 0; player < 2; player++) { Player.PlayerData playerData = player == 0 ? data.attacker : data.defender; float[,,] flag = playerData.flag; Vector2 beginningPos = (player == 0 ? Vector2.one * (pixelSide / 2.0f + 20) : new Vector2((640 - pixelSide / 2.0f) - pixelSide * flag.GetLength(0), pixelSide / 2.0f + 20)) - new Vector2(320, 80); for (int x = 0; x < flag.GetLength(0); x++) { for (int y = 0; y < flag.GetLength(1); y++) { Color color = new Color(flag[x, y, 0], flag[x, y, 1], flag[x, y, 2]); GameObject pixel = Instantiate(pixelPrefab); pixel.transform.SetParent(pixelParent.transform, false); pixel.transform.localPosition = beginningPos + new Vector2(x, y) * pixelSide; pixel.GetComponent <RawImage>().color = color; } } } clearButton.gameObject.SetActive(true); label.text = usedMessage; } else { label.text = emptyMessage; clearButton.gameObject.SetActive(false); } }