예제 #1
0
        private void DeleteOldSaves(string _path)
        {
            string serverDatas = "";

            string[] files = Directory.GetFiles(_path);
            foreach (string file in files)
            {
                //select .json files
                if (file.EndsWith(".json"))
                {
                    File.Delete(file); File.Delete(file + ".meta");
                }
            }

            //request playfab server
            var getRequest = new PlayFab.ServerModels.GetTitleDataRequest();

            PlayFabServerAPI.GetTitleData(getRequest, (result) =>
            {
                foreach (var entry in result.Data)
                {
                    if (string.Compare(entry.Key, "Achievements") == 0)
                    {
                        //create a new save file with playfab datas
                        serverDatas = entry.Value;
                        Achievement.PushToLocalJSON(serverDatas, _path);
                    }
                }
            },
                                          (error) => {
                Debug.Log("Got error getting titleData:");
                Debug.Log(error.ErrorMessage);
            });
        }
        private void OnGUI()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            EditorGUILayout.BeginHorizontal();
            if (!add)
            {
                add = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/TestPlayFab/Editor/Resources/plus.png", typeof(Texture));
            }
            if (GUILayout.Button(add, GUILayout.Width(64), GUILayout.Height(64)))
            {
                if (!creator)
                {
                    creator = new AchievementsCreator();
                    creator.Display();
                }
            }

            if (Achievement.achievements.Count != 0)
            {
                if (achievementsTexture == null || achievementsTexture.Length < Achievement.achievements.Count)
                {
                    achievementsTexture = new Texture2D[Achievement.achievements.Count];
                }
                for (int i = 0; i < Achievement.achievements.Count; i++)
                {
                    if (!achievementsTexture[i])
                    {
                        achievementsTexture[i] = (Texture2D)AssetDatabase.LoadAssetAtPath(Achievement.achievements[i].sPath, typeof(Texture));
                    }
                    if (GUILayout.Button(achievementsTexture[i], GUILayout.Width(64), GUILayout.Height(64)))
                    {
                        Achievement.EditorDisplay(Achievement.achievements[i]);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Save to PlayFab", GUILayout.Width(128), GUILayout.Height(20)))
            {
                Achievement.PushToPlayFab(position);
            }

            else if (GUILayout.Button("Load From Playfab", GUILayout.Width(128), GUILayout.Height(20)))
            {
                Achievement.LoadFromPlayfab(position);
            }

            else if (GUILayout.Button("Clear list", GUILayout.Width(128), GUILayout.Height(20)))
            {
                Achievement.ClearList();
            }

            else if (GUILayout.Button("Save to Local", GUILayout.Width(128), GUILayout.Height(20)))
            {
                folderPath = EditorUtility.OpenFolderPanel("Select destination folder", folderPath, "");
                if (folderPath != string.Empty)
                {
                    Achievement.PushToLocalJSON(folderPath);
                }
            }
            else if (GUILayout.Button("Load from Local", GUILayout.Width(128), GUILayout.Height(20)))
            {
                filePath = EditorUtility.OpenFilePanel("Select destination folder", filePath, "json");
                if (filePath != string.Empty)
                {
                    Achievement.LoadFromLocalJSON(filePath);
                }
            }
            EditorGUILayout.EndHorizontal();
        }