예제 #1
0
        public void SelectState(SavedGameListItem item)
        {
            if (_selected != null)
            {
                _selected.Selected = false;
            }
            _selected          = item;
            _selected.Selected = true;
            string filepath = Path.Combine(UnityEngine.Application.persistentDataPath, _selected.Snapshot);

            if (File.Exists(filepath))
            {
                byte[]    bytes = File.ReadAllBytes(filepath);
                Texture2D tex   = new Texture2D(1, 1);
                Snapshot.gameObject.SetActive(true);
                tex.LoadImage(bytes);
                Snapshot.sprite         = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0));
                Snapshot.preserveAspect = true;
            }
            else
            {
                Snapshot.gameObject.SetActive(false);
            }
            LoadGameButton.interactable = true;
            TitleText.text = _selected.SaveText.text;

            if (this.isActiveAndEnabled)
            {
                StartCoroutine(ContentFitterHax());
            }

            _index = Pool.Count - Pool.IndexOf(_selected) - 1;
        }
예제 #2
0
        private void OnDelete()
        {
            if (_selected != null)
            {
                if (_index >= 0)
                {
                    _saves.RemoveAt(_index);
                }
                if (_index == AmbitionApp.Game.SaveSlotID)
                {
                    AmbitionApp.Game.SaveSlotID = -1;
                }
                _dirty = true;
                _index = -1;
                Destroy(_selected.gameObject);
                SaveStateGroup.SetAllTogglesOff(true);
                TitleText.text = "";
                LoadGameButton.interactable = false;
                Snapshot.gameObject.SetActive(false);
                _selected = null;

                FileCountTxt.text  = _saves.Count + "/" + AmbitionApp.Game.MaxSaves;
                FileCountTxt.color = (_saves.Count > AmbitionApp.Game.MaxSaves)
                     ? Color.red
                     : _defaultCountTextColor;
            }
        }
예제 #3
0
        public override void OnOpen()
        {
            string        filepath = Path.Combine(UnityEngine.Application.persistentDataPath, Filepath.SAVE_FILE);
            Transform     parent   = Pool[0].transform.parent;
            GameObject    obj;
            int           poolCount = Pool.Count;
            int           p         = 0;
            List <string> snapshots = new List <string>(Directory.GetFiles(UnityEngine.Application.persistentDataPath));

            snapshots.RemoveAll(s => !s.EndsWith(".jpg"));

            if (File.Exists(filepath))
            {
                string result = File.ReadAllText(filepath);
                _saves = JsonConvert.DeserializeObject <List <string[]> >(result);
            }
            _saves ??= new List <string[]>();
            FileCountTxt.text      = _saves.Count + "/" + AmbitionApp.Game.MaxSaves;
            _defaultCountTextColor = FileCountTxt.color;
            if (_saves.Count > AmbitionApp.Game.MaxSaves)
            {
                FileCountTxt.color = Color.red;
            }

            // the last item is the most recent; list that at the top
            for (int i = _saves.Count - 1; i >= 0; --i)
            {
                if (p < poolCount)
                {
                    Pool[p++].SetData(_saves[i]);
                }
                else
                {
                    obj       = Instantiate(Pool[0].gameObject, parent);
                    _selected = obj.GetComponent <SavedGameListItem>();
                    _selected.SetData(_saves[i]);
                    Pool.Add(_selected);
                }
                snapshots.Remove(Path.Combine(UnityEngine.Application.persistentDataPath, _saves[i][1]));
            }
            for (int i = _saves.Count; i < poolCount; ++i)
            {
                Pool[i].gameObject.SetActive(false);
            }
            foreach (string snapshot in snapshots)
            {
                filepath = Path.Combine(UnityEngine.Application.persistentDataPath, snapshot);
                File.Delete(filepath);
            }
            if (!string.IsNullOrEmpty(Pool[0].Data))
            {
                SelectState(Pool[0]);
            }
        }