mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
修正SetSprite接口绑定资源引用关系,避免0引用导致AssetBundle被释放使图片丢失。
修正SetSprite接口绑定资源引用关系,避免0引用导致AssetBundle被释放使图片丢失。
This commit is contained in:
@@ -149,12 +149,14 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
if (!isAsync)
|
if (!isAsync)
|
||||||
{
|
{
|
||||||
image.sprite =
|
var operation = GameModule.Resource.LoadAssetGetOperation<Sprite>(spriteName, customPackageName: customPackageName);
|
||||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
image.sprite = operation.AssetObject as Sprite;
|
||||||
if (isSetNativeSize)
|
if (isSetNativeSize)
|
||||||
{
|
{
|
||||||
image.SetNativeSize();
|
image.SetNativeSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -162,14 +164,16 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
if (image == null)
|
if (image == null)
|
||||||
{
|
{
|
||||||
|
operation.Dispose();
|
||||||
|
operation = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
image.sprite = operation.AssetObject as Sprite;
|
image.sprite = operation.AssetObject as Sprite;
|
||||||
if (isSetNativeSize)
|
if (isSetNativeSize)
|
||||||
{
|
{
|
||||||
image.SetNativeSize();
|
image.SetNativeSize();
|
||||||
}
|
}
|
||||||
|
image.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||||
}, customPackageName: customPackageName);
|
}, customPackageName: customPackageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,8 +202,10 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
if (!isAsync)
|
if (!isAsync)
|
||||||
{
|
{
|
||||||
spriteRenderer.sprite =
|
var operation = GameModule.Resource.LoadAssetGetOperation<Sprite>(spriteName, customPackageName: customPackageName);
|
||||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||||
|
|
||||||
|
spriteRenderer.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -207,10 +213,13 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
if (spriteRenderer == null)
|
if (spriteRenderer == null)
|
||||||
{
|
{
|
||||||
|
operation.Dispose();
|
||||||
|
operation = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||||
|
spriteRenderer.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||||
}, customPackageName: customPackageName);
|
}, customPackageName: customPackageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,5 +290,15 @@ namespace TEngine
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AssetReference GetAssetReference(this GameObject gameObject)
|
||||||
|
{
|
||||||
|
if (gameObject == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameObject.GetComponent<AssetReference>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -59,6 +59,12 @@ namespace TEngine
|
|||||||
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null,
|
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null,
|
||||||
string packageName = "")
|
string packageName = "")
|
||||||
{
|
{
|
||||||
|
if (_operationHandle != null)
|
||||||
|
{
|
||||||
|
Log.Warning($"rebind AssetReference gameObject.name:{gameObject.name} assetLocation:{assetLocation}");
|
||||||
|
_operationHandle.Dispose();
|
||||||
|
_operationHandle = null;
|
||||||
|
}
|
||||||
_operationHandle = operation;
|
_operationHandle = operation;
|
||||||
this._assetLocation = assetLocation;
|
this._assetLocation = assetLocation;
|
||||||
this._packageName = packageName;
|
this._packageName = packageName;
|
||||||
|
Reference in New Issue
Block a user