NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Debug/TestUnityObjectReference.cs

89 lines
3.3 KiB
C#
Raw Normal View History

2024-02-20 17:29:36 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
2024-02-21 12:38:57 +08:00
using UnityEngine.UI;
2024-02-20 17:29:36 +08:00
public class TestUnityObjectReference : MonoBehaviour
{
2024-02-20 18:50:36 +08:00
private Material _testMat;
public Material serializableTestMat;
2024-02-20 17:29:36 +08:00
private List<Material> _testMatList = new();
public List<Material> serializableTestMatList = new();
public void Test()
{
2024-02-21 12:38:57 +08:00
// var path =
// "Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
// var mat = Addressables.LoadAssetAsync<Material>(path).WaitForCompletion();
// _testMatList.Add(mat);
// Debug.LogError($"Test:{_testMatList[0].name}");
2024-02-20 17:29:36 +08:00
var path =
2024-02-21 12:38:57 +08:00
"Assets/Art/UI/Texture/Poster/Poster_Default/Poster_A00001.png";
var sprite = Addressables.LoadAssetAsync<Sprite>(path).WaitForCompletion();
var image = gameObject.GetComponent<Image>()?? gameObject.AddComponent<Image>();
image.sprite = sprite;
Debug.LogError($"Test:{sprite.name}");
2024-02-20 18:50:36 +08:00
}
public void TestEnd()
{
2024-02-21 12:38:57 +08:00
var image = gameObject.GetComponent<Image>()?? gameObject.AddComponent<Image>();
Addressables.Release(image.sprite);
Debug.LogError($"TestEnd:{image.sprite == null}");
2024-02-20 17:29:36 +08:00
}
public void TestSerializable()
{
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
var mat = Addressables.LoadAssetAsync<Material>(path).WaitForCompletion();
serializableTestMatList.Add(mat);
2024-02-20 18:50:36 +08:00
Debug.LogError($"TestSerializable:{serializableTestMatList[0].name}");
}
public void TestSerializableEnd()
{
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
Addressables.Release(serializableTestMatList[0]);
Debug.LogError($"TestSerializableEnd:{serializableTestMatList[0].name}");
}
public void TestSingleStart()
{
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
_testMat = Addressables.LoadAssetAsync<Material>(path).WaitForCompletion();
Debug.LogError($"TestSingleStart:{_testMat.name}");
}
public void TestSingleEnd()
{
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
Addressables.Release(_testMat);
Debug.LogError($"TestSingleEnd:{_testMat.name}");
}
public void TestSingleSerializableStart()
{
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
serializableTestMat = Addressables.LoadAssetAsync<Material>(path).WaitForCompletion();
Debug.LogError($"TestSingleSerializableStart:{serializableTestMat.name}");
2024-02-20 17:29:36 +08:00
}
2024-02-20 18:50:36 +08:00
public void TestSingleSerializableEnd()
2024-02-20 17:29:36 +08:00
{
2024-02-20 18:50:36 +08:00
var path =
"Assets/Art/AutoGen/PostProcessScenes/Assets_Scenes_CampScene/Combined/NLD_URP_NLD_Scene_Lambert/CombieMat.mat";
Addressables.Release(serializableTestMat);
Debug.LogError($"TestSingleSerializableEnd:{serializableTestMat.name}");
2024-02-20 17:29:36 +08:00
}
}