示例#1
0
        public static string FindUnusedName(string str)
        {
            int index     = 0;
            var dashIndex = str.LastIndexOf('-');

            if (dashIndex != -1)
            {
                var num = str.Substring(dashIndex);
                if (int.TryParse(num, out var res))
                {
                    // The file is named {Name}-(number) (eg. File-2)
                    str   = str.Substring(0, dashIndex);
                    index = res;
                }
            }

            var name = "";

            while (true)
            {
                name = index > 0 ? $"{str.Substring(0, str.Length > 22 ? 22 : str.Length)}-{index}" : str;
                if (!SaveExists(Saving.GetSavePath(name)))
                {
                    break;
                }

                index++;
            }

            return(name);
        }
示例#2
0
        public void Save()
        {
            if (SceneData.Name == null || SceneData.Name.Length == 0)
            {
                SceneData.Name = FindUnusedName(SceneData.IsTutorial ? "Tutorial" : "Unnamed");
            }

            var save     = GetSaveString();
            var savePath = Saving.GetSavePath(SceneData.Name);

            //File.WriteAllText(savePath, save);
            Saving.WriteSave(savePath, save);

            SceneData.AllowAutosave = true;
            Debug.Log($"Saved {SceneData.Name}");

            StopAllCoroutines();
            StartCoroutine(ChangedSaveText());
        }