안쓰는거 삭제
This commit is contained in:
@@ -1,171 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using XRLib;
|
||||
using XRLib.Util;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TriLibCore;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
#endif
|
||||
|
||||
|
||||
namespace XED.Manage
|
||||
{
|
||||
public class AssetManager : MonoBehaviour, ISingle
|
||||
{
|
||||
public Dictionary<string, HashSet<TwinObject>> loadedAssets = new();
|
||||
public Dictionary<string, AsyncOperationHandle<IList<GameObject>>> handles = new();
|
||||
private AssetLoaderOptions _assetLoaderOptions;
|
||||
public Action<float> onProgress;
|
||||
public Action<TwinObject> onLocalAssetLoadEnd;
|
||||
public Action onLoadAsset;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
Addressables.CleanBundleCache();
|
||||
}
|
||||
|
||||
bool isLoading;
|
||||
|
||||
public bool GetAssetsFromLabel(AssetLabel type, Action<TwinObject> callback)
|
||||
{
|
||||
if (isLoading)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string label = type.ToString();
|
||||
|
||||
if (!loadedAssets.ContainsKey(label))
|
||||
{
|
||||
loadedAssets.Add(label, new HashSet<TwinObject>());
|
||||
}
|
||||
|
||||
AsyncOperationHandle<IList<IResourceLocation>> locationHandle = Addressables.LoadResourceLocationsAsync(label);
|
||||
locationHandle.Completed += (op) => CompleteLabelExistCheck(op, callback, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CompleteLabelExistCheck(AsyncOperationHandle<IList<IResourceLocation>> handle, Action<TwinObject> successCallback, string label)
|
||||
{
|
||||
switch (handle.Status)
|
||||
{
|
||||
case AsyncOperationStatus.Succeeded:
|
||||
LoadAssets(handle.Result, successCallback, label);
|
||||
break;
|
||||
case AsyncOperationStatus.Failed:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadAssets(IList<IResourceLocation> locationHandles, Action<TwinObject> callback, string label)
|
||||
{
|
||||
foreach(var l in locationHandles)
|
||||
{
|
||||
var loadHandle = Addressables.LoadAssetAsync<TwinContainer>(l);
|
||||
loadHandle.Completed += (op) =>
|
||||
{
|
||||
var to = op.Result.twinObject;
|
||||
to.assetLabel = (AssetLabel)Enum.Parse(typeof(AssetLabel), label);
|
||||
to.metaData.address = l.PrimaryKey;
|
||||
|
||||
var texture = op.Result.twinObjectPortrait;
|
||||
var rect = new Rect(0, 0, texture.width, texture.height);
|
||||
to.metaData.portrait = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f), 1f, 0, SpriteMeshType.FullRect);
|
||||
|
||||
callback(to);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetAssetFromData(ObjectInfor infor, Action<TwinObject, ObjectInfor> callback)
|
||||
{
|
||||
if (isLoading)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string label = infor.assetLabel.ToString();
|
||||
AsyncOperationHandle<IList<IResourceLocation>> locationHandle = Addressables.LoadResourceLocationsAsync(infor.address);
|
||||
locationHandle.Completed += (op) => CompleteDataExistCheck(op, infor, callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CompleteDataExistCheck(AsyncOperationHandle<IList<IResourceLocation>> handle, ObjectInfor infor, Action<TwinObject, ObjectInfor> successCallback)
|
||||
{
|
||||
switch (handle.Status)
|
||||
{
|
||||
case AsyncOperationStatus.Succeeded:
|
||||
DataLoadAsset(handle.Result, infor, successCallback);
|
||||
break;
|
||||
case AsyncOperationStatus.Failed:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DataLoadAsset(IList<IResourceLocation> locationHandle, ObjectInfor infor, Action<TwinObject, ObjectInfor> callback)
|
||||
{
|
||||
var loadHandle = Addressables.LoadAssetsAsync<GameObject>(locationHandle, TransObject, true);
|
||||
loadHandle.Completed += (op) => CompleteDataLoadAsset(op, callback);
|
||||
void TransObject(GameObject target)
|
||||
{
|
||||
TwinObject trans = target.GetComponent<TwinObject>();
|
||||
callback(trans, infor);
|
||||
}
|
||||
}
|
||||
|
||||
void CompleteDataLoadAsset(AsyncOperationHandle<IList<GameObject>> objectHandle, Action<TwinObject, ObjectInfor> callback)
|
||||
{
|
||||
switch (objectHandle.Status)
|
||||
{
|
||||
case AsyncOperationStatus.Succeeded:
|
||||
break;
|
||||
case AsyncOperationStatus.Failed:
|
||||
break;
|
||||
case AsyncOperationStatus.None:
|
||||
break;
|
||||
}
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
public void LoadFile(LocalItem item)
|
||||
{
|
||||
if (isLoading)
|
||||
return;
|
||||
isLoading = true;
|
||||
var path = item.fileInfo.FullName;
|
||||
if (_assetLoaderOptions == null)
|
||||
{
|
||||
_assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions(false, true);
|
||||
}
|
||||
AssetLoader.LoadModelFromFile(path, null, OnLoad, OnProgress, OnError, null, _assetLoaderOptions);
|
||||
onLoadAsset?.Invoke();
|
||||
}
|
||||
|
||||
private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
|
||||
{
|
||||
var persent = progress * 100f;
|
||||
onProgress?.Invoke(persent);
|
||||
//Debug.Log($"Loading Model. Progress: {progress:P}");
|
||||
}
|
||||
|
||||
private void OnError(IContextualizedError obj)
|
||||
{
|
||||
Debug.LogError($"An error occurred while loading your Model: {obj.GetInnerException()}");
|
||||
}
|
||||
|
||||
private void OnLoad(AssetLoaderContext assetLoaderContext)
|
||||
{
|
||||
var obj = assetLoaderContext.RootGameObject;
|
||||
obj.GetOrAddComponent<BoxCollider>();
|
||||
var twin = obj.GetOrAddComponent<TwinObject>();
|
||||
isLoading = false;
|
||||
onLocalAssetLoadEnd?.Invoke(twin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd7c5a856ecb5ce48b1de5b15ab2f464
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,98 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
using XRLib;
|
||||
using XED.Interfaces;
|
||||
|
||||
namespace XED.Manage
|
||||
{
|
||||
//TODO::전체 수정 필요. 개별적인 ObjectPool이 존재하고 이 매니저는 그에 대한 접근 API만 제공하면 됨.
|
||||
public class ObjectPoolManager : MonoBehaviour, ISingle
|
||||
{
|
||||
[Serializable]
|
||||
public class ObjectInfo
|
||||
{
|
||||
//public Type objectType;
|
||||
public GameObject prefab;
|
||||
public int count;
|
||||
|
||||
public ObjectInfo(GameObject item, int count)
|
||||
{
|
||||
this.prefab = item;
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ObjectInfo> objectInfos = new();
|
||||
|
||||
HashSet<Type> cachingTypes = new();
|
||||
|
||||
Dictionary<Type, ObjectPool<Component>> cachingPools = new();
|
||||
Dictionary<Type, GameObject> prefabTable = new();
|
||||
|
||||
public void AddObjectInfo(GameObject pool)
|
||||
{
|
||||
var item = new ObjectInfo(pool, 3);
|
||||
pool.gameObject.SetActive(false);
|
||||
objectInfos.Add(item);
|
||||
}
|
||||
public T Get<T>() where T : Component
|
||||
{
|
||||
ObjectInfo targetInfo = null;
|
||||
if (!cachingTypes.Contains(typeof(T)))
|
||||
{
|
||||
foreach(var info in objectInfos)
|
||||
{
|
||||
if (!info.prefab.TryGetComponent(out T comp))
|
||||
continue;
|
||||
|
||||
prefabTable.Add(typeof(T), info.prefab);
|
||||
cachingTypes.Add(typeof(T));
|
||||
|
||||
var newPool = new ObjectPool<Component>
|
||||
(Create,
|
||||
Get,
|
||||
Release,
|
||||
Destroy, true, info.count);
|
||||
|
||||
Component Create()
|
||||
{
|
||||
var result = Instantiate(comp);
|
||||
result.GetComponent<IPooledObject>().Pool = cachingPools[typeof(T)];
|
||||
return result.GetComponent<T>();
|
||||
}
|
||||
cachingPools.Add(typeof(T), newPool);
|
||||
targetInfo = info;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!cachingTypes.Contains(typeof(T)))
|
||||
{
|
||||
Debug.LogError($"{typeof(T)} is NOT POOL");
|
||||
return default;
|
||||
}
|
||||
|
||||
return cachingPools[typeof(T)].Get().GetComponent<T>();
|
||||
}
|
||||
|
||||
|
||||
void Get(Component comp)
|
||||
{
|
||||
comp.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void Release(Component comp)
|
||||
{
|
||||
//comp.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void Destroy(Component comp)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d95a80e7f4d28f84984ffd9a3cacd121
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user