提交工程

This commit is contained in:
2026-05-20 12:01:19 +08:00
commit e0ddde0393
5502 changed files with 596320 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 46cb2ee281f541848a34a54377ffab9f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System;
namespace ChillConnect
{
public abstract class BaseInterfaceManager<T> : IDisposable, InterfaceManager where T : BaseInterfaceManager<T>, new()
{
public bool IsInit { get; private set; }
public bool IsStartUp { get; private set; }
public bool IsDispose { get; private set; }
private static T m_instance;
public static T Instance
{
get
{
if (m_instance == null)
{
m_instance = new T();
m_instance.New();
}
return m_instance;
}
}
protected virtual void New()
{
IsDispose = false;
}
public virtual void Init()
{
IsInit = true;
}
public virtual void StartUp()
{
IsStartUp = true;
}
public virtual void DisposeBefore()
{
IsDispose = true;
IsInit = false;
IsStartUp = false;
}
public virtual void Dispose()
{
m_instance = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0395f071bf7ad864083ee86433bcec9b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
namespace ChillConnect
{
public abstract class BaseUnityManager<T> : SingletonUnity<T>, InterfaceManager
where T : BaseUnityManager<T>
{
public bool IsInit { get; private set; }
public bool IsStartUp { get; private set; }
public bool IsDispose { get; private set; }
protected override string ParentRootName
{
get { return AppObjConst.MonoManagerGoName; }
}
protected override void New()
{
base.New();
IsDispose = false;
}
public virtual void Init()
{
IsInit = true;
}
public virtual void StartUp()
{
IsStartUp = true;
}
public virtual void DisposeBefore()
{
IsDispose = true;
IsInit = false;
IsStartUp = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c01f68bc92a2b648a38f328f7e95ce6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
namespace ChillConnect
{
public interface InterfaceManager
{
void Init();
void StartUp();
void DisposeBefore();
void Dispose();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e53d06f42f51d84498ab4ffe80556de6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 75c9b664059ad8548943c2dcce3e3b4e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,148 @@
using FairyGUI;
using UnityEngine;
using UnityEngine.EventSystems;
namespace ChillConnect
{
public sealed class CameraManager : BaseInterfaceManager<CameraManager>
{
public Transform mainCameraRoot;
public GameObject mainCameraGo;
public Camera mainCamera;
public Transform fguiCameraRoot;
public GameObject fguiCameraGo;
public Camera fguiCamera;
public bool isEnabledWorldRaycast;
public Physics2DRaycaster physics2DRaycaster;
public PhysicsRaycaster physics3DRaycaster;
private bool isMainCameraShakeing;
#region Coordinate
public Vector2 WorldPosToFGUIPos(Vector3 worldPos)
{
Vector3 screenPos = mainCamera.WorldToScreenPoint(worldPos);
screenPos.y = ScreenConst.CurrResolution.y - screenPos.y;
Vector2 pt = GRoot.inst.GlobalToLocal(screenPos);
return pt;
}
#endregion
#region Func
public void SetWorldRaycasterEnabled(bool enabled)
{
isEnabledWorldRaycast = enabled;
if (physics2DRaycaster != null)
{
EventKit.Set2DRaycasterEnabled(physics2DRaycaster, isEnabledWorldRaycast);
}
if (physics3DRaycaster != null)
{
EventKit.Set3DRaycasterEnabled(physics3DRaycaster, isEnabledWorldRaycast);
}
AppDispatcher.Instance.Dispatch(AppMsg.WorldRaycast_EnableChange, isEnabledWorldRaycast);
}
#endregion
#region Camera
public void CreateMainCamera()
{
if (mainCamera) return;
string name = "MainCamera";
mainCameraGo = new GameObject(name);
mainCameraGo.tag = name;
mainCameraGo.layer = LayerMaskConst.Default;
mainCameraGo.transform.localPosition = Vector3.zero;
int cullingMask = LayerMask.GetMask(LayerMaskConst.Default_Name);
mainCamera = CreateCamera(mainCameraGo, cullingMask: cullingMask);
mainCamera.clearFlags = CameraClearFlags.SolidColor;
mainCamera.forceIntoRenderTexture = false;
GameObject root = new GameObject(name + "Root");
root.transform.position = CameraConst.MainCameraPos;
root.SetParent(AppObjConst.CameraGo);
mainCameraGo.SetParent(root);
mainCameraRoot = root.transform;
CameraAdaptive adaptiveCom = mainCamera.gameObject.AddComponent<CameraAdaptive>();
adaptiveCom.DoAdaptive(isOrthographic: true, orthographicSize: ScreenConst.OrthographicSize_1280H);
}
public void CreateFGUICamera()
{
if (fguiCamera) return;
StageCamera.CheckMainCamera();
fguiCamera = StageCamera.main;
fguiCamera.depth = CameraConst.UICameraDepth;
fguiCamera.forceIntoRenderTexture = false;
fguiCameraGo = fguiCamera.gameObject;
GameObject root = new GameObject("FGUICameraRoot");
root.transform.position = CameraConst.UICameraPos;
root.SetParent(AppObjConst.CameraGo);
fguiCameraGo.SetParent(root);
fguiCameraRoot = root.transform;
}
public Camera CreateCamera(GameObject cameraGo, int cullingMask)
{
Camera cameraCom = cameraGo.AddComponent<Camera>();
cameraCom.clearFlags = CameraClearFlags.Depth;
cameraCom.backgroundColor = Color.black;
cameraCom.cullingMask = cullingMask;
cameraCom.nearClipPlane = -30f;
cameraCom.farClipPlane = 30f;
cameraCom.rect = new Rect(0, 0, 1f, 1f);
cameraCom.depth = CameraConst.MainDepth;
cameraCom.renderingPath = RenderingPath.UsePlayerSettings;
cameraCom.useOcclusionCulling = false;
cameraCom.allowHDR = false;
cameraCom.allowMSAA = false;
cameraCom.orthographicSize = 9.6f;
cameraCom.forceIntoRenderTexture = false;
return cameraCom;
}
#endregion
#region Mgr
public override void Init()
{
base.Init();
InitCameraMgr();
CreateMainCamera();
CreateFGUICamera();
}
private void InitCameraMgr()
{
AppObjConst.CameraGo = new GameObject(AppObjConst.CameraGoName);
AppObjConst.CameraGo.SetParent(AppObjConst.FrameGo);
}
public override void Dispose()
{
base.Dispose();
GeneralKit.Destroy(AppObjConst.CameraGo);
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45cef881d003bb84394180b075125699
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,420 @@
using System;
using UnityEngine;
namespace ChillConnect
{
public enum MonthType
{
None = 0,
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12,
}
public sealed class DateTimeManager : BaseInterfaceManager<DateTimeManager>
{
public static DateTime StartTimestampDT = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
private long HeartBeatInterval = 7;
private int FixTimeOffset;
public int ServerRTTOneWayTimeOffset { get; private set; }
public long ServerTickTimestamp { get; private set; }
#region CurrTime
public long GetCurrTimestamp()
{
long timestamp = (long)(DateTime.Now - StartTimestampDT).TotalSeconds;
return timestamp;
}
public string GetCurrTimestampInfo()
{
long timestamp = (long)(DateTime.Now - StartTimestampDT).TotalSeconds;
return timestamp.ToString();
}
#endregion
#region ServerCurrTime
public void SetHeartBeatTime(int heartBeatInterval)
{
HeartBeatInterval = heartBeatInterval;
}
public long GetHeartBeatTime()
{
return HeartBeatInterval;
}
public void SetServerCurrTimestamp(long serverCurrTimestamp)
{
ServerTickTimestamp = serverCurrTimestamp;
ServerRTTOneWayTimeOffset = (int)(GetCurrTimestamp() - serverCurrTimestamp);
}
public float GetServerTimeOffset()
{
return ServerRTTOneWayTimeOffset;
}
public long GetServerTickTimestamp()
{
return ServerTickTimestamp;
}
public DateTime GetServerTickDateTime()
{
return GetDateTime(ServerTickTimestamp);
}
public long GetServerCurrTimestamp(bool isFix = false)
{
var servertimes = GetCurrTimestamp() - ServerRTTOneWayTimeOffset;
if (isFix)
{
servertimes += FixTimeOffset;
}
return servertimes;
}
public void SetTimeOffset(int offset)
{
FixTimeOffset += offset;
}
public DateTime GetServerCurrDateTime()
{
long timestamp = GetServerCurrTimestamp();
return GetDateTime(timestamp);
}
#endregion
#region Interval
public long GetCurrTimeInterval(long timestamp)
{
return timestamp - GetCurrTimestamp();
}
public long GetServerCurrTimeInterval(long timestamp)
{
return timestamp - GetServerCurrTimestamp();
}
public int GetInteralDay(ulong time)
{
ulong interal = time - (ulong)GetServerCurrTimestamp();
int day = Mathf.CeilToInt(interal * 1f / (60 * 60 * 24));
return day;
}
public void GetIntervalHMS(long interval, out int hour, out int minute, out int second)
{
second = (int)(interval % 60);
int tempMinute = (int)(interval / 60);
hour = tempMinute / 60;
minute = tempMinute - (hour * 60);
}
public void GetIntervalMS(long interval, out int minute, out int second)
{
second = (int)(interval % 60);
minute = (int)(interval / 60);
}
public string GetIntervalHMSTextEn(long interval)
{
int hour, minute, second;
GetIntervalHMS(interval, out hour, out minute, out second);
return string.Format("{0:00}:{1:00}:{2:00}", hour, minute, second);
}
public string GetIntervalHMSTextCn(long interval)
{
int hour, minute, second;
GetIntervalHMS(interval, out hour, out minute, out second);
return string.Format("{0:00}{1:00}{2:00}", hour, minute, second);
}
public string GetIntervalMSTextEn(long interval)
{
int minute, second;
GetIntervalMS(interval, out minute, out second);
return string.Format("{0:00}:{1:00}", minute, second);
}
public string GetIntervalMSTextCn(long interval)
{
int minute, second;
GetIntervalMS(interval, out minute, out second);
return string.Format("{0:00}{1:00}", minute, second);
}
public string GetIntervalDateSimpleString(long interval)
{
DateTime dateTime = GetDateTime(interval);
return DateTimeToSimpleString(dateTime);
}
#endregion
#region DateTime
public DateTime GetCurrDateTime()
{
return DateTime.Now;
}
public double GetTimestamp(DateTime date)
{
return (date - StartTimestampDT).TotalSeconds;
}
public DateTime GetDateTime(long timestamp)
{
DateTime dt = StartTimestampDT.AddSeconds(timestamp);
return dt;
}
public int GetCurrTimeZone()
{
return int.Parse(GetCurrDateTime().ToString("%z"));
}
public int GetNowYear()
{
DateTime time = GetCurrDateTime();
return time.Year;
}
public int GetNowMonth()
{
DateTime time = GetCurrDateTime();
return time.Month;
}
public int GetNowDay()
{
DateTime time = GetCurrDateTime();
return time.Day;
}
public int GetNowHour()
{
DateTime time = GetCurrDateTime();
return time.Hour;
}
public int GetNowMinute()
{
DateTime time = GetCurrDateTime();
return time.Minute;
}
public int GetNowSecond()
{
DateTime time = GetCurrDateTime();
return time.Second;
}
public int GetNowMillisecond()
{
DateTime time = GetCurrDateTime();
return time.Millisecond;
}
#endregion
#region DateTimeFormat
public string DateTimeToMMdd(DateTime date)
{
return date.ToString("MM/dd");
}
public string DateTimeToYYYYMMDD(DateTime time)
{
return time.ToString("yyyyMMdd");
}
public string DateTimeToSimpleString(DateTime time)
{
return time.ToString("yyyy/MM/dd");
}
public string DateTimeToString(DateTime time)
{
return time.ToString("yyyy/MM/dd HH:mm:ss");
}
public string DateTimeToDetailString(DateTime time)
{
return time.ToString("yyyy/MM/dd HH:mm:ss:ffff dddd");
}
public DateTime GetDateTimeBy_yyyyMMddStr(string str)
{
return new DateTime(GetYearByDateStr(str), GetMonthByDateStr(str), GetDayByDateStr(str));
}
public string TimestampToString(long endTimestamp)
{
return DateTimeToString(GetDateTime(endTimestamp));
}
#endregion
#region Conversion
public float Millisecond2Second(uint millisecond)
{
if (millisecond == 0)
{
return 0f;
}
return millisecond / 1000f;
}
public double GetTimestampInMilliSecond(DateTime date)
{
return GetTimestamp(date) * 1000;
}
public string GetMSMTimeUID()
{
int minute = GetNowMinute();
int second = GetNowSecond();
int millisecond = GetNowMillisecond();
return string.Concat(minute, second, millisecond);
}
#endregion
#region Calculate
public int GetMonthDuration(string oldDate, string newDate)
{
int year = GetYearByDateStr(newDate) - GetYearByDateStr(oldDate);
int month = GetMonthByDateStr(newDate) - GetMonthByDateStr(oldDate);
return year * 12 + month;
}
public int GetMonthDuration(DateTime oldDate, DateTime newDate)
{
int year = newDate.Year - oldDate.Year;
int month = newDate.Month - oldDate.Month;
return year * 12 + month;
}
public int GetDayByDateStr(string dateStr)
{
int date = int.Parse(dateStr.Substring(6, 2));
return date;
}
public int GetMonthByDateStr(string dateStr)
{
int date = int.Parse(dateStr.Substring(4, 2));
return date;
}
public int GetYearByDateStr(string dateStr)
{
int date = int.Parse(dateStr.Substring(0, 4));
return date;
}
public DateTime FirstDayOfMonth(DateTime datetime)
{
return datetime.AddDays(1 - datetime.Day);
}
public DateTime LastDayOfMonth(DateTime datetime)
{
return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
}
public long GetCurrTimesTampByMillisecond()
{
long time = (long)(DateTime.Now - StartTimestampDT).TotalMilliseconds;
return time;
}
public string DateTimeToFFFString(DateTime time)
{
return time.ToString("HH:mm:ss ff");
}
public long GetServerCurrTimestampByMillisecond()
{
return GetCurrTimesTampByMillisecond() - ServerRTTOneWayTimeOffset * 1000;
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2ef349abda84fd42801a3062464921f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
namespace ChillConnect
{
public sealed class GameIManager : BaseInterfaceManager<GameIManager>
{
private float pauseCacheTimeScale = 1;
#region Scene
public void InitialMain()
{
SceneManager.Instance.InitialMain();
}
public void EnterMain()
{
SceneManager.Instance.SwitchScene(SceneManager.DefaultMainSceneIdx);
}
#endregion Scene
#region Msg
private void AddListener()
{
}
private void RemoveListener()
{
}
#endregion Msg
#region Private
public override void Init()
{
base.Init();
AddListener();
}
public override void Dispose()
{
base.Dispose();
RemoveListener();
}
#endregion Private
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 65948735d1d6a7249a4ee2778a8867b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,200 @@
using System;
using System.Collections.Generic;
namespace ChillConnect
{
public sealed class ModuleManager : BaseInterfaceManager<ModuleManager>
{
private Dictionary<string, BaseModel> modelDict = new();
private Dictionary<string, Type> uiTypeDict = new();
private Dictionary<string, BaseCtrl> ctrlDict = new();
private Dictionary<string, BaseUICtrl> uiCtrlDict = new();
public override void Init()
{
base.Init();
InitAllModule();
}
private void InitAllModule()
{
List<string> ctrlDisableList = AppConst.CtrlDisableList;
foreach (BaseModel model in modelDict.Values)
{
model.New();
}
foreach (BaseCtrl ctrl in ctrlDict.Values)
{
if (!ctrl.isEnable)
{
continue;
}
if (ctrlDisableList.Contains(ctrl.ctrlName))
{
ctrl.isEnable = false;
continue;
}
ctrl.isEnable = true;
ctrl.New();
}
foreach (BaseUICtrl uiCtrl in uiCtrlDict.Values)
{
if (!uiCtrl.isEnable)
{
continue;
}
if (ctrlDisableList.Contains(uiCtrl.ctrlName))
{
uiCtrl.isEnable = false;
continue;
}
uiCtrl.isEnable = true;
uiCtrl.New();
}
foreach (BaseModel model in modelDict.Values)
{
model.Init();
}
foreach (BaseCtrl ctrl in ctrlDict.Values)
{
ctrl.Init();
}
foreach (BaseUICtrl uiCtrl in uiCtrlDict.Values)
{
uiCtrl.Init();
}
}
public void StartUpAllModule()
{
foreach (BaseModel model in modelDict.Values)
{
model.StartUp();
}
foreach (BaseCtrl ctrl in ctrlDict.Values)
{
ctrl.StartUp();
}
foreach (BaseUICtrl uiCtrl in uiCtrlDict.Values)
{
uiCtrl.StartUp();
}
}
public void AllModuleGameStart()
{
foreach (BaseModel model in modelDict.Values)
{
model.GameStart();
}
foreach (BaseCtrl ctrl in ctrlDict.Values)
{
ctrl.GameStart();
}
foreach (BaseUICtrl uiCtrl in uiCtrlDict.Values)
{
uiCtrl.GameStart();
}
}
public BaseModel GetModel(string modelName)
{
BaseModel model = null;
if (!modelDict.TryGetValue(modelName, out model))
{
}
return model;
}
public BaseUICtrl GetUICtrl(string uiCtrlName)
{
BaseUICtrl uiCtrl = null;
if (!uiCtrlDict.TryGetValue(uiCtrlName, out uiCtrl))
{
}
return uiCtrl;
}
public void AddModel(string modelName, BaseModel model)
{
model.modelName = modelName;
modelDict[modelName] = model;
}
public void AddUIType(string uiName, Type uiType)
{
uiTypeDict[uiName] = uiType;
}
public void AddCtrl(string ctrlName, BaseCtrl ctrl)
{
ctrl.ctrlName = ctrlName;
ctrlDict[ctrlName] = ctrl;
}
public void AddUICtrl(string ctrlName, BaseUICtrl uiCtrl)
{
uiCtrl.ctrlName = ctrlName;
uiCtrlDict[ctrlName] = uiCtrl;
}
public void DisposeAllModel()
{
foreach (BaseModel model in modelDict.Values)
{
model.Dispose();
}
modelDict.Clear();
}
public void DisposeAllCtrl()
{
foreach (BaseCtrl ctrl in ctrlDict.Values)
{
ctrl.Dispose();
}
foreach (BaseUICtrl uiCtrl in uiCtrlDict.Values)
{
uiCtrl.Dispose();
}
ctrlDict.Clear();
uiCtrlDict.Clear();
}
public void DisposeAllModule()
{
DisposeAllModel();
DisposeAllCtrl();
}
public override void Dispose()
{
base.Dispose();
modelDict = null;
uiTypeDict = null;
ctrlDict = null;
uiCtrlDict = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eeedf720d335ccb4fa1e3d3497001ec3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
using System.Collections.Generic;
namespace ChillConnect
{
public sealed class SceneManager : BaseInterfaceManager<SceneManager>
{
public const int DefaultMainSceneIdx = 0;
private Dictionary<int, BaseScene> sceneDict = new();
private BaseScene m_currScene;
public void AddScene(BaseScene scene)
{
if (!sceneDict.ContainsKey(scene.SceneIdx))
{
sceneDict[scene.SceneIdx] = scene;
}
}
public void InitialMain(object param = null)
{
if (sceneDict.Count == 0) return;
BaseScene scene = GetScene(DefaultMainSceneIdx);
if (SetScene(scene))
{
SceneSwitchManager.Instance.SwitchInitialScene(DefaultMainSceneIdx, scene.SwitchSceneComplete, param);
}
}
public void SwitchScene(int sceneIdx, object param = null)
{
BaseScene scene = GetScene(sceneIdx);
if (SetScene(scene))
{
UIManager.Instance.SwitchSceneCloseAllUI();
SceneSwitchManager.Instance.SwitchScene(sceneIdx, scene.SwitchSceneComplete, param);
}
}
private bool SetScene(BaseScene scene)
{
if (scene == null)
{
return false;
}
if (scene == m_currScene)
{
return false;
}
if (m_currScene != null)
{
m_currScene.Leave();
}
m_currScene = scene;
m_currScene.Enter();
return true;
}
private BaseScene GetScene(int sceneIdx)
{
BaseScene scene = null;
if (!sceneDict.TryGetValue(sceneIdx, out scene))
{
}
return scene;
}
public override void Dispose()
{
base.Dispose();
foreach (BaseScene scene in sceneDict.Values)
{
scene.Dispose();
}
sceneDict.Clear();
sceneDict = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5e07bf3e2b867c4b9d7776206acc020
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System.Collections.Generic;
namespace ChillConnect
{
public sealed class ManagerOfManager : Singleton<ManagerOfManager>
{
private List<InterfaceManager> allManager = new();
public void Init()
{
foreach (var manager in allManager)
{
manager.Init();
}
foreach (var manager in allManager)
{
manager.StartUp();
}
}
public void AddManager(InterfaceManager interfaceManager)
{
if (!allManager.Contains(interfaceManager))
{
allManager.Add(interfaceManager);
}
}
public void DisposeAllManager()
{
foreach (var manager in allManager)
{
manager.DisposeBefore();
}
foreach (var manager in allManager)
{
manager.Dispose();
}
GeneralKit.Destroy(AppObjConst.MonoManagerGo);
allManager.Clear();
}
public override void Dispose()
{
base.Dispose();
allManager.Clear();
allManager = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6a04b8a543c2964ab598fc4296d0c70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a1d55654313a544b99ae81d86cf0e39
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,333 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FairyGUI;
using UnityEngine;
using UnityEngine.Events;
namespace ChillConnect
{
public sealed class AudioManager : BaseUnityManager<AudioManager>
{
public const bool IsUnscaleTime = true;
private Dictionary<string, AudioClip> audioClipCacheDict = new Dictionary<string, AudioClip>();
private GameObject newEffectSourcesRoot;
private GameObject dynamicEffectSourcesRoot;
[HideInInspector] public AudioListener audioListener;
[HideInInspector] public AudioSource bgmSource;
[HideInInspector] public AudioSource effectSource;
[HideInInspector] public List<AudioSource> dynamicEffectSources = new List<AudioSource>();
[HideInInspector] public List<AudioSource> unscaleTimeSounds = new List<AudioSource>();
[HideInInspector] public float currUISoundVolume = 1;
private bool isOpenBGM;
public bool IsOpenBGM
{
get { return isOpenBGM; }
set
{
isOpenBGM = value;
PlayerPrefsKit.WriteBool(PrefsKeyConst.AudioMgr_isOpenBGM, isOpenBGM);
if (!bgmSource) return;
bgmSource.enabled = isOpenBGM;
if (isOpenBGM)
{
bgmSource.Play();
}
else
{
bgmSource.Pause();
}
}
}
private bool isOpenEffect;
public bool IsOpenEffect
{
get { return isOpenEffect; }
set
{
isOpenEffect = value;
PlayerPrefsKit.WriteBool(PrefsKeyConst.AudioMgr_isOpenEffect, isOpenEffect);
GRoot.inst.soundVolume = isOpenEffect ? currUISoundVolume : 0f;
if (isOpenEffect)
{
GRoot.inst.EnableSound();
}
else
{
GRoot.inst.DisableSound();
}
}
}
private void InitAudioMode()
{
isOpenBGM = PlayerPrefsKit.ReadBool(PrefsKeyConst.AudioMgr_isOpenBGM, true);
isOpenEffect = PlayerPrefsKit.ReadBool(PrefsKeyConst.AudioMgr_isOpenEffect, true);
GRoot.inst.soundVolume = 1;
currUISoundVolume = GRoot.inst.soundVolume;
GRoot.inst.soundVolume = isOpenEffect ? currUISoundVolume : 0f;
}
public override void Init()
{
base.Init();
AppDispatcher.Instance.AddListener(AppMsg.TimeScale_Change, OnTimeScaleChange);
audioListener = gameObject.AddComponent<AudioListener>();
bgmSource = gameObject.AddComponent<AudioSource>();
bgmSource.playOnAwake = false;
bgmSource.loop = true;
effectSource = gameObject.AddComponent<AudioSource>();
effectSource.playOnAwake = false;
effectSource.loop = false;
newEffectSourcesRoot = new GameObject("NewEffectSources");
newEffectSourcesRoot.transform.SetParent(gameObject.transform, false);
dynamicEffectSourcesRoot = new GameObject("DynamicEffectSources");
dynamicEffectSourcesRoot.transform.SetParent(gameObject.transform, false);
InitAudioMode();
}
public override void Dispose()
{
base.Dispose();
AppDispatcher.Instance.RemoveListener(AppMsg.TimeScale_Change, OnTimeScaleChange);
}
public void InitDefaultButtonClickSound(string btnSound)
{
string defaultSound = AudioConst.gameclick;
if (!string.IsNullOrEmpty(btnSound))
{
defaultSound = btnSound;
}
LoadKit.Instance.LoadAudio("Audio", defaultSound, audioClip =>
{
if (audioClip != null)
{
UIConfig.buttonSound = new NAudioClip(audioClip);
UIConfig.buttonSoundVolumeScale = 1;
}
});
}
private void OnTimeScaleChange(object value)
{
if (unscaleTimeSounds.Count != 0)
{
for (int i = 0; i < unscaleTimeSounds.Count; i++)
{
AudioSource audioSource = unscaleTimeSounds[i];
if (audioSource)
{
audioSource.pitch = 1;
}
}
}
}
public void StopBGM()
{
bgmSource.Stop();
}
public void PlayBGM(string audioName, bool isUnscaleTime = IsUnscaleTime)
{
if (string.IsNullOrEmpty(audioName)) return;
string curName = bgmSource.clip == null ? null : bgmSource.clip.name;
if (curName != audioName)
{
AudioClip currClip = null;
if (audioClipCacheDict.TryGetValue(audioName, out var value))
{
currClip = value;
}
else
{
try
{
currClip = LoadKit.Instance.LoadAsset<AudioClip>("Audio", audioName);
}
catch (Exception)
{
}
}
if (currClip != null)
{
bgmSource.clip = currClip;
if (!isOpenBGM)
{
return;
}
if (isUnscaleTime)
{
if (!unscaleTimeSounds.Contains(bgmSource))
{
unscaleTimeSounds.Add(bgmSource);
}
}
else
{
if (unscaleTimeSounds.Contains(bgmSource))
{
unscaleTimeSounds.Remove(bgmSource);
}
}
bgmSource.pitch = isUnscaleTime ? 1 : Time.timeScale;
SetBGMSound();
bgmSource.Play();
}
}
}
public void SetBGMSound()
{
if (bgmSource == null)
{
return;
}
float volume = PlayerPrefs.GetFloat("musicSound", 1.0f);
bgmSource.volume = volume;
}
public AudioSource PlayDynamicEffect(string audioName, float delay = 0, bool isLoop = false,
bool isUnscaleTime = IsUnscaleTime)
{
if (!isOpenEffect || string.IsNullOrEmpty(audioName)) return null;
if (GRoot.inst.soundVolume <= 0f) return null;
AudioSource effectSourceCom = null;
for (int i = 0; i < dynamicEffectSources.Count; i++)
{
AudioSource sourceItem = dynamicEffectSources[i];
if (!sourceItem.isPlaying)
{
effectSourceCom = sourceItem;
break;
}
}
if (effectSourceCom == null)
{
effectSourceCom = dynamicEffectSourcesRoot.AddComponent<AudioSource>();
effectSourceCom.playOnAwake = false;
dynamicEffectSources.Add(effectSourceCom);
}
if (effectSourceCom.loop != isLoop)
{
effectSourceCom.loop = isLoop;
}
string curName;
AudioClip currClip = null;
if (effectSourceCom.clip == null)
{
curName = null;
}
else
{
currClip = effectSourceCom.clip;
curName = currClip.name;
}
var playAction = new UnityAction(delegate
{
if (currClip != null)
{
effectSourceCom.clip = currClip;
if (isUnscaleTime)
{
if (!unscaleTimeSounds.Contains(effectSourceCom))
{
unscaleTimeSounds.Add(effectSourceCom);
}
}
else
{
if (unscaleTimeSounds.Contains(effectSourceCom))
{
unscaleTimeSounds.Remove(effectSourceCom);
}
}
effectSourceCom.pitch =
isUnscaleTime ? 1 : Time.timeScale;
if (delay == 0)
{
effectSourceCom.Play();
}
else
{
effectSourceCom.PlayDelayed(delay);
}
}
});
if (curName != audioName)
{
if (audioClipCacheDict.ContainsKey(audioName))
{
currClip = audioClipCacheDict[audioName];
playAction();
}
else
{
var path = new StringBuilder("Audio");
var strs = audioName.Split('.');
var assetName = strs.Last();
if (strs.Length > 1)
{
var assetUrl = audioName.Replace($".{assetName}", string.Empty);
path.Append(".").Append(assetUrl);
}
LoadKit.Instance.LoadAudio(path.ToString(), assetName, clip =>
{
currClip = clip;
audioClipCacheDict[audioName] = clip;
playAction();
});
}
}
else
{
try
{
if (delay == 0)
{
effectSourceCom.Play();
}
else
{
effectSourceCom.PlayDelayed(delay);
}
}
catch (Exception)
{
}
}
return effectSourceCom;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 865f04198a097e941bd87d4c2716d517
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace ChillConnect
{
public sealed class SceneSwitchManager : BaseUnityManager<SceneSwitchManager>
{
private const bool IsUseUnityScene = false;
public delegate void LoadCallBack(object param);
public void SwitchInitialScene(int idx, LoadCallBack loadHandler, object param)
{
StartCoroutine(OnLoadInitialScene(idx, loadHandler, param));
}
public void SwitchScene(int idx, LoadCallBack loadHandler, object param)
{
StartCoroutine(OnLoadScene(idx, loadHandler, param));
}
private IEnumerator OnLoadInitialScene(int idx, LoadCallBack loadHandle, object param)
{
yield return YieldConst.Time10ms;
if (loadHandle != null)
{
loadHandle(param);
}
}
private IEnumerator OnLoadScene(int idx, LoadCallBack loadHandle, object param)
{
yield return YieldConst.WaitFor100ms;
GC.Collect();
GC.WaitForPendingFinalizers();
if (IsUseUnityScene)
{
AsyncOperation asyncUnityScene = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(idx, LoadSceneMode.Single);
yield return asyncUnityScene;
}
if (loadHandle != null)
{
loadHandle(param);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6503fa22efaefd542a68eccaa2f4e790
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using UnityEngine;
namespace ChillConnect
{
public enum TimerTimeType
{
Null = -1,
Time = 0,
UnscaledTime = 1,
RealtimeSinceStartup = 2,
}
public sealed class TimerIManager : BaseUnityManager<TimerIManager>
{
private GameObject simpleTimersRoot;
private GameObject timersRoot;
private GameObject heavyTimersRoot;
private void InitTimersRoot()
{
simpleTimersRoot = new GameObject("SimpleTimers");
simpleTimersRoot.SetParent(gameObject);
timersRoot = new GameObject("Timers");
timersRoot.SetParent(gameObject);
heavyTimersRoot = new GameObject("HeavyTimers");
heavyTimersRoot.SetParent(gameObject);
}
public EasyTimer CreateSimpleTimer(string name, TimerTimeType type)
{
EasyTimer easyTimer = simpleTimersRoot.AddComponent<EasyTimer>();
easyTimer.SetTimer(name, type);
return easyTimer;
}
public Timer CreateTimer(string name, TimerTimeType type)
{
Timer timer = timersRoot.AddComponent<Timer>();
timer.SetTimer(name, type);
return timer;
}
#region Mgr
public override void Init()
{
base.Init();
InitTimersRoot();
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f02ecdb607607114abbe6750658a9225
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,860 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FairyGUI;
using FairyGUI.Utils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using Object = UnityEngine.Object;
namespace ChillConnect
{
public class UISequenceInfo
{
public BaseUI ui;
public object args;
public bool isLaunch;
}
public class UIParentInfo
{
public GComponent parent;
public int index;
}
public static class UIMgrConst
{
public static bool IsEnableOpenUIAnim = true;
public static bool IsEnableCloseUIAnim = true;
public static Vector2 OpenUIAnimEffectScale = new Vector2(0.8f, 0.8f);
public static float OpenUIAnimEffectTime = 0.3f;
public static float ClickDownAnimEffectScale = 0.9f;
}
public sealed class UIManager : BaseUnityManager<UIManager>
{
private const bool IsUseSafeAreaAdaptive = false;
private const bool IsSetButtonPivotCenter = false;
private GameObject eventSystemGo;
private EventSystem eventSystem;
private StandaloneInputModule inputModule;
private string uiDefaultFontName;
private List<string> commonPackageList = new List<string>();
private Queue<GGraph> uiMaskCacheQueue = new Queue<GGraph>();
private Dictionary<GObject, UIParentInfo> tempGObjectParentDict = new Dictionary<GObject, UIParentInfo>();
private Dictionary<int, Window> uiLayerWindowDict = new Dictionary<int, Window>();
private List<BaseUI> existDynamicUIs = new List<BaseUI>();
private List<BaseUI> tickUpdateUIs = new List<BaseUI>();
private List<BaseUI> normalUIRecord = new List<BaseUI>();
private List<UISequenceInfo> uiSequenceQueue = new List<UISequenceInfo>();
private ObjectPool<UISequenceInfo> uiSequencePool = new ObjectPool<UISequenceInfo>();
private Vector2 uiCenterPos;
private uint currUIOpenCumsumId;
private int closeWorldRaycastRefCount;
public void RegisterCommonPackage(string commonPackage)
{
if (!commonPackageList.Contains(commonPackage))
{
commonPackageList.Add(commonPackage);
}
}
public void RegisterCommonPackages(List<string> commonPackages)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
for (int i = 0; i < commonPackages.Count; i++)
{
string pakName = commonPackages[i];
if (UIPackage.GetByName(pakName) == null)
{
string packagePath = GetPackageUIPath(pakName);
UIPackage.AddPackage(packagePath);
}
}
return;
}
#endif
for (int i = 0; i < commonPackages.Count; i++)
{
RegisterCommonPackage(commonPackages[i]);
}
}
public void RegisterDefaultFont(string defaultFontName)
{
uiDefaultFontName = defaultFontName;
LoadKit.Instance.LoadAsset<Font>("Font", defaultFontName, font =>
{
if (font != null)
{
FontManager.RegisterFont(new DynamicFont(defaultFontName, font), defaultFontName);
InitFguiConfig();
}
});
}
public void RegisterFont(params string[] otherFontNames)
{
for (int i = 0; i < otherFontNames.Length; i++)
{
string fontName = otherFontNames[i];
LoadKit.Instance.LoadAsset<Font>("Font", fontName, font =>
{
if (font != null)
{
FontManager.RegisterFont(new DynamicFont(fontName, font), fontName);
}
});
}
}
public void DisposeAllUI()
{
while (existDynamicUIs != null && existDynamicUIs.Count != 0)
{
BaseUI ui = existDynamicUIs[existDynamicUIs.Count - 1];
Internal_CloseUI(ui, true);
}
UIPackage.RemoveAllPackages();
}
public void SwitchSceneCloseAllUI()
{
for (int i = existDynamicUIs.Count - 1; i >= 0; i--)
{
if (existDynamicUIs.Count == 0) return;
if (i >= existDynamicUIs.Count)
{
i = existDynamicUIs.Count;
}
BaseUI ui = existDynamicUIs[i];
if (ui.uiInfo.isSwitchSceneCloseUI)
{
Internal_CloseUI(ui);
}
}
}
public void Internal_OpenUI(BaseUI ui, object args = null)
{
if (!IsStartUp) return;
LoadUI(ui, args, OpenUIProcess);
}
private void OpenUIProcess(BaseUI ui, object args)
{
existDynamicUIs.Add(ui);
ui.Process_Bind();
ui.Process_OpenBefore(args);
ui.Process_Open(args);
AddNormalBaseUI(ui);
NotificationEvent(AppMsg.UIEvent_UIOpen, ui);
if (ui.uiInfo.isTickUpdate)
{
tickUpdateUIs.Add(ui);
}
if (ui.uiInfo.isClosetWorldRaycast)
{
SetWorldRaycasterEnabled(false);
}
if (UIMgrConst.IsEnableOpenUIAnim && ui.uiInfo.isNeedOpenAnim)
{
ui.KillOpenUIAnim();
OpenUIAnim(ui);
}
}
public void Internal_CloseUI(BaseUI ui, bool isImmediatelyDispose = false)
{
if (existDynamicUIs.Contains(ui))
{
existDynamicUIs.Remove(ui);
RemoveNormalBaseUI(ui);
if (ui.uiInfo.isTickUpdate)
{
tickUpdateUIs.Remove(ui);
}
ui.Process_Close();
if (UIMgrConst.IsEnableOpenUIAnim && ui.uiInfo.isNeedOpenAnim)
{
ui.KillOpenUIAnim();
}
if (UIMgrConst.IsEnableCloseUIAnim && ui.uiInfo.isNeedCloseAnim)
{
ui.KillCloseUIAnim();
CloseUIAnim(ui, () => DestroyUI(ui, isImmediatelyDispose));
}
else
{
DestroyUI(ui, isImmediatelyDispose);
}
}
}
public void Internal_HideUI(BaseUI ui)
{
ui.Process_Hide();
NotificationEvent(AppMsg.UIEvent_UIHide, ui);
}
public void Internal_DisplayUI(BaseUI ui, object args = null)
{
ui.Process_Display(args);
NotificationEvent(AppMsg.UIEvent_UIDisplay, ui);
}
private void Update()
{
if (tickUpdateUIs.Count <= 0) return;
for (int i = tickUpdateUIs.Count - 1; i >= 0; i--)
{
BaseUI ui = tickUpdateUIs[i];
if (ui == null) continue;
if (ui.isClose) continue;
if (!ui.uiInfo.isTickUpdate) continue;
ui.OnUpdate();
}
}
private void LoadUI(BaseUI ui, object args, Action<BaseUI, object> completeFunc)
{
AddUIPackage(ui.uiInfo.packageName, () => { CreateUI(ui, args, completeFunc); });
}
private void CreateUI(BaseUI ui, object args, Action<BaseUI, object> completeFunc)
{
if (string.IsNullOrEmpty(ui.uiName))
{
return;
}
GObject gObject = UIPackage.CreateObject(ui.uiInfo.packageName, ui.uiInfo.assetName);
string rawGoName = gObject.gameObjectName;
string uiGoName = string.Format("({0}){1}", ui.uiName, rawGoName);
gObject.gameObjectName = uiGoName;
gObject.displayObject.name = uiGoName;
ui.baseGObj = gObject;
ui.baseUI = ui.baseGObj.asCom;
ui.baseUI.fairyBatching = true;
ui.baseUI.name = rawGoName;
ui.rawGameObjectName = rawGoName;
ui.gameObjectName = uiGoName;
ui.baseUI.MakeFullScreen();
ui.baseUI.SetSize(GRoot.inst.width, GRoot.inst.height, false);
if (IsUseSafeAreaAdaptive)
{
Rect safeArea = Screen.safeArea;
ui.baseUI.SetPivot(0.5f, 0.5f, false);
ui.baseUI.SetSize(GRoot.inst.width, safeArea.height);
ui.baseUI.y = GRoot.inst.height - safeArea.height;
}
SetButtonClickDownEffect(ui.baseUI);
if (ui.uiInfo.gComType == UIGComType.Window)
{
Window gWindowUI = new()
{
contentPane = ui.baseUI
};
ui.windowUI = gWindowUI;
ui.windowUI.fairyBatching = true;
ui.windowUI.Show();
}
if (ui.uiInfo.isNeedUIMask)
{
GGraph uiMask = CreateUIMask(ui.uiInfo.uiMaskCustomColor);
ui.uiMask = uiMask;
ui.baseUI.AddChildAt(ui.uiMask, 0);
if (ui.uiInfo.isNeedUIMaskCloseEvent)
{
ui.uiMask.onClick.Add(ui.CtrlCloseUI);
}
}
ui.uiOpenCumsumId = ++currUIOpenCumsumId;
ui.currLayer = (int)ui.uiInfo.layerType;
uiLayerWindowDict[ui.currLayer].AddChild(ui.baseUI);
completeFunc(ui, args);
}
private void AddUIPackage(string packageName, UnityAction onCompleted = null)
{
if (UIPackage.GetByName(packageName) == null)
{
if (packageName.Contains("PLoading") || packageName.Contains("A001_bigImg"))
{
var resUIPath = Path.Combine("FGUI", packageName);
UIPackage.AddPackage(resUIPath);
onCompleted?.Invoke();
}
else
{
LoadKit.Instance.LoadAsset<TextAsset>("FGUI", $"{packageName}_fui.bytes", textAsset =>
{
UIPackage.AddPackage(textAsset.bytes, packageName,
delegate (string s, string extension, Type type, out DestroyMethod destroyMethod)
{
destroyMethod = DestroyMethod.Unload;
return LoadKit.Instance.LoadAsset<Object>("FGUI", $"{s}{extension}");
});
onCompleted?.Invoke();
});
}
}
else
{
onCompleted?.Invoke();
}
}
private string GetPackageUIPath(string packageName)
{
return string.Format("FGUI/{0}", packageName);
}
private void SetButtonClickDownEffect(GComponent gComponent)
{
GObject[] gObjects = gComponent.GetChildren();
for (int i = 0; i < gObjects.Length; i++)
{
GObject gObject = gObjects[i];
GButton gButton = gObject.asButton;
if (gButton != null && gButton.mode == ButtonMode.Common)
{
if (!gButton.name.StartsWith("obtn_"))
{
if (IsSetButtonPivotCenter)
{
gButton.SetPivot(0.5f, 0.5f, false);
}
gButton.SetClickDownEffect(UIMgrConst.ClickDownAnimEffectScale);
}
continue;
}
GComponent otherGComponent = gObject.asCom;
if (otherGComponent != null)
{
SetButtonClickDownEffect(otherGComponent);
}
}
}
private GGraph CreateUIMask(Color color)
{
GGraph uiMask = null;
if (uiMaskCacheQueue.Count > 0)
{
uiMask = GetUIMaskFormPool();
uiMask.color = color;
uiMask.visible = true;
}
else
{
uiMask = new GGraph();
uiMask.gameObjectName = "UIMask";
uiMask.name = uiMask.gameObjectName;
uiMask.SetPivot(0.5f, 0.5f, true);
uiMask.SetXY(uiCenterPos.x, uiCenterPos.y);
uiMask.DrawRect(5000, 5000, 0, Color.black, color);
}
return uiMask;
}
private GGraph GetUIMaskFormPool()
{
if (uiMaskCacheQueue.Count == 0) return null;
return uiMaskCacheQueue.Dequeue();
}
private void ReleaseUIMaskToPool(BaseUI ui)
{
if (ui.uiMask == null) return;
GGraph uiMask = ui.uiMask;
ui.baseUI.RemoveChild(uiMask);
ui.uiMask = null;
uiMask.onClick.Clear();
uiMask.visible = false;
uiMaskCacheQueue.Enqueue(uiMask);
}
private void DestroyUI(BaseUI ui, bool isImmediatelyDispose)
{
if (ui.uiInfo.isNeedUIMask)
{
ReleaseUIMaskToPool(ui);
}
if (ui.uiInfo.isClosetWorldRaycast)
{
SetWorldRaycasterEnabled(true);
}
CloseAllSubUI(ui);
DisposeUI(ui);
ui.Process_Destroy();
NotificationEvent(AppMsg.UIEvent_UIClose, ui);
QuitUISequence(ui);
UnloadAsset(ui.uiInfo.packageName, ui.uiInfo.assetName);
}
private void UnloadAsset(string packageName, string assetName)
{
if (UIPackage.GetByName(packageName) != null)
{
LoadKit.Instance.RecycleAsset(packageName);
}
}
private void DisposeUI(BaseUI ui)
{
uiLayerWindowDict[ui.currLayer].RemoveChild(ui.baseUI);
if (ui.uiInfo.gComType == UIGComType.Window)
{
if (ui.windowUI != null)
{
ui.windowUI.Dispose();
ui.windowUI = null;
}
}
ui.baseUI.Dispose();
ui.baseUI = null;
}
private void NotificationEvent(uint msgId, BaseUI ui)
{
AppDispatcher.Instance.Dispatch(msgId, ui);
}
private void OpenUIAnim(BaseUI ui)
{
GObject gObj = ui.baseUI;
gObj.pivot = VectorConst.Half;
gObj.SetScale(UIMgrConst.OpenUIAnimEffectScale.x, UIMgrConst.OpenUIAnimEffectScale.y);
ui.openUiGTweener = gObj.TweenScale(Vector3.one, UIMgrConst.OpenUIAnimEffectTime).OnComplete(() =>
{
ui.openUiGTweener = null;
ui.Process_OpenUIAnimEnd();
}).SetIgnoreEngineTimeScale(true).SetEase(EaseType.BackOut);
}
private void CloseUIAnim(BaseUI ui, Action animEndCB)
{
GObject gObj = ui.baseUI;
ui.closeUiGTweener = gObj.TweenScale(UIMgrConst.OpenUIAnimEffectScale, UIMgrConst.OpenUIAnimEffectTime)
.OnComplete(() =>
{
ui.Process_CloseUIAnimEnd();
animEndCB();
}).SetIgnoreEngineTimeScale(true).SetEase(EaseType.BackIn);
}
private void SetWorldRaycasterEnabled(bool enabled)
{
if (enabled)
{
closeWorldRaycastRefCount--;
}
else
{
closeWorldRaycastRefCount++;
}
if (closeWorldRaycastRefCount > 0)
{
CameraManager.Instance.SetWorldRaycasterEnabled(false);
}
else
{
CameraManager.Instance.SetWorldRaycasterEnabled(true);
}
}
public BaseUI GetDynamicUI(string uiName)
{
foreach (BaseUI ui in existDynamicUIs)
{
if (ui.uiName == uiName)
{
return ui;
}
}
return null;
}
public bool IsExistUI(string uiName)
{
foreach (BaseUI ui in existDynamicUIs)
{
if (ui.uiName == uiName)
{
return true;
}
}
return false;
}
public void SetGObjectUILayer(UILayerType toLayer, params GObject[] objs)
{
foreach (GObject item in objs)
{
if (item.parent != null)
{
GComponent defaultParent = item.parent;
int idx = defaultParent.GetChildIndex(item);
if (!tempGObjectParentDict.ContainsKey(item))
{
tempGObjectParentDict.Add(item, new UIParentInfo
{
parent = defaultParent,
index = idx,
});
}
}
uiLayerWindowDict[(int)toLayer].AddChild(item);
Vector2 pos = item.LocalToRoot(Vector2.zero, GRoot.inst);
item.position = pos;
}
}
public void ResetGObjectUILayer(params GObject[] objs)
{
foreach (GObject item in objs)
{
if (tempGObjectParentDict.ContainsKey(item))
{
UIParentInfo parentInfo = tempGObjectParentDict[item];
int itemIndex = parentInfo.index;
int parentCount = parentInfo.parent.GetChildrenCount();
if (parentCount != 0 && parentCount >= itemIndex)
{
parentInfo.parent.AddChildAt(item, itemIndex);
}
else
{
parentInfo.parent.AddChild(item);
}
Vector2 pos = parentInfo.parent.RootToLocal(item.position, GRoot.inst);
item.position = pos;
tempGObjectParentDict.Remove(item);
}
}
}
public bool AddNormalBaseUI(BaseUI ui)
{
if (ui.uiInfo.layerType != UILayerType.Normal) return false;
BaseUI nowUI = GetNowBaseUI();
if (nowUI == null)
{
normalUIRecord.Add(ui);
return true;
}
if (ui.uiInfo.packageName == nowUI.uiInfo.packageName &&
ui.uiInfo.assetName == nowUI.uiInfo.assetName) return false;
normalUIRecord.Add(ui);
return true;
}
public bool RemoveNormalBaseUI(BaseUI ui)
{
if (ui.uiInfo.layerType != UILayerType.Normal) return false;
{
normalUIRecord.Remove(ui);
return true;
}
}
public BaseUI GetNowBaseUI()
{
if (normalUIRecord.Count > 0)
{
return normalUIRecord[normalUIRecord.Count - 1];
}
return null;
}
private void ExecuteOpenUISequence()
{
if (uiSequenceQueue.Count == 0) return;
UISequenceInfo sequenceInfo = uiSequenceQueue[0];
if (sequenceInfo.isLaunch) return;
sequenceInfo.isLaunch = true;
BaseUI ui = sequenceInfo.ui;
ui.Open(sequenceInfo.args);
}
private void QuitUISequence(BaseUI ui)
{
if (uiSequenceQueue.Count == 0) return;
UISequenceInfo sequenceInfo = uiSequenceQueue[0];
if (sequenceInfo.ui != ui) return;
uiSequenceQueue.Remove(sequenceInfo);
uiSequencePool.Release(sequenceInfo);
ExecuteOpenUISequence();
}
public void CloseSubUI(BaseUI mainUI, SubUI subUI)
{
mainUI.subUIs.Remove(subUI);
mainUI.baseUI.RemoveChild(subUI.baseGObj);
subUI.baseUI.Dispose();
subUI.baseUI = null;
}
public void CloseAllSubUI(BaseUI mainUI)
{
List<SubUI> subUIs = mainUI.subUIs;
if (subUIs == null) return;
for (int i = subUIs.Count - 1; i >= 0; i--)
{
CloseSubUI(mainUI, subUIs[i]);
}
mainUI.subUIs.Clear();
mainUI.subUIs = null;
}
private void InitUIMgr()
{
GameObject uiRootParent = new GameObject(AppObjConst.UIGoName);
uiRootParent.layer = LayerMaskConst.UI;
AppObjConst.UIGo = uiRootParent;
AppObjConst.UIGo.SetParent(AppObjConst.FrameGo);
AppObjConst.UIGo.transform.position = new Vector3(CameraConst.UICameraPos.x, CameraConst.UICameraPos.y, 0);
InitFguiConfig();
InitFguiSettings();
InitFguiLayers();
}
private void InitEventSystem()
{
GameObject engineEventSystemGo = new GameObject("[EngineEventSystem]");
engineEventSystemGo.AddComponent<EngineEventSystem>();
engineEventSystemGo.transform.SetParent(ChillConnectCore.Instance.transform, false);
}
private void InitFguiConfig()
{
UIPackage.branch = null;
AppObjConst.UIGo.AddComponent<UIConfig>();
UIConfig.defaultFont = uiDefaultFontName;
UIConfig.enhancedTextOutlineEffect = true;
UIConfig.bringWindowToFrontOnClick = false;
UIConfig.modalLayerColor = new Color(0f, 0f, 0f, (255f / 2f) / 255f);
UIConfig.buttonSoundVolumeScale = 1;
}
private void InitFguiSettings()
{
AppObjConst.UICacheGo = new GameObject(AppObjConst.UICacheGoName);
AppObjConst.UICacheGo.SetParent(AppObjConst.FrameGo);
DisplayObject.CreateUICacheRoot(AppObjConst.UICacheGo.transform);
Stage.Instantiate();
Stage.inst.gameObject.transform.SetParent(AppObjConst.UIGo.transform, false);
Vector2Int uiResolution = AppConst.UIResolution;
GRoot.inst.SetContentScaleFactor(uiResolution.x, uiResolution.y,
UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);
uiCenterPos = new Vector2(GRoot.inst.width / 2f, GRoot.inst.height / 2f);
}
private void InitFguiLayers()
{
GRoot.inst.fairyBatching = false;
for (int i = 0; i < UILayerConst.AllUILayer.Length; i++)
{
Window uiLayerWindow = new Window();
string name = UILayerConst.AllUILayer[i];
uiLayerWindow.fairyBatching = false;
uiLayerWindow.name = name;
uiLayerWindow.displayObject.name = name;
uiLayerWindow.gameObjectName = uiLayerWindow.name;
uiLayerWindow.sortingOrder = i * 100;
uiLayerWindow.Show();
uiLayerWindow.fairyBatching = false;
uiLayerWindowDict.Add(i, uiLayerWindow);
}
}
private void InitFguiCommonPackages()
{
foreach (string commonPackage in commonPackageList)
{
Debug.Log($"Load Common Package: {commonPackage}");
LoadKit.Instance.LoadAsset<TextAsset>("FGUI", $"{commonPackage}_fui.bytes",
textAsset =>
{
UIPackage.AddPackage(textAsset.bytes, commonPackage,
delegate (string s, string extension, Type type, out DestroyMethod destroyMethod)
{
destroyMethod = DestroyMethod.Unload;
return LoadKit.Instance.LoadAsset<Object>("FGUI", $"{s}{extension}");
});
});
}
}
private void InitFguiMultiLanguage()
{
if (AppConst.IsMultiLangue)
{
Stage.inst.currLang = AppConst.InternalLangue;
}
}
public override void Init()
{
base.Init();
AppDispatcher.Instance.AddListener(AppMsg.InitUIMgr, obj =>
{
// InitReporterGo();
InitEventSystem();
InitFguiCommonPackages();
InitFguiMultiLanguage();
});
InitUIMgr();
}
public override void DisposeBefore()
{
base.DisposeBefore();
DisposeAllUI();
}
protected override void OnDestroy()
{
base.OnDestroy();
GeneralKit.Destroy(AppObjConst.UIGo);
commonPackageList.Clear();
existDynamicUIs.Clear();
tickUpdateUIs.Clear();
commonPackageList = null;
existDynamicUIs = null;
tickUpdateUIs = null;
uiSequencePool.Dispose();
uiSequenceQueue.Clear();
uiSequencePool = null;
uiSequenceQueue = null;
}
public void SetEventSystemGo(GameObject go)
{
eventSystemGo = go;
eventSystem = eventSystemGo.GetComponent<EventSystem>();
inputModule = eventSystemGo.GetComponent<StandaloneInputModule>();
}
public void SetSwitchLanguage(string switchLang)
{
if (AppConst.IsMultiLangue)
{
var multiLangueConfig =
LoadKit.Instance.LoadAsset<TextAsset>("TextAsset.I18N", "#JarvisI18N");
if (!multiLangueConfig) return;
if (string.IsNullOrWhiteSpace(multiLangueConfig.text)) return;
var multiLangueConfigList = SerializeUtil.ToObject<List<string>>(multiLangueConfig.text);
if (multiLangueConfigList == null || multiLangueConfigList.Count == 0) return;
if (string.IsNullOrWhiteSpace(switchLang)) return;
if (switchLang == Stage.inst.currLang && switchLang == AppConst.InternalLangue) return;
if (!multiLangueConfigList.Contains(switchLang)) return;
var switchLangXML = LoadKit.Instance.LoadAsset<TextAsset>("TextAsset.I18N", switchLang);
if (!switchLangXML) return;
if (string.IsNullOrWhiteSpace(switchLangXML.text)) return;
var xml = new XML(switchLangXML.text);
UIPackage.SetStringsSource(xml);
Stage.inst.currLang = switchLang;
AppConst.CurrMultiLangue = switchLang;
PlayerPrefsKit.WriteObject(PrefsKeyConst.UIMgr_switchLanguage, AppConst.CurrMultiLangue);
AppDispatcher.Instance.Dispatch(AppMsg.App_SwitchLanguage);
var uiPackageList = UIPackage.GetPackages();
foreach (var packageItem in uiPackageList.Select(uiPackage => uiPackage.GetItems()).SelectMany(
packageItemList => packageItemList.Where(packageItem => packageItem.translated)))
{
packageItem.translated = false;
}
for (var i = existDynamicUIs.Count - 1; i >= 0; i--)
{
var ui = existDynamicUIs[i];
if (ui == null) continue;
if (ui.isClose) continue;
ui.ProcessFunc_SwitchLanguage();
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46e1248ba381a29489bc7e8d2ed09cc4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: