Skip to content

Commit

Permalink
feat: Modernize settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jan 11, 2025
1 parent 48c2d7f commit 97bac15
Show file tree
Hide file tree
Showing 33 changed files with 7,684 additions and 5,265 deletions.
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Resources/JCS_Managers.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4bbeb25e792087645b19e4cf30c3218a, type: 3}
m_Name:
m_EditorClassIdentifier:
mGameDoneInitialize: 0
mDoneInitialize: 0
--- !u!114 &11439248
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -162,7 +162,7 @@ MonoBehaviour:
mAlign: 0
mPopWhiteScreen: 1
mWhiteScreen: {fileID: 0}
mSwitchSceneType: 1
mSwitchSceneType: 2
mOverrideSetting: 0
mSceneFadeInTime: 1
mSceneFadeOutTime: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Interfaces/JCS_Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class JCS_Cursor : JCS_Settings<JCS_Cursor>

protected virtual void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

#if UNITY_EDITOR
mShowCursor = true;
Expand Down
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Scripts/Interfaces/JCS_Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class JCS_InstanceOld<T> : JCS_Instance<T>
/// <param name="destroyGO">
/// If true, destory the entire game object instead of just the component.
/// </param>
protected void CheckInstance(T _new, bool destroyGO = false)
protected virtual void CheckInstance(T _new, bool destroyGO = false)
{
if (instance != null)
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public abstract class JCS_InstanceNew<T> : JCS_Instance<T>
/// <param name="destroyGO">
/// If true, destory the entire game object instead of just the component.
/// </param>
protected void CheckInstance(T _new, bool destroyGO = false)
protected virtual void CheckInstance(T _new, bool destroyGO = false)
{
if (instance != null)
{
Expand Down
32 changes: 5 additions & 27 deletions Assets/JCSUnity/Scripts/Interfaces/JCS_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace JCSUnity
/// <summary>
/// Interface of all setting class.
/// </summary>
public abstract class JCS_Settings<T> : JCS_Instance<T>
public abstract class JCS_Settings<T> : JCS_InstanceNew<T>
where T : MonoBehaviour
{
/* Variables */
Expand All @@ -23,34 +23,12 @@ public abstract class JCS_Settings<T> : JCS_Instance<T>
/* Functions */

/// <summary>
/// Force the setting object singleton.
/// Check singleton for keep the new one.
/// </summary>
/// <param name="_old"> old instance. </param>
/// <param name="_new"> new instance. </param>
protected T CheckInstance(T _old, T _new)
/// <param name="_new"> new instance </param>
protected virtual void CheckInstance(T _new)
{
if (_old != null)
{
TransferData(_old, _new);

// Delete the old one
Destroy(_old.gameObject);
}

return _new;
base.CheckInstance(_new, true);
}

/// <summary>
/// Instead of Unity Engine's scripting layer's DontDestroyOnLoad.
/// I would like to use own define to transfer the old instance
/// to the newer instance.
///
/// Every time when unity load the scene. The script have been
/// reset, in order not to lose the original setting.
/// transfer the data from old instance to new instance.
/// </summary>
/// <param name="_old"> old instance </param>
/// <param name="_new"> new instance </param>
protected abstract void TransferData(T _old, T _new);
}
}
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Network/JCS_PacketLostPreventer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class JCS_PacketLostPreventer : JCS_Settings<JCS_PacketLostPreventer>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

private void LateUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class JCS_ServerRequestProcessor

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

private void Update()
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class JCS_AppSettings : JCS_Settings<JCS_AppSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

if (SET_FRAME_RATE)
Application.targetFrameRate = FRAME_RATE;
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_GameSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class JCS_GameSettings : JCS_Settings<JCS_GameSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

REAL_DATA_PATH = JCS_AppData.SavePath();
REAL_SCREENSHOT_PATH = JCS_Camera.SavePath();
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_InputSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public JoystickMap GetJoysitckMapByIndex(int index)

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

private void LateUpdate()
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_NetworkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class JCS_NetworkSettings : JCS_Settings<JCS_NetworkSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

this.mServerRequestProcessor = this.GetComponent<JCS_ServerRequestProcessor>();
this.mPacketLostPreventer = this.GetComponent<JCS_PacketLostPreventer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class JCS_PackageDataSettings : JCS_Settings<JCS_PackageDataSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_PauseSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class JCS_PauseSettings : JCS_Settings<JCS_PauseSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_SceneSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class JCS_SceneSettings : JCS_Settings<JCS_SceneSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_ScreenSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Color RESIZABLE_PANELS_COLOR

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

// This will only run once at the time when
// the application is starts.
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_SoundSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void SetSoudnVolume(JCS_SoundSettingType type, float volume)

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_StreamingAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class JCS_StreamingAssets : JCS_Settings<JCS_StreamingAssets>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);

downloadList = preloadPath;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/Settings/JCS_UISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class JCS_UISettings : JCS_Settings<JCS_UISettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class JCS_PlatformSettings : JCS_Settings<JCS_PlatformSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class JCS_PortalSettings : JCS_Settings<JCS_PortalSettings>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class JCS_GameWindowHandler : JCS_Settings<JCS_GameWindowHandler>

private void Awake()
{
instance = CheckInstance(instance, this);
CheckInstance(this);
}

private void Start()
Expand Down
Loading

0 comments on commit 97bac15

Please sign in to comment.