Skip to content

Commit

Permalink
Merge pull request #10 from modio/Syncing-v2024.7.1
Browse files Browse the repository at this point in the history
Syncing v2024.7.1
  • Loading branch information
johnw-modio authored Aug 1, 2024
2 parents f69afac + 2e390b7 commit 1464563
Show file tree
Hide file tree
Showing 843 changed files with 45,642 additions and 2,267 deletions.
30 changes: 30 additions & 0 deletions Editor/ModIO.EditorCode/CacheOpener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.IO;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;

public static class CacheOpener
{
[MenuItem("Tools/mod.io/Open Cache")]
public static void OpenCache()
{
try
{
string path = Path.GetFullPath($"{Application.persistentDataPath}/mod.io");
#if UNITY_EDITOR_WIN || UNITY_EDITOR_LINUX
// Supposedly Linux uses the same executable name as windows, though not 100% confident
// so wrapping all this in a try catch.
System.Diagnostics.Process.Start("explorer.exe", path);
#elif UNITY_EDITOR_OSX
System.Diagnostics.Process.Start("open", $"-R \"{path}\"");
#endif
}
catch (Exception exception)
{
Debug.LogError($"Exception opening local cache: {exception.Message}\n{exception.StackTrace}");
}
}
}
#endif
11 changes: 11 additions & 0 deletions Editor/ModIO.EditorCode/CacheOpener.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions Editor/ModIO.EditorCode/EditorMenu.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;

using ModIO.Implementation;
using ModIO.Implementation.Platform;
using UnityEditor;
using UnityEngine;

namespace ModIO.EditorCode
{

/// <summary>summary</summary>
public static class EditorMenu
{
Expand All @@ -16,10 +15,11 @@ 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();
SettingsAsset settingsAsset = GetConfigAsset();

EditorGUIUtility.PingObject(settingsAsset);
Selection.activeObject = settingsAsset;
Expand All @@ -28,23 +28,19 @@ public static void EditSettingsAsset()

internal static SettingsAsset GetConfigAsset()
{
var settingsAsset = Resources.Load<SettingsAsset>(SettingsAsset.FilePath);
SettingsAsset settingsAsset = Resources.Load<SettingsAsset>(SettingsAsset.FilePath);

// if it doesnt exist we create one
if(settingsAsset == null)
if (settingsAsset == null)
{
// create asset
settingsAsset = ScriptableObject.CreateInstance<SettingsAsset>();

// ensure the directories exist before trying to create the asset
if(!AssetDatabase.IsValidFolder("Assets/Resources"))
{
if (!AssetDatabase.IsValidFolder("Assets/Resources"))
AssetDatabase.CreateFolder("Assets", "Resources");
}
if(!AssetDatabase.IsValidFolder("Assets/Resources/mod.io"))
{
if (!AssetDatabase.IsValidFolder("Assets/Resources/mod.io"))
AssetDatabase.CreateFolder("Assets/Resources", "mod.io");
}

AssetDatabase.CreateAsset(settingsAsset, $@"Assets/Resources/{SettingsAsset.FilePath}.asset");

Expand Down
42 changes: 42 additions & 0 deletions Editor/ModIO.EditorCode/ModioSettingProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using ModIO.Implementation;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace ModIO.EditorCode
{
public class ModioSettingProvider : SettingsProvider
{
SettingsAsset _config;
SerializedObject _serializedConfig;

ModioSettingProvider() :
base("mod.io/Settings", SettingsScope.Project, new HashSet<string>(new[] { "modio", "gameId", "gameKey", "apiKey", "Server URL" }))
{
}

public override void OnActivate(string searchContext, VisualElement rootElement)
{
_config = EditorMenu.GetConfigAsset();
_serializedConfig = new SerializedObject(_config);

rootElement.Add(new Label("mod.io Settings")
{
style =
{
marginLeft = 4,
fontSize = 19,
unityFontStyleAndWeight = FontStyle.Bold,
},
});
rootElement.Add(new InspectorElement(_serializedConfig));
}

[SettingsProvider]
public static SettingsProvider OpenModioSettingsProvider() => new ModioSettingProvider();
}
}
#endif
11 changes: 11 additions & 0 deletions Editor/ModIO.EditorCode/ModioSettingProvider.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 56 additions & 26 deletions Editor/ModIO.EditorCode/SettingsAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,68 @@
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SettingsAsset))]
[CustomEditor(typeof( SettingsAsset ))]
public class SettingsAssetEditor : Editor
{
SerializedProperty serverURL;
SerializedProperty gameId;
SerializedProperty gameKey;
SerializedProperty languageCode;
int previousGameId = 0;

void OnEnable()
SerializedProperty gameId;
SerializedProperty gameKey;
SerializedProperty languageCode;
int previousGameId;
SerializedProperty serverURL;
SerializedProperty useCommandLineArgumentOverrides;
SerializedProperty _showMonetizationUIProperty;
SerializedProperty _showEnabledModToggleProperty;

void OnEnable()
{
//get references to SerializedProperties
var serverSettingsProperty = serializedObject.FindProperty("serverSettings");
SerializedProperty serverSettingsProperty = serializedObject.FindProperty("serverSettings");
serverURL = serverSettingsProperty.FindPropertyRelative("serverURL");
gameId = serverSettingsProperty.FindPropertyRelative("gameId");
gameKey = serverSettingsProperty.FindPropertyRelative("gameKey");
languageCode = serverSettingsProperty.FindPropertyRelative("languageCode");
useCommandLineArgumentOverrides = serverSettingsProperty.FindPropertyRelative("useCommandLineArgumentOverrides");

var uiSettingsProperty = serializedObject.FindProperty("uiSettings");

_showMonetizationUIProperty = uiSettingsProperty.FindPropertyRelative("ShowMonetizationUI");
_showEnabledModToggleProperty = uiSettingsProperty.FindPropertyRelative("ShowEnabledModToggle");
}

public override void OnInspectorGUI()
{
{
//Grab any changes to the original object data
serializedObject.UpdateIfRequiredOrScript();

SettingsAsset myTarget = (SettingsAsset)target;

base.OnInspectorGUI();
DrawPropertiesExcluding(serializedObject, "m_Script");

EditorGUILayout.Space();
EditorGUILayout.Space();

GUIStyle labelStyle = new GUIStyle();
labelStyle.alignment = TextAnchor.MiddleCenter;
labelStyle.fontStyle = FontStyle.Bold;
labelStyle.normal.textColor = Color.white;
GUIStyle labelStyle = new GUIStyle
{
alignment = TextAnchor.MiddleCenter,
fontStyle = FontStyle.Bold,
normal =
{
textColor = Color.white,
},
};

EditorGUILayout.LabelField("Server Settings", labelStyle);
EditorGUILayout.LabelField("Server Settings", labelStyle);

EditorGUILayout.Space();

EditorGUILayout.PropertyField(gameId,new GUIContent("Game ID"));
gameKey.stringValue = EditorGUILayout.PasswordField("API Key", gameKey.stringValue);
EditorGUILayout.DelayedIntField(gameId, new GUIContent("Game ID"));
using (EditorGUI.ChangeCheckScope passwordChange = new EditorGUI.ChangeCheckScope())
{
string tempPassword = EditorGUILayout.PasswordField("API Key", gameKey.stringValue);
if (passwordChange.changed)
gameKey.stringValue = tempPassword;
}

if(myTarget.serverSettings.gameId == 0 || string.IsNullOrWhiteSpace(myTarget.serverSettings.gameKey))
if (myTarget.serverSettings.gameId == 0 || string.IsNullOrWhiteSpace(myTarget.serverSettings.gameKey))
{
EditorGUILayout.Space();

Expand Down Expand Up @@ -76,11 +95,14 @@ public override void OnInspectorGUI()
EditorGUILayout.EndHorizontal();

EditorGUILayout.Space();
} else {
}
else
{
EditorGUILayout.Space();

EditorGUILayout.PropertyField(serverURL, new GUIContent("Server URL"));
EditorGUILayout.PropertyField(languageCode, new GUIContent("Language code"));
EditorGUILayout.DelayedTextField(serverURL, new GUIContent("Server URL"));
EditorGUILayout.DelayedTextField(languageCode, new GUIContent("Language code"));
EditorGUILayout.PropertyField(useCommandLineArgumentOverrides, new GUIContent("Use Command Line Argument Override"));

EditorGUILayout.Space();

Expand All @@ -96,16 +118,23 @@ public override void OnInspectorGUI()
}

// If the gameId has been changed, update the url
if (gameId.intValue != previousGameId)
if (gameId.intValue != previousGameId)
{
if (IsURLProduction(serverURL.stringValue))
serverURL.stringValue = GetURLProduction(gameId.intValue);

previousGameId = gameId.intValue;
}
previousGameId = gameId.intValue;
}

EditorGUILayout.Space();
EditorGUILayout.LabelField("UI Settings", labelStyle);

EditorGUILayout.PropertyField(_showMonetizationUIProperty);
EditorGUILayout.PropertyField(_showEnabledModToggleProperty);

//Save the new values
serializedObject.ApplyModifiedProperties();
AssetDatabase.SaveAssetIfDirty(serializedObject?.targetObject);

return;

Expand All @@ -123,6 +152,7 @@ void SetURLTest()
}

internal static string GetURLProduction(int gameId) => $"https://g-{gameId}.modapi.io/v1";

static string GetURLTest(int gameId) => "https://api.test.mod.io/v1";

static bool IsURLProduction(string url) => Regex.IsMatch(url, @"https:\/\/g-\d*.modapi.io\/v1");
Expand Down
8 changes: 8 additions & 0 deletions Experimental.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Experimental/modio-ui.unitypackage
Binary file not shown.
7 changes: 7 additions & 0 deletions Experimental/modio-ui.unitypackage.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Platform/Steam/Facepunch.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Platform/Steam/Facepunch/ModioPlatformExampleFacepunch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#if UNITY_FACEPUNCH
using Steamworks;
#endif
using UnityEngine;

namespace ModIO.Implementation.Platform
{
public class ModioPlatformExampleFacepunch : MonoBehaviour
{
[SerializeField] int appId;

void Awake()
{
bool supportedPlatform = !Application.isConsolePlatform;

#if !UNITY_FACEPUNCH
supportedPlatform = false;
#endif

if (!supportedPlatform)
{
Destroy(this);
return;
}

#if UNITY_FACEPUNCH
try
{
SteamClient.Init((uint)appId, true);
}
catch (System.Exception e)
{
Debug.Log(e);
return;
}
#endif

// --- This is the important line to include in your own implementation ---
ModioPlatformFacepunch.SetAsPlatform();
}

#if UNITY_FACEPUNCH
void OnDisable()
{
SteamClient.Shutdown();
}

void Update()
{
SteamClient.RunCallbacks();
}
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1464563

Please sign in to comment.