修改unit load及unload
parent
5dd39e93e1
commit
587fefc008
|
|
@ -17,84 +17,6 @@ namespace PhxhSDK
|
|||
}
|
||||
|
||||
private Dictionary<int, GameplayInfo> _infos = new Dictionary<int, GameplayInfo>(32);
|
||||
|
||||
public void Register(int gameObjectId, GameplayInfo info)
|
||||
{
|
||||
_infos.Add(gameObjectId, info);
|
||||
}
|
||||
|
||||
|
||||
public void UnRegister(int gameObjectId)
|
||||
{
|
||||
if (_infos.ContainsKey(gameObjectId))
|
||||
{
|
||||
_infos.Remove(gameObjectId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GameplayInfo QueryByRaycast(Ray ray, int layerMask, float maxDistance = 1000, int queryDeep = 6)
|
||||
{
|
||||
try
|
||||
{
|
||||
GameplayInfo gameplayInfo;
|
||||
RaycastHit hitInfo;
|
||||
UnityEngine.Physics.Raycast(ray, out hitInfo, maxDistance, layerMask);
|
||||
var trans = hitInfo.transform;
|
||||
while (trans != null && --queryDeep >= 0)
|
||||
{
|
||||
var id = trans.gameObject.GetInstanceID();
|
||||
if (_infos.TryGetValue(id, out gameplayInfo))
|
||||
{
|
||||
return gameplayInfo;
|
||||
}
|
||||
|
||||
trans = trans.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugUtil.LogError(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameplayInfo QueryByScreen(Camera camera, Vector3 screenPosition, int layerMask,
|
||||
float maxDistance = 1000, int queryDeep = 6)
|
||||
{
|
||||
if (camera)
|
||||
{
|
||||
var ray = camera.ScreenPointToRay(screenPosition);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameplayInfo QueryByTransform(Transform trans, int queryDeep = 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
GameplayInfo gameplayInfo;
|
||||
while (trans != null && --queryDeep >= 0)
|
||||
{
|
||||
var id = trans.gameObject.GetInstanceID();
|
||||
if (_infos.TryGetValue(id, out gameplayInfo))
|
||||
{
|
||||
return gameplayInfo;
|
||||
}
|
||||
|
||||
trans = trans.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugUtil.LogError(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ using Cysharp.Threading.Tasks;
|
|||
using MagicaCloth2;
|
||||
using PhxhSDK;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Framework.Wrapper
|
||||
{
|
||||
|
|
@ -58,13 +59,14 @@ namespace Framework.Wrapper
|
|||
return _id;
|
||||
}
|
||||
|
||||
public async UniTask<GameObject> Load(string path)
|
||||
public GameObject Load(string path)
|
||||
{
|
||||
_loadStatus = LoadStatus.Loading;
|
||||
_path = path;
|
||||
UpdateGameObjectName();
|
||||
var sampleObj = await AssetManager.Instance.InstantiateGameObjectInstance(path);
|
||||
_onLoaded(sampleObj);
|
||||
var sampleObj = AssetManager.Instance.LoadAsset<GameObject>(path);
|
||||
var instObj = Object.Instantiate(sampleObj);
|
||||
_OnLoaded(instObj);
|
||||
return _node.GameObject;
|
||||
}
|
||||
|
||||
|
|
@ -77,9 +79,12 @@ namespace Framework.Wrapper
|
|||
{
|
||||
OnDispose();
|
||||
_goWrapper?.SetActive(false);
|
||||
if (_goWrapper != null) GameplayInfoManager.Instance.UnRegister(_goWrapper.GetInstanceID());
|
||||
// if (_goWrapper != null) GameplayInfoManager.Instance.UnRegister(_goWrapper.GetInstanceID());
|
||||
//Utils.Destroy(_goWrapper?.GameObject);
|
||||
AssetManager.Instance.DestroyGameObjectInstance(_goWrapper?.GameObject);
|
||||
if (_goWrapper != null && _goWrapper.GameObject != null)
|
||||
{
|
||||
Object.Destroy(_goWrapper.GameObject);
|
||||
}
|
||||
_node?.Dispose();
|
||||
_node = null;
|
||||
_loadStatus = LoadStatus.NotLoad;
|
||||
|
|
@ -113,20 +118,20 @@ namespace Framework.Wrapper
|
|||
_node.Name = name;
|
||||
}
|
||||
|
||||
private void _onLoaded(GameObject o)
|
||||
private void _OnLoaded(GameObject instObj)
|
||||
{
|
||||
if (IsDispose())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (o == null)
|
||||
if (instObj == null)
|
||||
{
|
||||
DebugUtil.LogError("Unit Load Error: path = {0}", _path);
|
||||
return;
|
||||
}
|
||||
|
||||
var go = o;
|
||||
var go = instObj;
|
||||
if (go != null)
|
||||
{
|
||||
_goWrapper = new GameObjectWrapper(go);
|
||||
|
|
@ -139,11 +144,12 @@ namespace Framework.Wrapper
|
|||
RawAnimator = collector.FirstAnimator;
|
||||
MagicaCloth = collector.MagicaClothFirst;
|
||||
|
||||
|
||||
var info = new GameplayInfoManager.GameplayInfo();
|
||||
info.id = _id;
|
||||
info.type = 0;
|
||||
GameplayInfoManager.Instance.Register(_goWrapper.GetInstanceID(), info);
|
||||
// 原用与收集unit信息然后进行选中判断,现在已弃用
|
||||
// var info = new GameplayInfoManager.GameplayInfo();
|
||||
// info.id = _id;
|
||||
// info.type = 0;
|
||||
// GameplayInfoManager.Instance.Register(_goWrapper.GetInstanceID(), info);
|
||||
|
||||
_node.AttachChild(_goWrapper);
|
||||
DebugUtil.Log("------------unit({0}) loaded, path = {1}", _id, _path);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ using Cysharp.Threading.Tasks;
|
|||
using Gameplay.Emoji;
|
||||
using Gameplay.Level;
|
||||
using Gameplay.Performance;
|
||||
using Gameplay.Unit;
|
||||
using PhxhSDK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gameplay.Character
|
||||
|
|
@ -9,9 +11,12 @@ namespace Gameplay.Character
|
|||
public partial class Character
|
||||
{
|
||||
|
||||
public async UniTask LoadAsync()
|
||||
public async UniTask CreateAsync()
|
||||
{
|
||||
var obj = await Load(runtimeData.configData.modelPath);
|
||||
var modelPath = runtimeData.configData.modelPath;
|
||||
GameUnitManager.instance.RecordLoadPath(modelPath);
|
||||
await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
||||
var obj = Load(runtimeData.configData.modelPath);
|
||||
PerformanceManager.instance.HandleCreateUnit(obj);
|
||||
await _OnObjLoaded(obj);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,6 @@ namespace Gameplay.Level
|
|||
private const string SCENE_ORIGIN_PATH = "Assets/Scenes/Maps";
|
||||
private const string SCENE_POSTPROCESS_PATH = "Assets/Art/AutoGen/Maps";
|
||||
private const string SCENE_POST_PROCESS_NAME = "PostProcess";
|
||||
|
||||
public static uint RaycastUnit(Vector3 screenPosition)
|
||||
{
|
||||
var camera = CameraManager.Instance.MainCamera;
|
||||
if (camera)
|
||||
{
|
||||
var ray = camera.ScreenPointToRay(screenPosition * PerformanceManager.instance.screenScale);
|
||||
var info = GameplayInfoManager.Instance.QueryByRaycast(ray, LayerMask.GetMask("Unit"));
|
||||
if (info != null && info.type == GameplayInfoManager.GameplayInfo.GameInfoType.Unit)
|
||||
{
|
||||
return info.id;
|
||||
}
|
||||
}
|
||||
return Constants.INVALID_UINT_ID;
|
||||
}
|
||||
|
||||
// public static bool CheckEnterLevel(int levelId)
|
||||
// {
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ namespace Gameplay.Summon
|
|||
public async void Create()
|
||||
{
|
||||
var modelPath = PathEx.GetSummonGameModelPath(configData.ModelPath);
|
||||
GameUnitManager.instance.RecordLoadPath(modelPath);
|
||||
var loadObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
||||
if (loadObj == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ namespace Gameplay.Unit
|
|||
public static GameUnitManager instance { get; private set; }
|
||||
|
||||
public bool enableLog = false;
|
||||
|
||||
private Dictionary<string, int> _loadPathRecord = new Dictionary<string, int>();
|
||||
|
||||
public static void CreateInstance()
|
||||
{
|
||||
|
|
@ -68,6 +70,18 @@ namespace Gameplay.Unit
|
|||
_RegistEvents();
|
||||
}
|
||||
|
||||
public void RecordLoadPath(string path)
|
||||
{
|
||||
if (_loadPathRecord.ContainsKey(path))
|
||||
{
|
||||
_loadPathRecord[path]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadPathRecord.Add(path, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void _RegistEvents()
|
||||
{
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
||||
|
|
@ -170,7 +184,7 @@ namespace Gameplay.Unit
|
|||
return null;
|
||||
}
|
||||
|
||||
await createUnit.LoadAsync();
|
||||
await createUnit.CreateAsync();
|
||||
await createUnit.Prepare();
|
||||
|
||||
_PrepareUnit(createUnit);
|
||||
|
|
@ -188,7 +202,7 @@ namespace Gameplay.Unit
|
|||
return null;
|
||||
}
|
||||
|
||||
await createUnit.LoadAsync();
|
||||
await createUnit.CreateAsync();
|
||||
await createUnit.Prepare();
|
||||
|
||||
_PrepareUnit(createUnit);
|
||||
|
|
@ -200,7 +214,7 @@ namespace Gameplay.Unit
|
|||
var nGuid = GUIDManager.GenGuid();
|
||||
var dataConfig = VehicleDataHelper.CombineConfigData(vInfo);
|
||||
var createUnit = new NormalVehicle(nGuid, dataConfig, troopId);
|
||||
await createUnit.Create();
|
||||
await createUnit.CreateAsync();
|
||||
await createUnit.Prepare();
|
||||
|
||||
_PrepareUnit(createUnit);
|
||||
|
|
@ -454,6 +468,18 @@ namespace Gameplay.Unit
|
|||
var unit = deadUnits.GetByIndex(i);
|
||||
unit.Dispose();
|
||||
}
|
||||
|
||||
// unload
|
||||
foreach (var kv in _loadPathRecord)
|
||||
{
|
||||
var path = kv.Key;
|
||||
var count = kv.Value;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AssetManager.Instance.Unload(path);
|
||||
}
|
||||
}
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ namespace Gameplay.Vehicle
|
|||
commonData.canControl = troopId == ETroopsId.Self;
|
||||
}
|
||||
|
||||
public async UniTask Create()
|
||||
public async UniTask CreateAsync()
|
||||
{
|
||||
GameUnitManager.instance.RecordLoadPath(configData.prefabPath);
|
||||
var sampleObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(configData.prefabPath);
|
||||
if (sampleObj == null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue