first commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace SingularityGroup.HotReload.Editor {
|
||||
internal class AllowAndroidAppToMakeHttpRequestsOption : ProjectOptionBase {
|
||||
public override string ShortSummary {
|
||||
get {
|
||||
return "Allow app to make HTTP requests";
|
||||
}
|
||||
}
|
||||
|
||||
public override string Summary => ShortSummary;
|
||||
|
||||
public override bool GetValue(SerializedObject so) {
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
// use PlayerSettings as the source of truth
|
||||
return PlayerSettings.insecureHttpOption != InsecureHttpOption.NotAllowed;
|
||||
#else
|
||||
return GetProperty(so).boolValue;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override string ObjectPropertyName =>
|
||||
nameof(HotReloadSettingsObject.AllowAndroidAppToMakeHttpRequests);
|
||||
|
||||
public override void SetValue(SerializedObject so, bool value) {
|
||||
base.SetValue(so, value);
|
||||
|
||||
// Enabling on Unity 2022 or newer → set the Unity option to ‘Development Builds only’
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
var notAllowed = PlayerSettings.insecureHttpOption == InsecureHttpOption.NotAllowed;
|
||||
if (value) {
|
||||
// user chose to enable it
|
||||
if (notAllowed) {
|
||||
PlayerSettings.insecureHttpOption = InsecureHttpOption.DevelopmentOnly;
|
||||
}
|
||||
} else {
|
||||
// user chose to disable it
|
||||
PlayerSettings.insecureHttpOption = InsecureHttpOption.NotAllowed;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void InnerOnGUI(SerializedObject so) {
|
||||
var description = "For Hot Reload to work on-device, please allow HTTP requests";
|
||||
EditorGUILayout.LabelField(description, HotReloadWindowStyles.WrapStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a7442cee510ab4498ca2a846e0c4e92
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb8474c37f13d704d96b43e0f681680d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace SingularityGroup.HotReload.Editor {
|
||||
/// <summary>
|
||||
/// An option stored inside the current Unity project.
|
||||
/// </summary>
|
||||
internal abstract class ProjectOptionBase : IOption, ISerializedProjectOption {
|
||||
public abstract string ShortSummary { get; }
|
||||
public abstract string Summary { get; }
|
||||
|
||||
public virtual bool GetValue(SerializedObject so) {
|
||||
return so.FindProperty(ObjectPropertyName).boolValue;
|
||||
}
|
||||
|
||||
protected SerializedProperty GetProperty(SerializedObject so) {
|
||||
return so.FindProperty(ObjectPropertyName);
|
||||
}
|
||||
|
||||
public virtual void SetValue(SerializedObject so, bool value) {
|
||||
so.FindProperty(ObjectPropertyName).boolValue = value;
|
||||
}
|
||||
|
||||
public virtual void InnerOnGUI(SerializedObject so) { }
|
||||
|
||||
public abstract string ObjectPropertyName { get; }
|
||||
|
||||
/// <remarks>
|
||||
/// Override this if your option is not needed for on-device Hot Reload to work.<br/>
|
||||
/// (by default, a project option must be true for Hot Reload to work)
|
||||
/// </remarks>
|
||||
public virtual bool IsRequiredForBuild() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An option that is stored on the user's computer (shared between Unity projects).
|
||||
/// </summary>
|
||||
internal abstract class ComputerOptionBase : IOption {
|
||||
public abstract string ShortSummary { get; }
|
||||
public abstract string Summary { get; }
|
||||
|
||||
public abstract bool GetValue();
|
||||
|
||||
/// Uses <see cref="HotReloadPrefs"/> for storing the value on the user's computer.
|
||||
public virtual void SetValue(bool value) { }
|
||||
|
||||
public bool GetValue(SerializedObject so) => GetValue();
|
||||
|
||||
public virtual void SetValue(SerializedObject so, bool value) => SetValue(value);
|
||||
|
||||
void IOption.InnerOnGUI(SerializedObject so) {
|
||||
InnerOnGUI();
|
||||
}
|
||||
public virtual void InnerOnGUI() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dab8ef53c2ee30a40ab6a7e4abd1260c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace SingularityGroup.HotReload.Editor {
|
||||
public interface IOption {
|
||||
string ShortSummary { get; }
|
||||
string Summary { get; }
|
||||
|
||||
/// <param name="so">The <see cref="HotReloadSettingsObject"/> wrapped by SerializedObject</param>
|
||||
bool GetValue(SerializedObject so);
|
||||
|
||||
/// <summary>
|
||||
/// Handle the new value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note: caller must skip calling this if value same as GetValue!
|
||||
/// </remarks>
|
||||
/// <param name="so">The <see cref="HotReloadSettingsObject"/> wrapped by SerializedObject</param>
|
||||
/// <param name="value"></param>
|
||||
void SetValue(SerializedObject so, bool value);
|
||||
|
||||
/// <param name="so">The <see cref="HotReloadSettingsObject"/> wrapped by SerializedObject</param>
|
||||
void InnerOnGUI(SerializedObject so);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An option scoped to the current Unity project.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// These options are intended to be shared with collaborators and used by Unity Player builds.
|
||||
/// </remarks>
|
||||
public interface ISerializedProjectOption {
|
||||
string ObjectPropertyName { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a626aa97160471f85de4646a634bdf1
|
||||
timeCreated: 1674574633
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using SingularityGroup.HotReload.Editor.Cli;
|
||||
using UnityEditor;
|
||||
|
||||
namespace SingularityGroup.HotReload.Editor {
|
||||
internal sealed class ExposeServerOption : ComputerOptionBase {
|
||||
|
||||
public override string ShortSummary => "Allow Devices to Connect";
|
||||
public override string Summary => "Allow Devices to Connect (WiFi)";
|
||||
|
||||
public override void InnerOnGUI() {
|
||||
string description;
|
||||
if (GetValue()) {
|
||||
description = "The HotReload server is reachable from devices on the same Wifi network";
|
||||
} else {
|
||||
description = "The HotReload server is available to your computer only. Other devices cannot connect to it.";
|
||||
}
|
||||
EditorGUILayout.LabelField(description, HotReloadWindowStyles.WrapStyle);
|
||||
}
|
||||
|
||||
public override bool GetValue() {
|
||||
return HotReloadPrefs.ExposeServerToLocalNetwork;
|
||||
}
|
||||
|
||||
public override void SetValue(SerializedObject so, bool val) {
|
||||
// AllowAndroidAppToMakeHttpRequestsOption
|
||||
if (val == HotReloadPrefs.ExposeServerToLocalNetwork) {
|
||||
return;
|
||||
}
|
||||
|
||||
HotReloadPrefs.ExposeServerToLocalNetwork = val;
|
||||
if (val) {
|
||||
// they allowed this one for mobile builds, so now we allow everything else needed for player build to work with HR
|
||||
new AllowAndroidAppToMakeHttpRequestsOption().SetValue(so, true);
|
||||
}
|
||||
RunTask(() => {
|
||||
RunOnMainThreadSync(() => {
|
||||
var isRunningResult = ServerHealthCheck.I.IsServerHealthy;
|
||||
if (isRunningResult) {
|
||||
var restartServer = EditorUtility.DisplayDialog("Hot Reload",
|
||||
$"When changing '{Summary}', the Hot Reload server must be restarted for this to take effect." +
|
||||
"\nDo you want to restart it now?",
|
||||
"Restart server", "Don't restart");
|
||||
if (restartServer) {
|
||||
CodePatcher.I.ClearPatchedMethods();
|
||||
EditorCodePatcher.RestartCodePatcher().Forget();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void RunTask(Action action) {
|
||||
var token = HotReloadWindow.Current.cancelToken;
|
||||
Task.Run(() => {
|
||||
if (token.IsCancellationRequested) return;
|
||||
try {
|
||||
action();
|
||||
} catch (Exception ex) {
|
||||
ThreadUtility.LogException(ex, token);
|
||||
}
|
||||
}, token);
|
||||
}
|
||||
|
||||
void RunOnMainThreadSync(Action action) {
|
||||
ThreadUtility.RunOnMainThread(action, HotReloadWindow.Current.cancelToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ab0973d3ae1275469237480381842c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace SingularityGroup.HotReload.Editor {
|
||||
internal class IncludeInBuildOption : ProjectOptionBase, ISerializedProjectOption {
|
||||
static IncludeInBuildOption _I;
|
||||
public static IncludeInBuildOption I = _I ?? (_I = new IncludeInBuildOption());
|
||||
public override string ShortSummary => "Include Hot Reload in player builds";
|
||||
public override string Summary => ShortSummary;
|
||||
|
||||
public override string ObjectPropertyName =>
|
||||
nameof(HotReloadSettingsObject.IncludeInBuild);
|
||||
|
||||
public override void InnerOnGUI(SerializedObject so) {
|
||||
string description;
|
||||
if (GetValue(so)) {
|
||||
description = "The Hot Reload runtime is included in development builds that use the Mono scripting backend.";
|
||||
} else {
|
||||
description = "The Hot Reload runtime will not be included in any build. Use this option to disable HotReload without removing it from your project.";
|
||||
}
|
||||
description += " This option does not affect Hot Reload usage in Playmode";
|
||||
EditorGUILayout.LabelField(description, HotReloadWindowStyles.WrapStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39ed4f822bcd81340bdf7189b3bc5016
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user