mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 08:38:45 +00:00
临时提交
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using JNGame.Util.Types;
|
||||
using JNGame.Runtime.Util.Types;
|
||||
|
||||
namespace JNGame.Runtime.Entitas
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using JNGame.Util;
|
||||
using Plugins.JNGame.System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using JNGame.Runtime.System;
|
||||
using JNGame.Runtime.Util;
|
||||
|
||||
namespace JNGame
|
||||
namespace JNGame.Runtime
|
||||
{
|
||||
public class JNetGame : SingletonScene<JNetGame>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Math;
|
||||
using Profiler = JNGame.Util.Profiler;
|
||||
using Profiler = JNGame.Runtime.Util.Profiler;
|
||||
|
||||
namespace JNGame.PathFinding
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Math;
|
||||
using JNGame.Util;
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ using DotRecast.Recast.Toolset;
|
||||
using DotRecast.Recast.Toolset.Builder;
|
||||
using JNGame.Map.DotRecast.Util;
|
||||
using JNGame.Math;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Map.DotRecast
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//线程库类 虽然不会影响帧同步 但是显示的使用线程库 这里给它改正常
|
||||
//Interlocked.Increment
|
||||
|
||||
using JNGame.Util.NoThread;
|
||||
using JNGame.Runtime.Util.NoThread;
|
||||
|
||||
namespace DotRecast.Core
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using JNGame.Util.NoThread;
|
||||
using JNGame.Runtime.Util.NoThread;
|
||||
|
||||
namespace DotRecast.Core
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Plugins.JNGame.Network.Action
|
||||
namespace JNGame.Network.Action
|
||||
{
|
||||
public enum NActionEnum : int
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace Plugins.JNGame.Network.Entity
|
||||
namespace JNGame.Network.Entity
|
||||
{
|
||||
public class JNetParam
|
||||
{
|
||||
|
||||
@@ -3,12 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using JNGame.Runtime.System;
|
||||
using JNGame.Util;
|
||||
|
||||
namespace Plugins.JNGame.Network.Group
|
||||
namespace JNGame.Network.Group
|
||||
{
|
||||
public class JNClientGroup<T> : SystemBase where T : JNClientBase
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using JNGame.Network.Entity;
|
||||
using JNGame.Network.Util;
|
||||
using JNGame.Runtime.System;
|
||||
using JNGame.Util;
|
||||
|
||||
namespace Plugins.JNGame.Network
|
||||
namespace JNGame.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础客户端网络类
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using JNGame.Runtime.System;
|
||||
using JNGame.Util;
|
||||
|
||||
namespace Plugins.JNGame.Network
|
||||
namespace JNGame.Network
|
||||
{
|
||||
|
||||
public class JNServerParam
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using JNGame.Network.Util;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Http.WebSockets;
|
||||
using TouchSocket.Sockets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Plugins.JNGame.Network
|
||||
namespace JNGame.Network
|
||||
{
|
||||
public abstract class JNSocket : JNClientBase
|
||||
{
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using JNGame.Network.Action;
|
||||
using JNGame.Network.Entity;
|
||||
using JNGame.Network.Util;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using JNGame.Network.Action;
|
||||
using JNGame.Network.Entity;
|
||||
using JNGame.Network.Util;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Util;
|
||||
using JNGame.Network.Entity;
|
||||
using JNGame.Runtime.Util;
|
||||
|
||||
namespace Plugins.JNGame.Network.Util
|
||||
namespace JNGame.Network.Util
|
||||
{
|
||||
// 网络数据工具类 [请求Id*4,处理Id*4,...参数数据*N]
|
||||
public static class NDataUtil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System.View;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Frame;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using JNGame.Math;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using JNGame.Runtime.Entitas;
|
||||
using JNGame.Sync.Frame.Entity.Component.Components;
|
||||
using JNGame.Util.Types;
|
||||
using System;
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Util.Types;
|
||||
|
||||
namespace JNGame.Sync.Frame.Entity.Components
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Component.Components;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
|
||||
namespace JNGame.Sync.Entity
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Entitas;
|
||||
|
||||
namespace JNGame.Sync
|
||||
namespace JNGame.Runtime.Sync
|
||||
{
|
||||
public abstract class JNBaseSystem : ISystem
|
||||
{
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.View;
|
||||
using JNGame.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Sync.Frame
|
||||
namespace JNGame.Runtime.Sync
|
||||
{
|
||||
public abstract class JNSyncDefaultService : JNSyncService
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JNGame.Sync
|
||||
namespace JNGame.Runtime.Sync
|
||||
{
|
||||
public abstract class JNSyncService : Feature
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using UnityEngine;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
@@ -5,7 +5,6 @@ using DotRecast.Core.Collections;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.System.Data
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Util.Types;
|
||||
using JNGame.Runtime.Util.Types;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace JNGame.Sync.System.View
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace JNGame.Sync.Frame.Service
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Sync;
|
||||
using JNGame.Sync.Entity;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.System
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.System
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.System
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Entitas;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace JNGame.Sync.System
|
||||
{
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Entitas;
|
||||
|
||||
namespace Plugins.JNGame.Runtime.System
|
||||
namespace JNGame.Runtime.System
|
||||
{
|
||||
public class JNSystemLoad : ISystem
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Plugins.JNGame.System
|
||||
namespace JNGame.Runtime.System
|
||||
{
|
||||
public abstract class SystemBase
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Util;
|
||||
using JNGame.Runtime.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Plugins.JNGame.Util
|
||||
namespace JNGame.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// 静态事件分发器
|
||||
|
||||
@@ -2,10 +2,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Plugins.JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
|
||||
public class JAPIConfig{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace JNGame.Util {
|
||||
namespace JNGame.Runtime.Util {
|
||||
public static class JsonUtil {
|
||||
public static string ToJson(object obj){
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public class NetTool
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace JNGame.Util.NoThread
|
||||
namespace JNGame.Runtime.Util.NoThread
|
||||
{
|
||||
public class Interlocked
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public class Profiler
|
||||
{
|
||||
[System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
||||
|
||||
// [System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
||||
public static void BeginSample(string tag)
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
@@ -14,7 +14,7 @@ namespace JNGame.Util
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
||||
// [System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
||||
public static void EndSample()
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Plugins.JNGame.Util
|
||||
{
|
||||
|
||||
//Proto工具
|
||||
public class ProtoUtil
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37c91935ad854ee1a4b199391df35004
|
||||
timeCreated: 1706006228
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using JNGame.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Plugins.JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public static class RandomUtil
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Plugins.JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public abstract class SingletonUtil<T> where T : Singleton<T>,new() {
|
||||
|
||||
|
||||
@@ -1,93 +1,97 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Be aware this will not prevent a non singleton constructor
|
||||
/// such as `T myT = new T();`
|
||||
/// To prevent that, add `protected T () {}` to your singleton class.
|
||||
///
|
||||
/// As a note, this is made as MonoBehaviour because we need Coroutines.
|
||||
/// </summary>
|
||||
public class SingletonScene<T> : MonoBehaviour where T : MonoBehaviour
|
||||
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
private static object _lock = new object();
|
||||
|
||||
public static T Instance
|
||||
/// <summary>
|
||||
/// Be aware this will not prevent a non singleton constructor
|
||||
/// such as `T myT = new T();`
|
||||
/// To prevent that, add `protected T () {}` to your singleton class.
|
||||
///
|
||||
/// As a note, this is made as MonoBehaviour because we need Coroutines.
|
||||
/// </summary>
|
||||
public class SingletonScene<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
get
|
||||
private static T _instance;
|
||||
|
||||
private static object _lock = new object();
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
if (applicationIsQuitting)
|
||||
get
|
||||
{
|
||||
Debug.LogWarning("[Singleton] Instance '" + typeof(T) +
|
||||
"' already destroyed on application quit." +
|
||||
" Won't create again - returning null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (_instance == null)
|
||||
if (applicationIsQuitting)
|
||||
{
|
||||
try
|
||||
{
|
||||
_instance = (T)FindObjectOfType(typeof(T));
|
||||
|
||||
if (FindObjectsOfType(typeof(T)).Length > 1)
|
||||
{
|
||||
Debug.LogError("[Singleton] Something went really wrong " +
|
||||
" - there should never be more than 1 singleton!" +
|
||||
" Reopening the scene might fix it.");
|
||||
return _instance;
|
||||
}
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject singleton = new GameObject();
|
||||
_instance = singleton.AddComponent<T>();
|
||||
singleton.name = "(singleton) " + typeof(T).ToString();
|
||||
|
||||
DontDestroyOnLoad(singleton);
|
||||
|
||||
Debug.Log("[Singleton] An instance of " + typeof(T) +
|
||||
" is needed in the scene, so '" + singleton +
|
||||
"' was created with DontDestroyOnLoad.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[Singleton] Using instance already created: " +
|
||||
_instance.gameObject.name);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.Message);
|
||||
}
|
||||
Debug.LogWarning("[Singleton] Instance '" + typeof(T) +
|
||||
"' already destroyed on application quit." +
|
||||
" Won't create again - returning null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return _instance;
|
||||
lock (_lock)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_instance = (T)FindObjectOfType(typeof(T));
|
||||
|
||||
if (FindObjectsOfType(typeof(T)).Length > 1)
|
||||
{
|
||||
Debug.LogError("[Singleton] Something went really wrong " +
|
||||
" - there should never be more than 1 singleton!" +
|
||||
" Reopening the scene might fix it.");
|
||||
return _instance;
|
||||
}
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject singleton = new GameObject();
|
||||
_instance = singleton.AddComponent<T>();
|
||||
singleton.name = "(singleton) " + typeof(T).ToString();
|
||||
|
||||
DontDestroyOnLoad(singleton);
|
||||
|
||||
Debug.Log("[Singleton] An instance of " + typeof(T) +
|
||||
" is needed in the scene, so '" + singleton +
|
||||
"' was created with DontDestroyOnLoad.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[Singleton] Using instance already created: " +
|
||||
_instance.gameObject.name);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool applicationIsQuitting = false;
|
||||
private static bool applicationIsQuitting = false;
|
||||
|
||||
/// <summary>
|
||||
/// When Unity quits, it destroys objects in a random order.
|
||||
/// In principle, a Singleton is only destroyed when application quits.
|
||||
/// If any script calls Instance after it have been destroyed,
|
||||
/// it will create a buggy ghost object that will stay on the Editor scene
|
||||
/// even after stopping playing the Application. Really bad!
|
||||
/// So, this was made to be sure we're not creating that buggy ghost object.
|
||||
/// </summary>
|
||||
public void OnDestroy()
|
||||
{
|
||||
applicationIsQuitting = true;
|
||||
OnDispose();
|
||||
}
|
||||
|
||||
protected virtual void OnDispose()
|
||||
{
|
||||
/// <summary>
|
||||
/// When Unity quits, it destroys objects in a random order.
|
||||
/// In principle, a Singleton is only destroyed when application quits.
|
||||
/// If any script calls Instance after it have been destroyed,
|
||||
/// it will create a buggy ghost object that will stay on the Editor scene
|
||||
/// even after stopping playing the Application. Really bad!
|
||||
/// So, this was made to be sure we're not creating that buggy ghost object.
|
||||
/// </summary>
|
||||
public void OnDestroy()
|
||||
{
|
||||
applicationIsQuitting = true;
|
||||
OnDispose();
|
||||
}
|
||||
|
||||
protected virtual void OnDispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// 单例接口。
|
||||
/// </summary>
|
||||
public interface ISingleton
|
||||
{
|
||||
void Active();
|
||||
|
||||
void Release();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单例管理器(统一化持久和释放)。
|
||||
/// </summary>
|
||||
public static class SingletonManager
|
||||
{
|
||||
private static List<ISingleton> _singletonList;
|
||||
private static Dictionary<string, GameObject> _gameObjects;
|
||||
private static GameObject _root;
|
||||
|
||||
public static GameObject Root
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_root == null)
|
||||
{
|
||||
_root = GameObject.Find("[SingletonManager]");
|
||||
|
||||
if (_root == null)
|
||||
{
|
||||
_root = new GameObject("[SingletonManager]")
|
||||
{
|
||||
transform =
|
||||
{
|
||||
position = Vector3.zero
|
||||
}
|
||||
};
|
||||
}
|
||||
UnityEngine.Object.DontDestroyOnLoad(_root);
|
||||
}
|
||||
return _root;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Retain(ISingleton go)
|
||||
{
|
||||
if (_singletonList == null)
|
||||
{
|
||||
_singletonList = new List<ISingleton>();
|
||||
}
|
||||
|
||||
_singletonList.Add(go);
|
||||
}
|
||||
|
||||
public static void Retain(GameObject go)
|
||||
{
|
||||
if (_gameObjects == null)
|
||||
{
|
||||
_gameObjects = new Dictionary<string, GameObject>();
|
||||
}
|
||||
|
||||
if (!_gameObjects.ContainsKey(go.name))
|
||||
{
|
||||
_gameObjects.Add(go.name, go);
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
UnityEngine.Object.DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Release(GameObject go)
|
||||
{
|
||||
if (_gameObjects != null && _gameObjects.ContainsKey(go.name))
|
||||
{
|
||||
_gameObjects.Remove(go.name);
|
||||
UnityEngine.Object.Destroy(go);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Release(ISingleton go)
|
||||
{
|
||||
if (_singletonList != null && _singletonList.Contains(go))
|
||||
{
|
||||
_singletonList.Remove(go);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Release()
|
||||
{
|
||||
if (_gameObjects != null)
|
||||
{
|
||||
foreach (var item in _gameObjects)
|
||||
{
|
||||
Object.Destroy(item.Value);
|
||||
}
|
||||
|
||||
_gameObjects.Clear();
|
||||
}
|
||||
|
||||
if (_singletonList != null)
|
||||
{
|
||||
for (int i = 0; i < _singletonList.Count; ++i)
|
||||
{
|
||||
_singletonList[i].Release();
|
||||
}
|
||||
|
||||
_singletonList.Clear();
|
||||
}
|
||||
|
||||
Resources.UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
public static GameObject GetGameObject(string name)
|
||||
{
|
||||
GameObject go = null;
|
||||
if (_gameObjects != null)
|
||||
{
|
||||
_gameObjects.TryGetValue(name, out go);
|
||||
}
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
internal static bool ContainsKey(string name)
|
||||
{
|
||||
if (_gameObjects != null)
|
||||
{
|
||||
return _gameObjects.ContainsKey(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static ISingleton GetSingleton(string name)
|
||||
{
|
||||
for (int i = 0; i < _singletonList.Count; ++i)
|
||||
{
|
||||
if (_singletonList[i].ToString() == name)
|
||||
{
|
||||
return _singletonList[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放所有单例。
|
||||
/// </summary>
|
||||
public static void ReStart()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局单例对象(非线程安全)。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型T。</typeparam>
|
||||
public abstract class TSingleton<T> : ISingleton where T : TSingleton<T>, new()
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _instance)
|
||||
{
|
||||
_instance = new T();
|
||||
_instance.Init();
|
||||
SingletonManager.Retain(_instance);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsValid => _instance != null;
|
||||
|
||||
protected TSingleton()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Active()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Release()
|
||||
{
|
||||
if (_instance != null)
|
||||
{
|
||||
SingletonManager.Release(_instance);
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f5742a6d574437b86898a1d984862fb
|
||||
timeCreated: 1722414939
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
|
||||
public delegate void TimerCallback();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace Plugins.JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public class ToUtil
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace JNGame.Util.Types
|
||||
namespace JNGame.Runtime.Util.Types
|
||||
{
|
||||
public class KeyValue<TKey, TValue>
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
/// Author: Pim de Witte (pimdewitte.com) and contributors, https://github.com/PimDeWitte/UnityMainThreadDispatcher
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace Game.Plugins.JNGame.Util
|
||||
namespace JNGame.Runtime.Util
|
||||
{
|
||||
public class UseUtil
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user