diff --git a/Assets/AddressableAssetsData/AssetGroups/Materials.asset b/Assets/AddressableAssetsData/AssetGroups/Materials.asset index df1020f7d..2d2e63798 100644 --- a/Assets/AddressableAssetsData/AssetGroups/Materials.asset +++ b/Assets/AddressableAssetsData/AssetGroups/Materials.asset @@ -20,7 +20,8 @@ MonoBehaviour: - m_GUID: 3235960cb099ec949b5b899a120e1b58 m_Address: DotLine m_ReadOnly: 0 - m_SerializedLabels: [] + m_SerializedLabels: + - default FlaggedDuringContentUpdateRestriction: 0 m_ReadOnly: 0 m_Settings: {fileID: 11400000, guid: 77169ce22e430f64fb36c771815a4a7b, type: 2} diff --git a/Assets/RawResources/Art/大脑维修.psb.meta b/Assets/RawResources/Art/大脑维修.psb.meta index 4a3662c1f..e8d35c892 100644 --- a/Assets/RawResources/Art/大脑维修.psb.meta +++ b/Assets/RawResources/Art/大脑维修.psb.meta @@ -1289,7 +1289,7 @@ ScriptedImporter: documentAlignment: 0 importHiddenLayers: 1 layerMappingOption: 2 - generatePhysicsShape: 0 + generatePhysicsShape: 1 paperDollMode: 0 keepDupilcateSpriteName: 1 skeletonAssetReferenceID: diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs index 145c9e4fb..730650ffe 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using AibisDream.Framework; using AibisDream.Utility; using Newtonsoft.Json; using UnityEngine; @@ -123,8 +125,13 @@ namespace AibisDream.FixSystem // 设置Line的参数 dotLine.sortingLayerName = ConstRef.FixMiddleLayer; dotLine.sortingOrder = 4; - // dotLine.materials = new[] { }; - Addressables.LoadAssetAsync(ConstRef.DotLineMaterialName); + dotLine.materials = new[] { ResourceKit.LoadAssetSync(ConstRef.DotLineMaterialName) }; + dotLine.textureMode = LineTextureMode.Tile; + dotLine.loop = true; + + // 设置line的周长 + _targetSpriteRenderer.sprite.GetPhysicsShape(0, new List()); + return dotLine; } diff --git a/Assets/Scripts/Framework/ResourceKit/ResourceKit.cs b/Assets/Scripts/Framework/ResourceKit/ResourceKit.cs index ee74a832c..1b9ae5055 100644 --- a/Assets/Scripts/Framework/ResourceKit/ResourceKit.cs +++ b/Assets/Scripts/Framework/ResourceKit/ResourceKit.cs @@ -1,6 +1,10 @@ using System; +using System.Collections; +using System.Linq; using UnityEditor; using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.ResourceManagement.AsyncOperations; namespace AibisDream.Framework { @@ -10,7 +14,7 @@ namespace AibisDream.Framework { #if UNITY_EDITOR if (!sprite) return ""; - + // 先读Psd的路径 string psdPath = AssetDatabase.GetAssetPath(sprite); var psdResPath = GetResourcePath(psdPath); @@ -25,49 +29,67 @@ namespace AibisDream.Framework // 提取文件名(不包括扩展名) var purePath = psdResPath.Substring(0, lastDotIndex); - + // 添加后缀 return purePath + "/" + sprite.name; #else return null; #endif - } private static string GetResourcePath(string absolutePath) { const string resourcesFolderName = "Resources/"; - int index = absolutePath.IndexOf(resourcesFolderName, StringComparison.Ordinal); + var index = absolutePath.IndexOf(resourcesFolderName, StringComparison.Ordinal); - if (index >= 0) - { - // 获取 "Resources/" 之后的部分 - return absolutePath.Substring(index + resourcesFolderName.Length); - } - else - { - return absolutePath; - } + return index >= 0 ? absolutePath[(index + resourcesFolderName.Length)..] : absolutePath; } public static Sprite LoadSpriteFromPsd(string path) { int lastIndex = path.LastIndexOf('/'); - string spriteName = path.Substring(lastIndex + 1); - string resPath = path.Substring(0, lastIndex); - + string spriteName = path[(lastIndex + 1)..]; + string resPath = path[..lastIndex]; + // 加载 var sprites = Resources.LoadAll(resPath); - foreach (var sprite in sprites) + return sprites.FirstOrDefault(sprite => sprite.name == spriteName); + } + + public static T LoadAssetSync(string key) where T : UnityEngine.Object + { + T result = null; + var operation = Addressables.LoadAssetAsync(key); + + // 运行协程等待加载完成 + GameManager.Instance.StartCoroutine(LoadCoroutine(operation, loadedObject => result = loadedObject)); + + // 等待协程完成(阻塞主线程) + while (!operation.IsDone) { - if (sprite.name == spriteName) - { - return sprite; - } + // 主动让出一帧 + System.Threading.Thread.Sleep(1); } - return null; + return result; + } + + private static IEnumerator LoadCoroutine(AsyncOperationHandle operation, Action onComplete) + where T : UnityEngine.Object + { + yield return operation; + + if (operation.Status == AsyncOperationStatus.Succeeded) + { + onComplete?.Invoke(operation.Result); + } + else + { + Debug.LogError("Failed to load addressable"); + } + + Addressables.Release(operation); } } } \ No newline at end of file