update 0.5.7
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Deconstruction.Runtime
|
||||
{
|
||||
public static class XericSceneHelper
|
||||
{
|
||||
public delegate void SceneOperationAsyncDelegate(TimeSpan elapsedTime, float process, bool isDone);
|
||||
|
||||
/// <summary>
|
||||
/// 获取索引对应的场景名称
|
||||
/// </summary>
|
||||
/// <param name="sceneBuildIndex"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetSceneBuildIndexName(int sceneBuildIndex)
|
||||
{
|
||||
return IsSceneBuildIndexValid(sceneBuildIndex)
|
||||
? SceneManager.GetSceneByBuildIndex(sceneBuildIndex).name
|
||||
: string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 协程加载场景
|
||||
/// </summary>
|
||||
/// <param name="sceneName"></param>
|
||||
/// <param name="loadProcess"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator LoadScene(string sceneName, SceneOperationAsyncDelegate loadProcess = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sceneName))
|
||||
{
|
||||
Debug.LogError("加载场景的名称为空或无效,请检查后重试");
|
||||
yield break;
|
||||
}
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
||||
yield return AsyncOperation(asyncLoad, loadProcess);
|
||||
}
|
||||
/// <summary>
|
||||
/// 协程加载场景
|
||||
/// </summary>
|
||||
/// <param name="sceneBuildIndex"></param>
|
||||
/// <param name="loadProcess"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator LoadScene(int sceneBuildIndex, SceneOperationAsyncDelegate loadProcess = null)
|
||||
{
|
||||
if (IsSceneBuildIndexValid(sceneBuildIndex))
|
||||
{
|
||||
Debug.LogError($"加载场景的索引({sceneBuildIndex})无效,请检查后重试");
|
||||
yield break;
|
||||
}
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(1, LoadSceneMode.Additive);
|
||||
yield return AsyncOperation(asyncLoad, loadProcess);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 协程卸载场景
|
||||
/// </summary>
|
||||
/// <param name="sceneName"></param>
|
||||
/// <param name="loadProcess"></param>
|
||||
/// <param name="froceUnloadUnusedAssets"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator UnloadSceneAsync(string sceneName, SceneOperationAsyncDelegate loadProcess = null, bool froceUnloadUnusedAssets = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sceneName))
|
||||
{
|
||||
Debug.LogError("加载场景的名称为空或无效,请检查后重试");
|
||||
yield break;
|
||||
}
|
||||
AsyncOperation asyncUnload = SceneManager.UnloadSceneAsync(sceneName);
|
||||
yield return AsyncOperation(asyncUnload, loadProcess);
|
||||
if (froceUnloadUnusedAssets)
|
||||
UnloadUnusedAssets();
|
||||
}
|
||||
/// <summary>
|
||||
/// 协程卸载场景
|
||||
/// </summary>
|
||||
/// <param name="sceneBuildIndex"></param>
|
||||
/// <param name="loadProcess"></param>
|
||||
/// <param name="froceUnloadUnusedAssets"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerator UnloadSceneAsync(int sceneBuildIndex, SceneOperationAsyncDelegate loadProcess = null, bool froceUnloadUnusedAssets = false)
|
||||
{
|
||||
if (IsSceneBuildIndexValid(sceneBuildIndex))
|
||||
{
|
||||
Debug.LogError($"加载场景的索引({sceneBuildIndex})无效,请检查后重试");
|
||||
yield break;
|
||||
}
|
||||
AsyncOperation asyncUnload = SceneManager.UnloadSceneAsync(sceneBuildIndex);
|
||||
yield return AsyncOperation(asyncUnload, loadProcess);
|
||||
if (froceUnloadUnusedAssets)
|
||||
UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
private static IEnumerator AsyncOperation(AsyncOperation asyncOperator, SceneOperationAsyncDelegate loadProcess)
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
do
|
||||
{
|
||||
loadProcess?.Invoke(DateTime.Now - startTime, asyncOperator.progress, false);
|
||||
yield return null;
|
||||
} while (!asyncOperator.isDone);
|
||||
loadProcess?.Invoke(DateTime.Now - startTime, asyncOperator.progress, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为主场景
|
||||
/// </summary>
|
||||
/// <param name="sceneName"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SetActiveScene(string sceneName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sceneName))
|
||||
{
|
||||
Debug.LogError("期望设置为主场景的名称为空或无效,请检查后重试");
|
||||
return false;
|
||||
}
|
||||
var scene = SceneManager.GetSceneByName(sceneName);
|
||||
return SceneManager.SetActiveScene(scene);
|
||||
}
|
||||
|
||||
public static bool IsSceneBuildIndexValid(int sceneBuildIndex)
|
||||
=> sceneBuildIndex < 0 || sceneBuildIndex > SceneManager.sceneCountInBuildSettings;
|
||||
|
||||
// 可选:强制进行垃圾回收,更彻底地释放内存
|
||||
public static void UnloadUnusedAssets()
|
||||
{
|
||||
Resources.UnloadUnusedAssets();
|
||||
System.GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dea79c8847b402ca99d1b51b3dd108d
|
||||
timeCreated: 1776905969
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,10 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
#if ODIN_INSPECTOR
|
||||
using Sirenix.OdinInspector;
|
||||
#endif
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Pool;
|
||||
using XericLibrary.Runtime.MacroLibrary;
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
@@ -14,6 +17,28 @@ namespace Deconstruction.UI.TmpText
|
||||
/// <summary>
|
||||
/// TMP超链接点击管理组件
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 在tmp文本中使用id块创建超链接区域,鼠标点击后,该tmp文本会发出事件。
|
||||
/// 超链接管理器可以快速管理这个事件,在事件根节点上挂载这个组件后,执行刷新操作将会自动绑定所有带有超链接的文本到此,然后由管理器发送统一的触发事件。
|
||||
/// 超链接事件由id块的id决定,当用户触发超链接后,管理器上的 onClickLink 委托会被触发。
|
||||
///
|
||||
/// 当超链接管理器的层级下包含另一个超链接管理器时,默认不会触发这个管理器下的超链接。
|
||||
/// 你可以在使用 GetChildrenTmpText2Hyperlink 追踪时手动设置 includeRepeatedMarking 为 ture 来强制包含。
|
||||
/// GetChildrenTmpText2Hyperlink是主要的用来绑定所有文本到管理器的方法,如果你只是为了刷新文本,可以直接调用 RefreshHyperLink 。
|
||||
///
|
||||
/// 注意在使用Xchart,XchartUI等动态创建tmp文本组件的功能时,需要频繁进行刷新。
|
||||
/// 特别是xchartui在刷新数据后,tmp文本会换成新的,这时必须重新刷新,否则表格中的超链接点击会没有反应。
|
||||
///
|
||||
/// 疑难解答:
|
||||
/// * 文本超链接点击没有反应。
|
||||
/// 首先检查格式是否为 <link=xxx></link> ,注意末尾一定要带上结束标记,不然tmp不识别。
|
||||
/// 其次检查是否开启了射线检测,文本上方有没有其他也处于射线检测的对象遮挡。
|
||||
/// 可以开启每个文本上的 自动解决射线检测问题 来解决。
|
||||
///
|
||||
/// * 文本没有被管理器识别。
|
||||
/// 检查文本中是否带有<link=>的标记,只要有一个标记就会被识别为可能的链接,然后挂载超链接脚本。
|
||||
/// 被挂载超链接脚本的文本后续无论如何都会被识别为超链接。
|
||||
/// </remarks>
|
||||
public class TMPHyperlinkManager : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,7 +57,16 @@ namespace Deconstruction.UI.TmpText
|
||||
[SerializeField]
|
||||
public UnityEvent<string> onClickLink = new UnityEvent<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前超链接管理器下的所有超链接
|
||||
/// </summary>
|
||||
[ShowInInspector]
|
||||
public List<TMPHyperlinkReceiver> Children { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子项发生变更
|
||||
/// </summary>
|
||||
private bool _dirty;
|
||||
/// <summary>
|
||||
/// 当前摄像机
|
||||
/// </summary>
|
||||
@@ -66,6 +100,17 @@ namespace Deconstruction.UI.TmpText
|
||||
_camera = canvas.worldCamera;
|
||||
}
|
||||
|
||||
protected void LateUpdate()
|
||||
{
|
||||
if (Children == null || Children.Count <= 0)
|
||||
return;
|
||||
for (int i = 0; i < Children.Count; i++)
|
||||
{
|
||||
if (Children[i].autoFixRayCastTargetState)
|
||||
Children[i].SetRayCastVisible();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册链接回调函数
|
||||
/// </summary>
|
||||
@@ -225,11 +270,11 @@ namespace Deconstruction.UI.TmpText
|
||||
_tempGetChildrenTmpText2Hyperlink.Count > 0)
|
||||
return _tempGetChildrenTmpText2Hyperlink;
|
||||
|
||||
var children = includeRepeatedMarking
|
||||
var children = (includeRepeatedMarking
|
||||
? transform.GetChildrenBFS()
|
||||
: transform.GetChildrenBFS<TMPHyperlinkManager>();
|
||||
: transform.GetChildrenBFS<TMPHyperlinkManager>()).ToList();
|
||||
|
||||
var result = new List<TMPHyperlinkReceiver>();
|
||||
var result = ListPool<TMPHyperlinkReceiver>.Get();
|
||||
var hyperlinkType = typeof(TMPHyperlinkReceiver);
|
||||
var tmpTextType = typeof(TMP_Text);
|
||||
|
||||
@@ -256,7 +301,11 @@ namespace Deconstruction.UI.TmpText
|
||||
result.Add(child.gameObject.AddComponent<TMPHyperlinkReceiver>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_dirty = true;
|
||||
if (Children != null)
|
||||
ListPool<TMPHyperlinkReceiver>.Release(Children);
|
||||
Children = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if ODIN_INSPECTOR
|
||||
using Sirenix.OdinInspector;
|
||||
#endif
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -79,8 +81,18 @@ namespace Deconstruction.UI.TmpText
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
// xchart会自动设置射线不可见
|
||||
if (autoFixRayCastTargetState)
|
||||
_tmpText.raycastTarget = true;
|
||||
SetRayCastVisible();
|
||||
}
|
||||
|
||||
internal void SetRayCastVisible()
|
||||
{
|
||||
if (!_tmpText)
|
||||
return;
|
||||
if (_tmpText.raycastTarget)
|
||||
return;
|
||||
_tmpText.raycastTarget = true;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+30
-32
@@ -5796,6 +5796,36 @@
|
||||
</summary>
|
||||
<param name="message"></param>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.MacroLibrary.MacroCecil">
|
||||
<summary>
|
||||
il指令分析库
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroCecil.GetAssemblyDefinition(System.Type)">
|
||||
<summary>
|
||||
从类上获取IL程序集
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroCecil.CallsBaseMethod(System.Type,System.String)">
|
||||
<summary>
|
||||
检查类上的方法是否调用了基类的类
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="methodName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroCecil.CallsBaseMethod(System.String,System.String,System.String,System.String)">
|
||||
<summary>
|
||||
检查一个方法里是否通过base.调用基类的方法
|
||||
</summary>
|
||||
<param name="assemblyPath"></param>
|
||||
<param name="typeName"></param>
|
||||
<param name="methodName"></param>
|
||||
<param name="baseMethodName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.MacroLibrary.MacroMenu">
|
||||
<summary>
|
||||
菜单宏
|
||||
@@ -10490,20 +10520,6 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroObject.GetSceneComponentFirst``1">
|
||||
<summary>
|
||||
在场景中查找组件
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroObject.GetSceneComponentLast``1">
|
||||
<summary>
|
||||
在场景中查找组件
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:XericLibrary.Runtime.MacroLibrary.MacroObject.GetAllSceneComponents``1">
|
||||
<summary>
|
||||
获取所有场景中的组件对象
|
||||
@@ -15771,15 +15787,6 @@
|
||||
原生支持各种宏用法的mono脚本
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.Type.Weakly.XericJumpWire`1">
|
||||
<summary>
|
||||
组件跳线
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<remarks>
|
||||
跳线基于场景进行组件查找,并保存关联在该实例类中供后续成员快速查找。
|
||||
</remarks>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.Type.Weakly.XericSeriousMonoBehaviour">
|
||||
<summary>
|
||||
严格模式脚本
|
||||
@@ -17018,15 +17025,6 @@
|
||||
<param name="attributeName"></param>
|
||||
<param name="hookPass"></param>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.Type.PreferredDerivedSingleMonoClassAttribute">
|
||||
<summary>
|
||||
单例首选派生类
|
||||
</summary>
|
||||
<remarks>
|
||||
只在目标单例的类型不明确,泛型类型与单例模式不成封闭关系的时候,且这样的类型不止一个的时候。
|
||||
使用这个特性标记实际需要实例化的类,在某些特殊的情况下,单例会自动根据特性进行生成。
|
||||
</remarks>
|
||||
</member>
|
||||
<member name="T:XericLibrary.Runtime.Type.WeaklyHistoryMonoBase">
|
||||
<summary>
|
||||
带有历史记录的脚本
|
||||
|
||||
Reference in New Issue
Block a user