-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
2023.5.hotfix
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 mod.io Proprietary Limited | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#if UNITY_EDITOR | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
using ModIO.Implementation; | ||
using ModIO.Implementation.Platform; | ||
|
||
namespace ModIO.EditorCode | ||
{ | ||
|
||
/// <summary>summary</summary> | ||
public static class EditorMenu | ||
{ | ||
static EditorMenu() | ||
{ | ||
new MenuItem("Tools/mod.io/Edit Settings", false, 0); | ||
} | ||
|
||
[MenuItem("Tools/mod.io/Edit Settings", false, 0)] | ||
public static void EditSettingsAsset() | ||
{ | ||
var settingsAsset = GetConfigAsset(); | ||
|
||
EditorGUIUtility.PingObject(settingsAsset); | ||
Selection.activeObject = settingsAsset; | ||
} | ||
|
||
|
||
internal static SettingsAsset GetConfigAsset() | ||
{ | ||
var settingsAsset = Resources.Load<SettingsAsset>(SettingsAsset.FilePath); | ||
|
||
// if it doesnt exist we create one | ||
if(settingsAsset == null) | ||
{ | ||
// create asset | ||
settingsAsset = ScriptableObject.CreateInstance<SettingsAsset>(); | ||
|
||
// ensure the directories exist before trying to create the asset | ||
if(!AssetDatabase.IsValidFolder("Assets/Resources")) | ||
{ | ||
AssetDatabase.CreateFolder("Assets", "Resources"); | ||
} | ||
if(!AssetDatabase.IsValidFolder("Assets/Resources/mod.io")) | ||
{ | ||
AssetDatabase.CreateFolder("Assets/Resources", "mod.io"); | ||
} | ||
|
||
AssetDatabase.CreateAsset(settingsAsset, $@"Assets/Resources/{SettingsAsset.FilePath}.asset"); | ||
|
||
//create a data representation of the Settings Asset | ||
SerializedObject so = new SerializedObject(settingsAsset); | ||
|
||
//Find properties and apply default values | ||
SerializedProperty serverSettingsProperty = so.FindProperty("serverSettings"); | ||
serverSettingsProperty.FindPropertyRelative("serverURL").stringValue = "https://api.mod.io/v1";; | ||
serverSettingsProperty.FindPropertyRelative("languageCode").stringValue = "en"; | ||
|
||
//Apply new values while ensuring the user cannot use "undo" to erase the initial values. | ||
so.ApplyModifiedPropertiesWithoutUndo(); | ||
|
||
//Grab any asset changes and unload unused assets | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
return settingsAsset; | ||
} | ||
|
||
[MenuItem("Tools/mod.io/Debug/Clear Data", false, 0)] | ||
public static void ClearStoredData() | ||
{ | ||
// Only used for the editor | ||
SystemIOWrapper.DeleteDirectory(EditorDataService.GlobalRootDirectory); | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#if UNITY_EDITOR | ||
using ModIO.Implementation; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
[CustomEditor(typeof(SettingsAsset))] | ||
public class SettingsAssetEditor : Editor | ||
{ | ||
private SerializedProperty serverURL; | ||
private SerializedProperty gameId; | ||
private SerializedProperty gameKey; | ||
private SerializedProperty languageCode; | ||
|
||
private void OnEnable() | ||
{ | ||
//get references to SerializedProperties | ||
var serverSettingsProperty = serializedObject.FindProperty("serverSettings"); | ||
serverURL = serverSettingsProperty.FindPropertyRelative("serverURL"); | ||
gameId = serverSettingsProperty.FindPropertyRelative("gameId"); | ||
gameKey = serverSettingsProperty.FindPropertyRelative("gameKey"); | ||
languageCode = serverSettingsProperty.FindPropertyRelative("languageCode"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
//Grab any changes to the original object data | ||
this.serializedObject.UpdateIfRequiredOrScript(); | ||
|
||
SettingsAsset myTarget = (SettingsAsset)target; | ||
|
||
base.OnInspectorGUI(); | ||
|
||
EditorGUILayout.Space(); | ||
|
||
GUIStyle labelStyle = new GUIStyle(); | ||
labelStyle.alignment = TextAnchor.MiddleCenter; | ||
labelStyle.fontStyle = FontStyle.Bold; | ||
labelStyle.normal.textColor = Color.white; | ||
|
||
EditorGUILayout.LabelField("Server Settings", labelStyle); | ||
if(myTarget.serverSettings.gameId == 0 || string.IsNullOrWhiteSpace(myTarget.serverSettings.gameKey)) | ||
{ | ||
EditorGUILayout.HelpBox("Once you've created a game profile on mod.io (or test.mod.io) " | ||
+ "you can input the game ID and Key below in order for the plugin " | ||
+ "to retrieve mods and information associated to your game.", | ||
MessageType.Info); | ||
} | ||
|
||
EditorGUILayout.PropertyField(serverURL, new GUIContent("Server URL")); | ||
EditorGUILayout.PropertyField(gameId,new GUIContent("Game ID")); | ||
gameKey.stringValue = EditorGUILayout.PasswordField("API Key", gameKey.stringValue); | ||
EditorGUILayout.PropertyField(languageCode, new GUIContent("Language code")); | ||
|
||
|
||
EditorGUILayout.Space(); | ||
EditorGUILayout.Space(); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
if(GUILayout.Button("Insert URL for Test API")) | ||
{ | ||
serverURL.stringValue = "https://api.test.mod.io/v1"; | ||
|
||
//remove focus from other fields | ||
GUI.FocusControl(null); | ||
} | ||
if(GUILayout.Button("Insert URL for Production API")) | ||
{ | ||
serverURL.stringValue = "https://api.mod.io/v1"; | ||
//remove focus from other fields | ||
GUI.FocusControl(null); | ||
} | ||
EditorGUILayout.EndHorizontal(); | ||
|
||
if(GUILayout.Button("Locate ID and API Key")) | ||
{ | ||
if(myTarget.serverSettings.serverURL == "https://api.test.mod.io/v1") | ||
{ | ||
Application.OpenURL("https://test.mod.io/apikey"); | ||
} | ||
else | ||
{ | ||
Application.OpenURL("https://mod.io/apikey"); | ||
} | ||
} | ||
|
||
//Save the new values | ||
this.serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.