/// <summary> /// This method is invoked by Unity "when the object becomes enabled and active." /// </summary> void OnEnable() { try { //First off, if this item is not randomized, don't show it. string pool = resources.PinData()[this.pinData.ID].Pool; var isRandomized = pool switch { "Dreamer" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeDreamers, "Skill" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeSkills, "Charm" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeCharms, "Key" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeKeys, "Geo" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeGeoChests, "Mask" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeMaskShards, "Vessel" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeVesselFragments, "Ore" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizePaleOre, "Notch" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeCharmNotches, "Egg" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeRancidEggs, "Relic" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeRelics, "Map" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeMaps, "Stag" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeStags, "Grub" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeGrubs, "Root" => RandomizerMod.RandomizerMod.Instance.Settings.RandomizeWhisperingRoots, _ => true, }; if (!isRandomized) { this.disableSelf(); return; } //Otherwise, check if it's reachable and/or if it has any prerequisites. this.SetIsPossible(this.pinData.Possible); if (this.isPossible) { //Set Pin state according to prereqs. this.setPrereqState(this.pinData.PreReqMet); } //Disable Pin if we've already obtained / checked this location. if (LogicManager.ItemIsChecked(this.pinData.ID.Replace('_', ' '))) { this.disableSelf(); } else { } } catch (Exception e) { logger.Error($"Failed to enable pin: {e.Message} {e.StackTrace}"); } }
private void _UpdateState() { try { if (this.PinData == null) { throw new Exception("Cannot enable pin with null pindata. Ensure game object is disabled before adding as component, then call SetPinData(<pd>) before enabling."); } //Set Pin state according to prereqs. this._UpdatePrereqState(); //Otherwise, check if it's reachable and/or if it has any prerequisites. this._UpdateReachableState(); //Disable Pin if we've already obtained / checked this location. if (GameStatus.ItemIsChecked(this.PinData.ID)) { this._DisableSelf(); } else { } } catch (Exception e) { DebugLog.Error($"Failed to enable pin! ID: {this.PinData.ID}", e); } }
/// <summary> /// 回收GameObject /// </summary> /// <param name="item"></param> public void ReleaseItem(GameObject item) { if (item == null) { DebugLog.Error(GOPoolUtil.LOGGER_NAME, "GameObjectPool::ReleaseItem->Item is Null"); return; } if (unusedItemQueue.Count > limitMaxAmount) { UnityObject.Destroy(item); return; } item.transform.SetParent(categoryTransform, false); item.SetActive(false); unusedItemQueue.Enqueue(item); #if UNITY_EDITOR //从使用列表中删除要回收的对象 for (int i = usedItemList.Count - 1; i >= 0; i--) { if (usedItemList[i].TryGetTarget(out GameObject target) && !target.IsNull()) { if (target != item) { continue; } else { usedItemList.RemoveAt(i); break; } }
internal void DoUpdate(float deltaTime) { //检查Loader初始化状态 if (State == AssetLoaderState.Initing) { DoInitUpdate(); if (State == AssetLoaderState.Running) { DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::DoUpdate->Loader init success."); initCallback?.Invoke(true); } else if (State == AssetLoaderState.Error) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::DoUpdate->Loader init failed."); initCallback?.Invoke(false); } return; } else if (State != AssetLoaderState.Running) { return; } DoWaitingDataUpdate(); DoAsyncOperationUpdate(); DoLoadingDataUpdate(); DoUnloadUnsedAssetUpdate(); }
public SceneHandler UnloadSceneAsync(string address, OnSceneLoadProgress progress, OnSceneLoadComplete complete, SystemObject userData) { if (assetLoader != null) { string scenePath = assetLoader.GetAssetPathByAddress(address); if (string.IsNullOrEmpty(scenePath)) { DebugLog.Error(AssetConst.LOGGER_NAME, "scenePath is null.address = " + address); return(null); } SceneLoaderData data = new SceneLoaderData(); data.InitUnloadData(address, scenePath, complete, progress, userData); loaderDatas.Add(data); return(data.handler); } else { DebugLog.Error(AssetConst.LOGGER_NAME, "assetloader is not init"); return(null); } }
private QuadNode InsertObjectToNode(QuadNode node, IQuadObject quadObject) { if (!node.Bounds.Contains(quadObject.Bounds)) { DebugLog.Error(LOGGER_NAME, "QuadTree::InsertObjectToNode->Object's bounds is not fit within node bounds"); return(null); } if (node.IsLeaf && node.Depth < m_MaxDepth && node.ObjectCount >= m_NodeSplitThreshold) { SplitNode(node); ResetNodeObjects(node); } if (!node.IsLeaf) { QuadNode[] childNodes = node.ChildNodes; foreach (var childNode in childNodes) { if (childNode.Bounds.Contains(quadObject.Bounds)) { return(InsertObjectToNode(childNode, quadObject)); } } } node.InsertObject(quadObject); m_ObjectToNodeDic[quadObject] = node; return(node); }
/// <summary> /// 更新指定的对象(一般情况下,由于对象发生了位置变化造成AABB变化后需要更新) /// </summary> /// <param name="quadObject"></param> public void UpdateObject(IQuadObject quadObject) { if (m_ObjectToNodeDic.TryGetValue(quadObject, out var node)) { RemoveObjectFromNode(node, quadObject); QuadNode targetNode = node; while (targetNode != null) { if (targetNode.Bounds.Contains(quadObject.Bounds)) { break; } targetNode = targetNode.ParentNode; } if (targetNode != null) { targetNode = InsertObjectToNode(targetNode, quadObject); if (targetNode != node) { MergeNode(node); } } else { DebugLog.Error(QuadTree.LOGGER_NAME, "the object hasn't been added to tree"); } } else { DebugLog.Error(QuadTree.LOGGER_NAME, "the object hasn't been added to tree"); } }
public void SceneLoad(SCENE scene) { GameObject CreateScene = null; for (int i = 0; i < SceneLoadList.Count; i++) { if (SceneLoadList[i].name.Equals(scene.ToString())) { CreateScene = SceneLoadList[i]; break; } } if (CreateScene == null) { CreateScene = Resources.Load("Scene/Scene" + scene.ToString()) as GameObject; if (CreateScene == null) { DebugLog.Error(DebugLog.LOG_TYPE.SCENE, scene.ToString() + " not find"); return; } SceneLoadList.Add(CreateScene); } StartCoroutine(SceneLoadCorountine(CreateScene)); }
/// <summary> /// 查找所有标记为指定标签的资源 /// </summary> /// <param name="label"></param> /// <returns></returns> public string[] GetAddressesByLabel(string label) { if (labelToAddressDic.TryGetValue(label, out List <string> addressList)) { return(addressList.ToArray()); } DebugLog.Error(typeof(AssetAddressConfig).Name, $"address is not found.label={label}!"); return(null); }
/// <summary> /// 根据资源的路径查找所在的AB /// </summary> /// <param name="path"></param> /// <returns></returns> public string GetBundleByPath(string path) { if (pathToDataDic.TryGetValue(path, out AssetAddressData data)) { return(data.bundlePath); } DebugLog.Error(typeof(AssetAddressConfig).Name, $"bundle is not found.path={path}!"); return(null); }
/// <summary> /// 判断资源是否是场景资源 /// </summary> /// <param name="path"></param> /// <returns></returns> public bool CheckIsSceneByPath(string path) { if (pathToDataDic.TryGetValue(path, out AssetAddressData data)) { return(data.isScene); } DebugLog.Error(typeof(AssetAddressConfig).Name, $"data is not found.path={path}!"); return(false); }
/// <summary> /// 使用资源加载接口只加载资源后,如果需要实例化时,需要统一通过此接口 /// 注意:必须使用此接口才能保证资源正常的实例化 /// </summary> /// <param name="address">资源地址</param> /// <param name="asset">加载到的资源</param> /// <returns></returns> public UnityObject InstantiateAsset(string address, UnityObject asset) { if (assetLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::InstantiateAsset->assetLoader is Null"); return(null); } return(assetLoader.InstantiateAsset(address, asset)); }
/// <summary> /// 停止正在加载中的资源 /// 如果资源已经加载完毕,调用后没有任何效果,只需要使用Destroy销毁资源即可。 /// 如果资源在加载中,则会终止资源的回调(对于使用AB加载的话,由于Unity底层接口无法停止的问题, /// 所以并不会真正停止,只是不再回调加载完成后的接口),如果此资源需要实例化,则会根据<paramref name="destroyIfIsInstnace"/> /// 来判断是否删除已经实例化的资源 /// </summary> /// <param name="handler">调用加载接口后返回的Handler</param> /// <param name="destroyIfIsInstnace">如果资源需要实例化时,对于已经实例化的实例是否需要删除,如果指定为true,则会调用Destroy销毁</param> public void UnloadAssetAsync(AssetHandler handler, bool destroyIfIsInstnace = false) { if (assetLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::UnloadAssetAsync->assetLoader is Null"); return; } assetLoader.UnloadAssetAsync(handler, destroyIfIsInstnace); }
/// <summary> /// 默认情况下资源的清理是基于GC和定时器,通过此接口可以立即深度清理资源 /// </summary> /// <param name="callback">清理完毕后回调</param> public void UnloadUnusedAsset(Action callback = null) { if (assetLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::UnloadUnusedAsset->assetLoader is Null"); return; } assetLoader.DeepUnloadUnusedAsset(callback); }
/// <summary> /// 查找资源地址对应的路径 /// </summary> /// <param name="address"></param> /// <returns></returns> public string GetPathByAddress(string address) { if (addressToDataDic.TryGetValue(address, out AssetAddressData data)) { return(data.assetPath); } DebugLog.Error(typeof(AssetAddressConfig).Name, $"Path is not found.address={address}!"); return(null); }
public void UnregistMessageHandler(int id) { if (m_MessageHandlerDic.ContainsKey(id)) { m_MessageHandlerDic.Remove(id); } else { DebugLog.Error(""); } }
public void RegistMessageHandler(int id, Action <ServerLogMessage> handler) { if (!m_MessageHandlerDic.ContainsKey(id)) { m_MessageHandlerDic.Add(id, handler); } else { DebugLog.Error(""); } }
/// <summary> /// 初始化资源加载器。 /// 在使用前必须先进行初始化,初始成功后才能正常使用 /// </summary> /// <param name="mode">资源加载模式,参见<see cref="AssetLoaderMode"/></param> /// <param name="initCallback">管理器初始化成功后回调,成功返回true,否则返回false</param> /// <param name="assetRootDir">使用AB加载资源时,需要指定AB资源所在的根目录</param> public void InitManager(AssetLoaderMode mode, Action <bool> initCallback, string assetRootDir = "") { loaderMode = mode; DebugLog.Info(AssetConst.LOGGER_NAME, $"AssetManager::InitManager->Start init mgr.mode = {mode.ToString()},assetRootDir = {assetRootDir}"); if (loaderMode == AssetLoaderMode.AssetBundle) { assetLoader = new BundleLoader(); } #if UNITY_EDITOR else { assetLoader = new DatabaseLoader(); } #endif if (assetLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader is Null"); initCallback?.Invoke(false); } else { assetLoader.Initialize((Action <bool>)((result) => { if (!result) { DebugLog.Error((string)AssetConst.LOGGER_NAME, "AssetManager::InitManager->init failed"); } DebugLog.Info((string)AssetConst.LOGGER_NAME, "AssetManager::InitManager->init Success"); if (loaderMode == AssetLoaderMode.AssetBundle) { sceneLoader = new BundleSceneLoader(assetLoader); } #if UNITY_EDITOR else { sceneLoader = new DatabaseSceneLoader(assetLoader); } #endif if (result) { StartAutoClean(); } initCallback.Invoke(result); }), assetRootDir); } }
/// <summary> /// 修改可同时进行加载的加载器的数量 /// 注意:此数量并非指定资源的数量 /// </summary> /// <param name="count">加载器的最大数量</param> public void ChangeMaxLoadingCount(int count) { if (assetLoader != null) { DebugLog.Info(AssetConst.LOGGER_NAME, $"AssetManager::ChangeMaxLoadingCount->Change Count from {assetLoader.MaxLoadingCount} to {count}"); assetLoader.MaxLoadingCount = count; } else { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::ChangeMaxLoadingCount->assetloader is null"); } }
/// <summary> /// 卸载指定的场景 /// </summary> /// <param name="address">场景地址</param> /// <param name="complete">卸载完毕后回调</param> /// <param name="progress">卸载进度回调</param> /// <param name="userData">自定义参数</param> /// <returns></returns> public SceneHandler UnloadSceneAsync(string address, OnSceneLoadProgress progress, OnSceneLoadComplete complete, SystemObject userData = null) { if (sceneLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::UnloadSceneAsync->loader hasn't been inited"); return(null); } return(sceneLoader.UnloadSceneAsync(address, progress, complete, userData)); }
private void OnCompleted(int level) { int nextLevel = level + 1; if (nextLevel >= m_Wheels.Length) { DebugLog.Error("Timer", "Timer Error"); return; } m_Wheels[nextLevel].DoPushWheel(1); }
protected internal override Object GetAsset() { if (State == OperationState.Finished) { return(asyncOperation?.assetBundle); } else { DebugLog.Error(AssetConst.LOGGER_NAME, "BundleAsyncOperation::GetAsset->bundle is not loaded"); return(null); } }
protected internal override UnityObject GetInstance() { if (uObject != null) { return(UnityObject.Instantiate(uObject)); } else { DebugLog.Error(AssetConst.LOGGER_NAME, "State is not finished or object is null"); return(null); } }
protected internal override UnityObject GetAsset() { if (uObject != null) { return(uObject); } else { DebugLog.Error(AssetConst.LOGGER_NAME, "Asset is null"); return(null); } }
public void Release(T element) { #if DEBUG if (m_Stack.Contains(element)) { DebugLog.Error("GenericObjectPool::Release->The element has been push into pool!"); return; } #endif m_OnRelease?.Invoke(element); m_Stack.Push(element); }
internal bool Trigger() { if (TriggerLeftInMS <= 0) { if (m_Category == TimerTaskCategory.End) { m_OnEndEvent?.Invoke(m_UserData); return(true); } else if (m_Category == TimerTaskCategory.Interval) { m_OnIntervalEvent?.Invoke(m_UserData); TriggerLeftInMS = m_IntervalInMS; return(false); } else if (m_Category == TimerTaskCategory.IntervalAndEnd) { m_OnIntervalEvent?.Invoke(m_UserData); m_TotalInMS -= m_IntervalInMS; if (m_TotalInMS <= 0) { m_OnEndEvent?.Invoke(m_UserData); return(true); } else { if (m_TotalInMS >= m_IntervalInMS) { TriggerLeftInMS = m_IntervalInMS; return(false); } else { m_Category = TimerTaskCategory.End; TriggerLeftInMS = m_TotalInMS; return(false); } } } else { DebugLog.Error("Timer error"); return(true); } } else { return(false); } }
/// <summary> /// 按批量方式进行资源的加载 /// 如果指定使用标签进行资源加载,则会忽略<paramref name="addresses"/>的值 /// </summary> /// <param name="label">加载设定指定标签的资源</param> /// <param name="addresses">资源加载地址</param> /// <param name="isInstance">是否需要实例化</param> /// <param name="complete">单个资源加载完毕后回调</param> /// <param name="batchComplete">所有资源加载完毕后回调</param> /// <param name="progress">单个资源加载进度回调</param> /// <param name="batchProgress">所有资源加载进度回调</param> /// <param name="priority">优先级</param> /// <param name="userData">自定义参数</param> /// <returns></returns> internal AssetHandler LoadBatchAssetAsync( string label, string[] addresses, bool isInstance, OnAssetLoadComplete complete, OnBatchAssetLoadComplete batchComplete, OnAssetLoadProgress progress, OnBatchAssetsLoadProgress batchProgress, AssetLoaderPriority priority, SystemObject userData) { //如果指定按标签加载资源,则查找标记为指定标签的所有资源 if (!string.IsNullOrEmpty(label)) { addresses = addressConfig.GetAddressesByLabel(label); DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->Load asset by label.label = {label},addresses = {string.Join(",",addresses)}"); } if (addresses == null || addresses.Length == 0) { DebugLog.Error(AssetConst.LOGGER_NAME, "AAssetLoader::LoadBatchAssetAsync->addresses is null"); return(null); } //获取资源真实的路径 string[] paths = addressConfig.GetPathsByAddresses(addresses); if (paths == null || paths.Length == 0) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->paths is null"); return(null); } else { DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->find assetPath by address.addresses = {string.Join(",", addresses)},path = {string.Join(",",paths)}"); } if (dataWaitingQueue.Count >= dataWaitingQueue.MaxSize) { dataWaitingQueue.Resize(dataWaitingQueue.MaxSize * 2); DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->Reset the queue size."); } AssetLoaderData data = dataPool.Get(); data.InitData(label, addresses, paths, isInstance, complete, progress, batchComplete, batchProgress, userData); data.State = AssetLoaderDataState.Waiting; dataWaitingQueue.Enqueue(data, (float)priority); return(data.Handler); }
/// <summary> /// 异步加载并初始化场景。场景的加载分为两步,一是加载场景资源及其依赖资源,二是初始化场景 /// </summary> /// <param name="address">场景地址</param> /// <param name="complete">加载及初始化完成后回调</param> /// <param name="progress">加载进度回调</param> /// <param name="mode">加载模式<see cref="LoadSceneMode"/></param> /// <param name="activateOnLoad">场景加载完毕后是否立即激活所有的根结点</param> /// <param name="userData">自定义参数</param> /// <returns></returns> public SceneHandler LoadSceneAsync(string address, OnSceneLoadProgress progress, OnSceneLoadComplete complete, LoadSceneMode mode = LoadSceneMode.Single, bool activateOnLoad = true, SystemObject userData = null) { if (sceneLoader == null) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetManager::LoadSceneAsync->loader hasn't been inited"); return(null); } return(sceneLoader.LoadSceneAsync(address, progress, complete, mode, activateOnLoad, userData)); }
private void ProcessSend(SocketAsyncEventArgs socketEvent) { if (socketEvent.SocketError == SocketError.Success) { lock (sendingLock) { isSending = false; } } else { DebugLog.Error(NetConst.SERVER_LOGGER_TAG, $"ServerNetSession::ProcessSend->send message error.error = {socketEvent.SocketError}"); Disconnect(); } }
/// <summary> /// 深度清理资源 /// </summary> /// <param name="callback">清理完毕后回调</param> internal void DeepUnloadUnusedAsset(Action callback) { if (unloadUnusedCallback != null) { DebugLog.Error(AssetConst.LOGGER_NAME, "UnloadUnusedAsset is running!!"); return; } unloadUnusedCallback = callback; UnloadUnusedAsset(); GC.Collect(); GC.Collect(); unloadUnusedOperation = Resources.UnloadUnusedAssets(); }