示例#1
0
        // Add menu item named "My Window" to the Window menu

        /*[MenuItem("GameSparks/REST Api")]
         * public static void ShowWindow()
         * {
         *      //Show existing window instance. If one doesn't exist, make one.
         *      EditorWindow.GetWindow(typeof(GameSparksRestWindow));
         * }*/

        void OnGUI()
        {
            GUILayout.Label("Binary Content", EditorStyles.boldLabel);
            shortCode = EditorGUILayout.TextField("ShortCode", shortCode);


            EditorGUILayout.BeginHorizontal();
            userName = EditorGUILayout.TextField("User Name", userName);
            password = EditorGUILayout.PasswordField("Password", password);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("GET"))
            {
                result = GameSparksRestApi.getDownloadable(GameSparksSettings.ApiKey, userName, password, shortCode);
            }

            if (GUILayout.Button("POST"))
            {
                result = GameSparksRestApi.setDownloadable(GameSparksSettings.ApiKey, userName, password, shortCode, fileName);
            }

            if (GUILayout.Button(fileName))
            {
                fileName = EditorUtility.OpenFilePanel("Select file to upload", "", "");
            }


            EditorGUILayout.EndHorizontal();
            GUILayout.Label("REST Output", EditorStyles.label);
            GUILayout.TextArea(result, EditorStyles.textField);
        }
示例#2
0
        private static void UpdateSDK(Boolean silentMode)
        {
            string lastVersion = GameSparksRestApi.GetLastVersion();

            if (lastVersion != null)
            {
                Debug.Log("Latest version available: " + lastVersion);

                if (GameSparksRestApi.CompareCurrentWithLastVersion(GameSparks.Core.GS.Version, lastVersion))
                {
                    if (EditorUtility.DisplayDialog("GameSparks SDK", "There is a new SDK available.\nUpdate to the latest version now.", "OK"))
                    {
                        Debug.Log("Updating GameSparks SDK from " + GameSparks.Core.GS.Version + " to " + lastVersion + " version");

                        if (GameSparksRestApi.UpdateSDK(lastVersion))
                        {
                            Debug.Log("Updated GameSparks SDK!");

                            Application.OpenURL("https://docs2.gamesparks.com/sdk-center/unity.html?utm_source=Unity%20SDK&utm_campaign=Unity%20Asset%20Store&utm_medium=Unity%20Editor");
                        }
                    }
                }
                else
                {
                    if (!silentMode)
                    {
                        EditorUtility.DisplayDialog("GameSparks SDK", "The SDK is already up to date.", "OK");
                    }
                }
            }
            else
            {
                if (!silentMode)
                {
                    EditorUtility.DisplayDialog("GameSparks SDK", "Error occured during getting last version!", "OK");
                }
            }
        }
        private static void UpdateSDK(Boolean silentMode)
        {
            string lastVersion = GameSparksRestApi.GetLastVersion();

            if (lastVersion != null)
            {
                Debug.Log("Latest version available: " + lastVersion);

                if (GameSparksRestApi.CompareCurrentWithLastVersion(GameSparks.Core.GS.Version, lastVersion))
                {
                    if (EditorUtility.DisplayDialog("GameSparks SDK", "There is a new available SDK.\nWould you like to update it?", "Yes", "No"))
                    {
                        Debug.Log("Updating GameSparks SDK from " + GameSparks.Core.GS.Version + " to " + lastVersion + " version");

                        if (GameSparksRestApi.UpdateSDK(lastVersion))
                        {
                            Debug.Log("Updated GameSparks SDK!");
                        }
                    }
                }
                else
                {
                    if (!silentMode)
                    {
                        EditorUtility.DisplayDialog("GameSparks SDK", "Sorry, there is any new available SDK.", "OK");
                    }
                }
            }
            else
            {
                if (!silentMode)
                {
                    EditorUtility.DisplayDialog("GameSparks SDK", "Error occured during getting last version!", "OK");
                }
            }
        }
示例#4
0
        public override void OnInspectorGUI()
        {
            GameSparksSettings settings = (GameSparksSettings)target;

            GameSparksSettings.SetInstance(settings);

            GUILayout.TextArea("SDK Version : " + GameSparks.Core.GS.Version, EditorStyles.wordWrappedLabel);

            EditorGUILayout.HelpBox("Add the GameSparks Api Key and Secret associated with this game", MessageType.None);

            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.ApiKey = EditorGUILayout.TextField(apiKeyLabel, GameSparksSettings.ApiKey).Trim();
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.ApiSecret = EditorGUILayout.TextField(apiSecretLabel, GameSparksSettings.ApiSecret).Trim();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.Credential = EditorGUILayout.TextField(credentialLabel, GameSparksSettings.Credential);
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.PreviewBuild = EditorGUILayout.Toggle(previewLabel, GameSparksSettings.PreviewBuild);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.DebugBuild = EditorGUILayout.Toggle(debugLabel, GameSparksSettings.DebugBuild);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();


            String testScenePath = "Assets/GameSparks/TestUI/GameSparksTestUI.unity";

            String testButtonText = "Test Configuration";

            if (EditorApplication.currentScene.Equals(testScenePath) && EditorApplication.isPlaying)
            {
                testButtonText = "Stop Test";
            }

            if (GameSparksSettings.ApiKey != null && GameSparksSettings.ApiSecret != null)
            {
                String myApiPath = "Assets/GameSparks/MyGameSparks.cs";
                GUILayout.TextArea("Download your custom data structures into your own SDK. Be sure to update this if you change the structure of Events and Leaderboards within the developer portal", EditorStyles.wordWrappedLabel);
                if (GUILayout.Button("Get My Custom SDK"))
                {
                    String myApi = GameSparksRestApi.getApi();
                    if (myApi != null)
                    {
                        Debug.Log("Updating GameSparks Api for game." + GameSparksSettings.ApiKey);
                        Directory.CreateDirectory(Path.GetDirectoryName(myApiPath));
                        using (StreamWriter outfile = new StreamWriter(myApiPath))
                        {
                            outfile.Write(myApi);
                        }
                    }
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.Refresh();
                }

                GUILayout.TextArea("Get the latest GameSparks SDK version.", EditorStyles.wordWrappedLabel);

                if (GUILayout.Button("Update SDK"))
                {
                    UpdateSDK(false);
                }
            }

            GUILayout.TextArea("Run the GameSparks test harness in the editor. ", EditorStyles.wordWrappedLabel);
            if (GUILayout.Button(testButtonText))
            {
                EditorUtility.SetDirty(settings);
                if (EditorApplication.currentScene.Equals(testScenePath) && EditorApplication.isPlaying)
                {
                    EditorApplication.isPlaying = false;
                }
                else
                {
                    if (!EditorApplication.currentScene.Equals(testScenePath))
                    {
                        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                        {
                            if (!EditorApplication.OpenScene(testScenePath))
                            {
                                EditorApplication.NewScene();
                                new GameObject("GameSparks", typeof(GameSparksTestUI), typeof(GameSparksUnity));
                                EditorApplication.SaveScene(testScenePath);
                            }
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        EditorApplication.isPlaying = true;
                    }
                }
            }
            if (GUI.changed)
            {
                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
            }
        }
        public override void OnInspectorGUI()
        {
            GameSparksSettings settings = (GameSparksSettings)target;

            GameSparksSettings.SetInstance(settings);

            GUILayout.TextArea("SDK Version : " + GameSparks.Core.GS.Version, EditorStyles.wordWrappedLabel);

            EditorGUILayout.HelpBox("Add the GameSparks Api Key and Secret associated with this game", MessageType.None);

            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.ApiKey = EditorGUILayout.TextField(apiKeyLabel, GameSparksSettings.ApiKey);
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.ApiSecret = EditorGUILayout.TextField(apiSecretLabel, GameSparksSettings.ApiSecret);
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.PreviewBuild = EditorGUILayout.Toggle(previewLabel, GameSparksSettings.PreviewBuild);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GameSparksSettings.DebugBuild = EditorGUILayout.Toggle(debugLabel, GameSparksSettings.DebugBuild);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();


            String testScenePath = "Assets/GameSparks/TestUI/GameSparksTestUI.unity";

            String testButtonText = "Test Configuration";

            if (EditorApplication.currentScene.Equals(testScenePath) && EditorApplication.isPlaying)
            {
                testButtonText = "Stop Test";
            }

            if (GameSparksSettings.ApiKey != null && GameSparksSettings.ApiSecret != null)
            {
                String myApiPath = "Assets/GameSparks/MyGameSparks.cs";
                GUILayout.TextArea("Download your custom data structures into your own SDK. Be sure to update this if you change the structure of Events and Leaderboards within the developer portal", EditorStyles.wordWrappedLabel);
                if (GUILayout.Button("Get My Custom SDK"))
                {
                    String myApi = GameSparksRestApi.getApi();
                    if (myApi != null)
                    {
                        Debug.Log("Updating GameSparks Api for game." + GameSparksSettings.ApiKey);
                        Directory.CreateDirectory(Path.GetDirectoryName(myApiPath));
                        using (StreamWriter outfile = new StreamWriter(myApiPath))
                        {
                            outfile.Write(myApi);
                        }
                    }
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.Refresh();
                }

                //			GUILayout.TextArea("Get the latest GameSparks SDK version.", EditorStyles.wordWrappedLabel);
                //
                //			if(GUILayout.Button("Update SDK")){
                //				System.Xml.XmlReader sdkInfo = GameSparksRestApi.GetSDKInfo();
                //				if(sdkInfo != null){
                //					while(sdkInfo.Read()){
                //
                //						if((sdkInfo.NodeType == System.Xml.XmlNodeType.Element) && (sdkInfo.Name == "sdk"))
                //						{
                //							string serverVersion = sdkInfo.GetAttribute("version");
                //							Debug.Log ("Server Version " + serverVersion);
                //							if(GameSparksSettings.SdkVersion == null || !GameSparksSettings.SdkVersion.Equals(serverVersion)){
                //								Debug.Log ("Updating GameSparks SDK");
                //								System.Xml.XmlReader files = sdkInfo.ReadSubtree();
                //								while(files.Read()){
                //									if((files.NodeType == System.Xml.XmlNodeType.Element) && (files.Name == "file")){
                //										GameSparksRestApi.UpdateSDKFile(files.GetAttribute("source"), files.GetAttribute("target"));
                //									}
                //								}
                //								Debug.Log ("Updating GameSparks Version: from (" + GameSparksSettings.SdkVersion + ") to (" + serverVersion + ")");
                //								GameSparksSettings.SdkVersion = serverVersion;
                //								EditorUtility.SetDirty(instance);
                //								AssetDatabase.Refresh();
                //							} else {
                //								break;
                //							}
                //						}
                //					}
                //				}
                //
                //			}
            }

            GUILayout.TextArea("Run the GameSparks test harness in the editor. ", EditorStyles.wordWrappedLabel);
            if (GUILayout.Button(testButtonText))
            {
                EditorUtility.SetDirty(settings);
                if (EditorApplication.currentScene.Equals(testScenePath) && EditorApplication.isPlaying)
                {
                    EditorApplication.isPlaying = false;
                }
                else
                {
                    if (!EditorApplication.currentScene.Equals(testScenePath))
                    {
                        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                        {
                            if (!EditorApplication.OpenScene(testScenePath))
                            {
                                EditorApplication.NewScene();
                                new GameObject("GameSparks", typeof(GameSparksTestUI), typeof(GameSparksUnity));
                                EditorApplication.SaveScene(testScenePath);
                            }
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        EditorApplication.isPlaying = true;
                    }
                }
            }
            if (GUI.changed)
            {
                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
            }
        }