示例#1
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();
            }
        }