Merge branch 'develop' into 开头优化5.16.15.51
This commit is contained in:
@@ -6,9 +6,9 @@ using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class ActionKitMonoBehaviourEvents : Singleton<ActionKitMonoBehaviourEvents>
|
||||
public class ActionKitMonoBehaviourEvents : Singleton<ActionKitMonoBehaviourEvents>
|
||||
{
|
||||
private readonly EasyEvent _onUpdate = new();
|
||||
public EasyEvent OnUpdate { get; private set; }
|
||||
private readonly EasyEvent _onFixedUpdate = new();
|
||||
private readonly EasyEvent _onLateUpdate = new();
|
||||
private readonly EasyEvent _onGUIEvent = new();
|
||||
@@ -19,11 +19,17 @@ namespace AibisDream.Kit
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
hideFlags = HideFlags.HideInHierarchy;
|
||||
OnUpdate = new EasyEvent();
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
OnUpdate.UnRegisterAll();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_onUpdate?.Trigger();
|
||||
OnUpdate?.Trigger();
|
||||
|
||||
QueueUpdate();
|
||||
}
|
||||
@@ -53,11 +59,10 @@ namespace AibisDream.Kit
|
||||
_onApplicationPauseEvent?.Trigger(pauseStatus);
|
||||
}
|
||||
|
||||
// protected override void OnApplicationQuit()
|
||||
// {
|
||||
// OnApplicationQuitEvent?.Trigger();
|
||||
// base.OnApplicationQuit();
|
||||
// }
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
_onApplicationQuitEvent?.Trigger();
|
||||
}
|
||||
|
||||
public void ExecuteCoroutine(IEnumerator coroutine, Action onFinish)
|
||||
{
|
||||
|
||||
@@ -132,16 +132,16 @@ namespace AibisDream.Kit
|
||||
// {
|
||||
// return self.Start(ActionKitCurrentScene.SceneComponent, onFinish);
|
||||
// }
|
||||
//
|
||||
// public static IActionController StartGlobal(this IAction self, Action<IActionController> onFinish = null)
|
||||
// {
|
||||
// return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
// }
|
||||
//
|
||||
// public static IActionController StartGlobal(this IAction self, Action onFinish)
|
||||
// {
|
||||
// return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
// }
|
||||
|
||||
public static IActionController StartGlobal(this IAction self, Action<IActionController> onFinish = null)
|
||||
{
|
||||
return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
}
|
||||
|
||||
public static IActionController StartGlobal(this IAction self, Action onFinish)
|
||||
{
|
||||
return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
}
|
||||
|
||||
|
||||
public static void Pause(this IActionController self)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal interface IActionQueueCallback
|
||||
public interface IActionQueueCallback
|
||||
{
|
||||
void Call();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace AibisDream.Kit
|
||||
else
|
||||
{
|
||||
// 人名能找到
|
||||
var entry = LocalizationKit.ActorTableName[key];
|
||||
var entry = LocalizationKit.ActorTable[key];
|
||||
rawName = entry == null ? key : entry.LocalizedValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace AibisDream.Framework
|
||||
|
||||
private CameraEnum _curCameraEnum;
|
||||
private CamState _curInitState;
|
||||
public Camera uiCamera;
|
||||
private Camera _orthoMainCamera;
|
||||
private Camera _perspectiveMainCamera;
|
||||
|
||||
@@ -61,48 +60,10 @@ namespace AibisDream.Framework
|
||||
_orthoMainCamera.gameObject.SetActive(true);
|
||||
_perspectiveMainCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// 获取UICamera
|
||||
if (_orthoMainCamera && _orthoMainCamera.TryGetComponent<UniversalAdditionalCameraData>(out var orthoMaincameraData))
|
||||
{
|
||||
// 获取Stack Cameras
|
||||
var stackCameras = orthoMaincameraData.cameraStack;
|
||||
|
||||
// 获取UICamera
|
||||
uiCamera = stackCameras.Find(cam => cam && cam.name == "UI Camera");
|
||||
}
|
||||
|
||||
if (_perspectiveMainCamera && _perspectiveMainCamera.TryGetComponent<UniversalAdditionalCameraData>(out var perspectiveMaincameraData))
|
||||
{
|
||||
// 获取Stack Cameras
|
||||
var stackCameras = perspectiveMaincameraData.cameraStack;
|
||||
|
||||
// 获取UICamera
|
||||
uiCamera = stackCameras.Find(cam => cam && cam.name == "UI Camera");
|
||||
}
|
||||
}
|
||||
|
||||
#region 相机信息注册
|
||||
|
||||
/// <summary>
|
||||
/// 添加UI相机
|
||||
/// </summary>
|
||||
public void AddUICamera(Camera camera)
|
||||
{
|
||||
if (Camera.main && Camera.main.TryGetComponent<UniversalAdditionalCameraData>(out var cameraData))
|
||||
{
|
||||
cameraData.cameraStack.Add(camera);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveUICamera(Camera camera)
|
||||
{
|
||||
if (Camera.main && Camera.main.TryGetComponent<UniversalAdditionalCameraData>(out var cameraData))
|
||||
{
|
||||
cameraData.cameraStack.Remove(camera);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RegisterCamera(CameraEnum camType, ICinemachineCamera virtualCamera, bool isPerspective = false)
|
||||
{
|
||||
_virtualCameraDict[camType] = virtualCamera;
|
||||
@@ -157,23 +118,30 @@ namespace AibisDream.Framework
|
||||
/// </summary>
|
||||
/// <param name="camType"></param>
|
||||
public IEnumerator SwitchCamera(CameraEnum camType)
|
||||
{
|
||||
var switchDuration = SwitchCameraSync(camType);
|
||||
yield return new WaitForSeconds(switchDuration);
|
||||
}
|
||||
|
||||
public float SwitchCameraSync(CameraEnum camType)
|
||||
{
|
||||
Debug.Log("Camera Type is:" + camType);
|
||||
if (_curCameraEnum == camType)
|
||||
{
|
||||
yield break;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_virtualCameraDict.ContainsKey(camType))
|
||||
{
|
||||
Debug.Log($"{camType.ToString()}相机未注册");
|
||||
yield break;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 切换主相机
|
||||
bool isPerspective = _camInitStateDict[camType].isPerspective;
|
||||
_orthoMainCamera.gameObject.SetActive(!isPerspective);
|
||||
_perspectiveMainCamera.gameObject.SetActive(isPerspective);
|
||||
// _perspectiveMainCamera.gameObject.SetActive(isPerspective);
|
||||
var activeBrain = isPerspective ? _perspectiveCameraBrain : _orthoCameraBrain;
|
||||
|
||||
// 设置虚拟相机优先级
|
||||
foreach (var camPair in _virtualCameraDict)
|
||||
@@ -181,13 +149,23 @@ namespace AibisDream.Framework
|
||||
if (camPair.Key == camType) camPair.Value.Priority = HighPriority;
|
||||
if (camPair.Key != camType) camPair.Value.Priority = LowPriority;
|
||||
}
|
||||
|
||||
|
||||
_curInitState = _camInitStateDict[camType];
|
||||
var lastCamEnum = _curCameraEnum;
|
||||
_curCameraEnum = camType;
|
||||
|
||||
// 切完之后记得复原
|
||||
ActionKit.Delay(activeBrain.m_DefaultBlend.BlendTime, () => ResetVirCam(lastCamEnum)).StartGlobal();
|
||||
|
||||
// 等待相机切换完成
|
||||
var activeBrain = isPerspective ? _perspectiveCameraBrain : _orthoCameraBrain;
|
||||
yield return new WaitForSeconds(activeBrain.m_DefaultBlend.BlendTime);
|
||||
return activeBrain.m_DefaultBlend.BlendTime;
|
||||
}
|
||||
|
||||
private void ResetVirCam(CameraEnum cameraEnum)
|
||||
{
|
||||
var virCam = _virtualCameraDict[cameraEnum];
|
||||
virCam.VirtualCameraGameObject.transform.localPosition = _curInitState.pos;
|
||||
var camObj = virCam.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
camObj.m_Lens.OrthographicSize = _curInitState.initOrthoSize;
|
||||
}
|
||||
|
||||
public Tween TransCamera(Vector3 targetPos, float targetOrthographicSize, float duration)
|
||||
@@ -204,17 +182,31 @@ namespace AibisDream.Framework
|
||||
return sq;
|
||||
}
|
||||
|
||||
public Tween ReturnInitCamera(float duration)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="targetOrthographicSize">相机</param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public Tween TransCamera(float targetOrthographicSize, float duration)
|
||||
{
|
||||
// 寻找现在正在激活的相机
|
||||
var curCamera = _orthoCameraBrain.ActiveVirtualCamera;
|
||||
return curCamera.DOOrthoSize(targetOrthographicSize, duration);
|
||||
}
|
||||
|
||||
public Tween TransCamera(Vector3 targetPos, float duration)
|
||||
{
|
||||
// 寻找现在正在激活的相机
|
||||
var curCamera = _orthoCameraBrain.ActiveVirtualCamera;
|
||||
return curCamera.DOLocalMove(targetPos, duration);
|
||||
}
|
||||
|
||||
private Tween ReturnInitCamera(float duration)
|
||||
{
|
||||
return TransCamera(_curInitState.pos, _curInitState.initOrthoSize, duration);
|
||||
}
|
||||
|
||||
public IEnumerator TransCameraAsync(Vector3 targetPos, float duration)
|
||||
{
|
||||
var curCamera = _orthoCameraBrain.ActiveVirtualCamera;
|
||||
yield return curCamera.DOLocalMove(targetPos, duration).WaitForCompletion();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator TransCameraAsync(Vector3 targetPos, float targetOrthographicSize, float duration)
|
||||
{
|
||||
yield return TransCamera(targetPos, targetOrthographicSize, duration).WaitForCompletion();
|
||||
@@ -244,7 +236,6 @@ namespace AibisDream.Framework
|
||||
_perspectiveMainCamera :
|
||||
_orthoMainCamera;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CinemachineExtension
|
||||
@@ -259,7 +250,7 @@ namespace AibisDream.Framework
|
||||
public static TweenerCore<float, float, FloatOptions> DOOrthoSize(this ICinemachineCamera camera,
|
||||
float endValue, float duration)
|
||||
{
|
||||
var virtualCamera = camera.VirtualCameraGameObject.gameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
var virtualCamera = camera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
var currentOrthoSize = virtualCamera.m_Lens.OrthographicSize;
|
||||
return DOTween.To(() => currentOrthoSize, x => currentOrthoSize = x, endValue, duration)
|
||||
.OnUpdate(() => virtualCamera.m_Lens.OrthographicSize = currentOrthoSize);
|
||||
@@ -281,13 +272,6 @@ namespace AibisDream.Framework
|
||||
return CameraKit.Instance.TransCameraAsync(targetPos, targetOrthographicSize, duration);
|
||||
}
|
||||
|
||||
[YarnCommand("trans_camera_pos")]
|
||||
public static IEnumerator TransCameraAsync(float x, float y, float duration)
|
||||
{
|
||||
Vector3 targetPos = new Vector3(x, y, -10);
|
||||
return CameraKit.Instance.TransCameraAsync(targetPos, duration);
|
||||
}
|
||||
|
||||
[YarnCommand("shake_camera")]
|
||||
public static IEnumerator ShakeCamera(float duration, float strength, int vibrate = 10)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization;
|
||||
using UnityEngine.Localization.Settings;
|
||||
using UnityEngine.Localization.Tables;
|
||||
@@ -7,9 +8,44 @@ namespace AibisDream.Framework
|
||||
{
|
||||
public static class LocalizationKit
|
||||
{
|
||||
private static LocalizationTable _actorTableName;
|
||||
private const string LocalizationPrefix = "l10n.";
|
||||
private const string ActorTableName = "ActorName";
|
||||
private const string ParamTableName = "Params";
|
||||
|
||||
public static LocalizationTable ActorTableName => _actorTableName ??= new LocalizationTable("ActorName");
|
||||
private static LocalizationTable _paramTable;
|
||||
|
||||
public static LocalizationTable ActorTable { get; private set; }
|
||||
|
||||
static LocalizationKit()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.playModeStateChanged += OnPlayModeChanged;
|
||||
#else
|
||||
_paramTable = new LocalizationTable(ParamTableName);
|
||||
ActorTable = new LocalizationTable(ActorTableName);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static void OnPlayModeChanged(PlayModeStateChange playMode)
|
||||
{
|
||||
if (playMode == PlayModeStateChange.EnteredPlayMode)
|
||||
{
|
||||
// 进入游戏模式的时候
|
||||
_paramTable?.Dispose();
|
||||
ActorTable?.Dispose();
|
||||
_paramTable = new LocalizationTable(ParamTableName);
|
||||
ActorTable = new LocalizationTable(ActorTableName);
|
||||
}
|
||||
else if (playMode == PlayModeStateChange.ExitingPlayMode)
|
||||
{
|
||||
_paramTable?.Dispose();
|
||||
ActorTable?.Dispose();
|
||||
_paramTable = null;
|
||||
ActorTable = null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void SwitchLanguage(string localeCode)
|
||||
{
|
||||
@@ -25,6 +61,45 @@ namespace AibisDream.Framework
|
||||
Debug.LogWarning($"Locale with code {localeCode} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地化参数
|
||||
/// </summary>
|
||||
/// <param name="param">参数名</param>
|
||||
/// <param name="table">本地化表</param>
|
||||
/// <returns></returns>
|
||||
public static string LocalizeParam(string param, LocalizationTable table)
|
||||
{
|
||||
// 非本地化参数直接返回
|
||||
if (!param.StartsWith(LocalizationPrefix)) return param;
|
||||
|
||||
var localizationKey = param[LocalizationPrefix.Length..];
|
||||
// 获取本地化值
|
||||
if (table.TryGetValue(localizationKey, out var value))
|
||||
{
|
||||
return value.LocalizedValue;
|
||||
}
|
||||
|
||||
// 如果找不到,则使用原始值
|
||||
Debug.LogWarning($"Variable Key '{localizationKey}' not found in localization table.");
|
||||
return localizationKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地化参数
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public static string LocalizeParam(string param)
|
||||
{
|
||||
return LocalizeParam(param, _paramTable);
|
||||
}
|
||||
|
||||
public static string GetL10NParamKey(string key)
|
||||
{
|
||||
// 本地化参数则去除前缀,非本地化参数直接返回
|
||||
return key.StartsWith(LocalizationPrefix) ? key[LocalizationPrefix.Length..] : key;
|
||||
}
|
||||
}
|
||||
|
||||
public class LocalizationTable
|
||||
@@ -55,6 +130,12 @@ namespace AibisDream.Framework
|
||||
|
||||
public StringTableEntry this[string key] => _stringTable[key];
|
||||
|
||||
public bool TryGetValue(string key, out StringTableEntry value)
|
||||
{
|
||||
value = _stringTable.GetEntry(key);
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public LocaleIdentifier LocaleIdentifier => _stringTable.LocaleIdentifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
/// <summary>
|
||||
/// 实现一个类似沙漏的功能,给一个命令就开始倒计时,倒计时结束执行命令
|
||||
/// </summary>
|
||||
public class SandClock
|
||||
{
|
||||
public float CountDownTime { get; private set; }
|
||||
public float CurTime { get; private set; }
|
||||
private readonly Action _endAction;
|
||||
|
||||
public SandClock(float duration, Action endAction)
|
||||
{
|
||||
CountDownTime = duration;
|
||||
_endAction = endAction;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ActionKitMonoBehaviourEvents.Instance.OnUpdate.Register(OnUpdate);
|
||||
CurTime = 0;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
CurTime = 0;
|
||||
ActionKitMonoBehaviourEvents.Instance.OnUpdate.UnRegister(OnUpdate);
|
||||
_endAction?.Invoke();
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
ActionKitMonoBehaviourEvents.Instance.OnUpdate.UnRegister(OnUpdate);
|
||||
}
|
||||
|
||||
public void Continue()
|
||||
{
|
||||
ActionKitMonoBehaviourEvents.Instance.OnUpdate.Register(OnUpdate);
|
||||
}
|
||||
|
||||
private void OnUpdate()
|
||||
{
|
||||
CurTime += Time.deltaTime;
|
||||
if (CurTime >= CountDownTime)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d28e020c83b488db18eaaaa0a0f352c
|
||||
timeCreated: 1747810225
|
||||
Reference in New Issue
Block a user