public void Add(UnityObject unityObj) { try { unityObj.SetActive(false); if (_onlyCacheGameObject) { if (unityObj.AsGameObject != null) { Add(unityObj.Address, unityObj); } else { unityObj.OnDestory(); unityObj.Destroy(); } } else if (unityObj.AsObject != null) { Add(unityObj.Address, unityObj); } } catch (Exception e) { _logger.ErrorFormat("UnityGameObjectPool key:{0}, Exception:{1}", unityObj.Address, e); throw e; } }
public UnityObject GetOrNull(AssetInfo key, bool autoActive = true) { var pool = _poolDict.GetOrDefault(key); UnityObject unityObj = null; if (pool != null) { unityObj = pool.GetOrNull(); } if (unityObj != null) { if (autoActive) { unityObj.SetActive(true); } if (unityObj.AsObject == null) { unityObj = null; } } return(unityObj); }
private bool TryLoadAsGameObject(Object obj, AssetInfo assetInfo, AbstractAssetLoadRequest req) { var go = obj as GameObject; if (go != null) { var profiler = SingletonManager.Get <LoadRequestProfileHelp>().GetProfile(assetInfo); profiler.InstantiateTimes++; var hasPosition = req.Option.Position.HasValue; var hasRotation = req.Option.Rotation.HasValue; if (hasPosition || hasRotation) { var position = hasPosition ? req.Option.Position.Value : Vector3.zero; var rotation = hasRotation ? req.Option.Rotation.Value : Quaternion.identity; obj = Object.Instantiate(go, position, rotation, GetGameObjectParent(req)); } else { obj = Object.Instantiate(go, GetGameObjectParent(req), false); } go = obj as GameObject; } var unityObj = new UnityObject(obj, assetInfo); req.LoadedObject = unityObj; if (req.AutoActive) { unityObj.SetActive(true); } if (go != null) { unityObj.WithPostProcessor(req.Option.PostProcessorFactory).OnLoadFromAsset(); if (req.Option.Recyclable) { unityObj.AddUnityObjectReference(); } var profiler = SingletonManager.Get <LoadRequestProfileHelp>().GetProfile(assetInfo); profiler.TotalInstantiateTime += profiler.StopWatch(); return(true); } return(false); }
public void UnpackRequest(AssetLoadRequest <T> req, UnityObject unityObj) { if (_isDisposed) { _logger.Error("Call UnpackRequest On Disposed Asset Load Request Batch!"); return; } _loadedUnityObjects[req.BatchIndex] = unityObj; unityObj.SetActive(false); req.ReferenceBatch = null; _referenceCount--; if (_referenceCount <= 0) { _referenceCount = 0; if (_onLoaded != null) { try { if (_autoActive) { for (var i = 0; i < _loadedUnityObjects.Count; i++) { var unity = _loadedUnityObjects[i]; if (unity != null) { unity.SetActive(true); } } } _onLoaded(_source, _loadedUnityObjects); } catch (Exception e) { _logger.Error("Batch OnLoaded Callback Error", e); } } Free(this); } }
private bool TryLoadAsGameObject(Object obj, AssetInfo assetInfo, AbstractAssetLoadRequest req) { var go = obj as GameObject; if (go != null) { var profiler = SingletonManager.Get <LoadRequestProfileHelp>().GetProfile(assetInfo); profiler.InstantiateTimes++; obj = Object.Instantiate(go, GetGameObjectParent(req), false); go = obj as GameObject; } var unityObj = new UnityObject(obj, assetInfo); req.LoadedObject = unityObj; if (req.AutoActive) { unityObj.SetActive(true); } if (go != null) { unityObj.WithPostProcessor(req.Option.PostProcessorFactory).OnLoadFromAsset(); if (req.Option.Recyclable) { unityObj.AddUnityObjectReference(); } var profiler = SingletonManager.Get <LoadRequestProfileHelp>().GetProfile(assetInfo); profiler.TotalInstantiateTime += profiler.StopWatch(); return(true); } return(false); }