临时提交

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-17 01:59:25 +08:00
parent 6da2f9e691
commit c85f350e0a
191 changed files with 17326 additions and 17008 deletions

View File

@@ -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>
/// 静态事件分发器

View File

@@ -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{

View File

@@ -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);

View File

@@ -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
{

View File

@@ -1,4 +1,4 @@
namespace JNGame.Util.NoThread
namespace JNGame.Runtime.Util.NoThread
{
public class Interlocked
{

View File

@@ -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

View File

@@ -1,11 +0,0 @@
namespace Plugins.JNGame.Util
{
//Proto工具
public class ProtoUtil
{
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 37c91935ad854ee1a4b199391df35004
timeCreated: 1706006228

View File

@@ -1,8 +1,7 @@
using System;
using JNGame.Math;
using UnityEngine;
namespace Plugins.JNGame.Util
namespace JNGame.Runtime.Util
{
public static class RandomUtil
{

View File

@@ -1,4 +1,4 @@
namespace Plugins.JNGame.Util
namespace JNGame.Runtime.Util
{
public abstract class SingletonUtil<T> where T : Singleton<T>,new() {

View File

@@ -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()
{
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 0f5742a6d574437b86898a1d984862fb
timeCreated: 1722414939

View File

@@ -2,7 +2,7 @@
using System.Linq;
using UnityEngine;
namespace JNGame.Util
namespace JNGame.Runtime.Util
{
public delegate void TimerCallback();

View File

@@ -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
{

View File

@@ -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>
{

View File

@@ -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>

View File

@@ -1,6 +1,6 @@
using System;
namespace Game.Plugins.JNGame.Util
namespace JNGame.Runtime.Util
{
public class UseUtil
{