/// <summary> /// 加载场景(异步) /// </summary> /// <param name="info">资源信息标记</param> /// <param name="loadingAction">加载中事件</param> /// <param name="loadDoneAction">加载完成事件</param> /// <returns>加载协程迭代器</returns> public IEnumerator LoadSceneAsync(SceneInfo info, HTFAction <float> loadingAction, HTFAction loadDoneAction) { float beginTime = Time.realtimeSinceStartup; //单线加载,如果其他地方在加载资源,则等待 if (_isLoading) { yield return(_loadWait); } //轮到本线路加载资源 _isLoading = true; //等待相关依赖资源的加载 yield return(LoadDependenciesAssetBundleAsync(info.AssetBundleName)); float waitTime = Time.realtimeSinceStartup; if (LoadMode == ResourceLoadMode.Resource) { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载场景失败:场景加载不允许使用Resource模式!"); } else { #if UNITY_EDITOR if (IsEditorMode) { LoadSceneParameters parameters = new LoadSceneParameters() { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.None }; yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(info.AssetPath, parameters)); } else { yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.ResourcePath, LoadSceneMode.Additive)); } #else yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.ResourcePath, LoadSceneMode.Additive)); #endif } float endTime = Time.realtimeSinceStartup; Log.Info(string.Format("异步加载场景完成[{0}模式]:{1}\r\n等待耗时:{2}秒 加载耗时:{3}秒" , LoadMode.ToString() , info.ResourcePath , waitTime - beginTime , endTime - waitTime)); loadDoneAction?.Invoke(); //本线路加载资源结束 _isLoading = false; }
/// <summary> /// </summary> /// <param name="mode">a LoadMode enum (ie newgame,newmap,loadgame,loadmap,newasset,loadassett)</param> public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); CurrentLoadMode = mode; //save this guy for later. try { if (Mod.DEBUG_LOG_ON) { Logger.dbgLog("LoadMode:" + mode.ToString()); } if (Mod.isEnabled == true) { // only setup gui when in a real game, not in the asset editor if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame || (int)mode == 11) { if (Mod.DEBUG_LOG_ON) { Logger.dbgLog("Game modes detected, setting up detours."); } SettingsUI.isInGame = true; if (FireStats == null) { FireStats = new TFCStats(); } if (Singleton <LoadingManager> .instance.SupportsExpansion(Expansion.NaturalDisasters)) { TreeFireControl.Detours.DeployRedirects(); //only deploy if user has NaturalDisasters. } if (Mod.config.DisableBuildingFires) { if (Singleton <BuildingManager> .exists) { Singleton <BuildingManager> .instance.m_firesDisabled = true; if (Mod.DEBUG_LOG_ON) { Logger.dbgLog("BuildingManager.m_firesDisabled set to true"); } } } } } else { //This should technically never happen, but why not account for it anyway. if (Mod.DEBUG_LOG_ON) { Logger.dbgLog("We fired when we were not even enabled active??"); } TreeFireControl.Detours.RemoveRedirects(); SettingsUI.isInGame = false; } } catch (Exception ex) { Logger.dbgLog("Error:", ex, true); } }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); CurrentLoadMode = mode; try { if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 0) { Helper.dbgLog("LoadMode:" + mode.ToString()); } if (Mod.IsEnabled == true) { // only setup redirect when in a real game /* NewScenarioFromGame,8 * NewScenarioFromMap,9 * LoadScenario,10 * NewGameFromScenario,11 * UpdateScenarioFromGame,12 * UpdateScenarioFromMap,13 */ if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || mode == LoadMode.LoadMap || mode == LoadMode.NewMap || mode == LoadMode.NewGame || (int)mode == 8 || (int)mode == 9 || (int)mode == 10 || (int)mode == 11 || (int)mode == 12 || (int)mode == 13) { if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("Asset modes not detcted"); } if (Mod.IsGuiEnabled) { SetupGui(); } //setup gui if we're enabled. } int a = (int)CurrentLoadMode; } else { //This should never happen. if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("We fired when we were not even enabled active??"); } if (Mod.IsGuiEnabled) { RemoveGui(); } } } catch (Exception ex) { Helper.dbgLog("Error:", ex, true); } }
/// <summary> /// 加载场景(异步) /// </summary> /// <param name="info">资源信息标记</param> /// <param name="loadingAction">加载中事件</param> /// <param name="loadDoneAction">加载完成事件</param> /// <returns>加载协程迭代器</returns> public IEnumerator LoadSceneAsync(SceneInfo info, HTFAction <float> loadingAction, HTFAction loadDoneAction) { DateTime beginTime = DateTime.Now; if (_isLoading) { yield return(_loadWait); } _isLoading = true; yield return(LoadDependenciesAssetBundleAsync(info.AssetBundleName)); DateTime waitTime = DateTime.Now; if (LoadMode == ResourceLoadMode.Resource) { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载场景失败:场景加载不允许使用Resource模式!"); } else { #if UNITY_EDITOR if (IsEditorMode) { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载场景失败:场景加载不允许使用编辑器模式!"); } else { yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.AssetPath, LoadSceneMode.Additive)); } #else yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.AssetPath, LoadSceneMode.Additive)); #endif } DateTime endTime = DateTime.Now; Log.Info(string.Format("异步加载场景完成[{0}模式]:{1}\r\n等待耗时:{2}秒 加载耗时:{3}秒" , LoadMode.ToString() , info.AssetPath , (waitTime - beginTime).TotalSeconds , (endTime - waitTime).TotalSeconds)); loadDoneAction?.Invoke(); _isLoading = false; }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || (ExperimentsToggle.EnableInScenarios && mode == (LoadMode)11)) //11 is some new mode not implemented in ICities... { LoggingWrapper.Log("Loading mod"); CimTools.CimToolsHandler.CimToolBase.Changelog.DownloadChangelog(); CimTools.CimToolsHandler.CimToolBase.XMLFileOptions.Load(); if (!ExperimentsToggle.GhostMode) { if (_dateTimeGameObject == null) { _dateTimeGameObject = new GameObject("DateTimeBar"); } if (_mainUIGameObject == null) { _mainUIGameObject = new GameObject("RushHourUI"); EventPopupManager popupManager = EventPopupManager.Instance; } if (_dateTimeBar == null) { _dateTimeBar = _dateTimeGameObject.AddComponent <DateTimeBar>(); _dateTimeBar.Initialise(); } if (!_simulationRegistered) { SimulationManager.RegisterSimulationManager(_simulationManager); _simulationRegistered = true; LoggingWrapper.Log("Simulation hooked"); } Redirect(); } } else { Debug.Log("Rush Hour is not set to start up in this mode. " + mode.ToString()); } }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); CurrentLoadMode = mode; try { if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 0) { Helper.dbgLog("LoadMode:" + mode.ToString()); } if (Mod.IsEnabled == true) { // only setup redirect when in a real game /* NewScenarioFromGame,8 NewScenarioFromMap,9 LoadScenario,10 NewGameFromScenario,11 UpdateScenarioFromGame,12 UpdateScenarioFromMap,13 */ if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || mode==LoadMode.LoadMap ||mode==LoadMode.NewMap || mode== LoadMode.NewGame || (int)mode == 8 || (int)mode == 9 || (int)mode == 10 || (int)mode == 11 || (int)mode == 12 || (int)mode == 13) { if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("Asset modes not detcted"); } if (Mod.IsGuiEnabled) { SetupGui(); } //setup gui if we're enabled. } int a = (int)CurrentLoadMode; } else { //This should never happen. if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("We fired when we were not even enabled active??"); } if (Mod.IsGuiEnabled) { RemoveGui(); } } } catch(Exception ex) { Helper.dbgLog("Error:", ex, true); } }
/// <summary> /// 加载资源(异步) /// </summary> /// <typeparam name="T">资源类型</typeparam> /// <param name="info">资源信息标记</param> /// <param name="loadingAction">加载中事件</param> /// <param name="loadDoneAction">加载完成事件</param> /// <param name="isPrefab">是否是加载预制体</param> /// <param name="parent">预制体加载完成后的父级</param> /// <param name="isUI">是否是加载UI</param> /// <returns>加载协程迭代器</returns> public IEnumerator LoadAssetAsync <T>(ResourceInfoBase info, HTFAction <float> loadingAction, HTFAction <T> loadDoneAction, bool isPrefab, Transform parent, bool isUI) where T : UnityEngine.Object { DateTime beginTime = DateTime.Now; if (_isLoading) { yield return(_loadWait); } _isLoading = true; yield return(Main.Current.StartCoroutine(LoadDependenciesAssetBundleAsync(info.AssetBundleName))); DateTime waitTime = DateTime.Now; UnityEngine.Object asset = null; if (LoadMode == ResourceLoadMode.Resource) { ResourceRequest request = Resources.LoadAsync <T>(info.ResourcePath); while (!request.isDone) { loadingAction?.Invoke(request.progress); yield return(null); } asset = request.asset; if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:Resources文件夹中不存在资源 " + info.ResourcePath + "!"); } } else { #if UNITY_EDITOR if (IsEditorMode) { loadingAction?.Invoke(1); yield return(null); asset = AssetDatabase.LoadAssetAtPath <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:路径中不存在资源 " + info.AssetPath + "!"); } } else { if (AssetBundles.ContainsKey(info.AssetBundleName)) { loadingAction?.Invoke(1); yield return(null); asset = AssetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } } else { using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + info.AssetBundleName, GetAssetBundleHash(info.AssetBundleName))) { request.SendWebRequest(); while (!request.isDone) { loadingAction?.Invoke(request.downloadProgress); yield return(null); } if (!request.isNetworkError && !request.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); if (bundle) { asset = bundle.LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } if (IsCacheAssetBundle) { if (!AssetBundles.ContainsKey(info.AssetBundleName)) { AssetBundles.Add(info.AssetBundleName, bundle); } } else { bundle.Unload(false); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "请求:" + request.url + " 未下载到AB包!"); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "请求:" + request.url + " 遇到网络错误:" + request.error + "!"); } } } } #else if (AssetBundles.ContainsKey(info.AssetBundleName)) { loadingAction?.Invoke(1); yield return(null); asset = AssetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } } else { using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + info.AssetBundleName, GetAssetBundleHash(info.AssetBundleName))) { request.SendWebRequest(); while (!request.isDone) { loadingAction?.Invoke(request.downloadProgress); yield return(null); } if (!request.isNetworkError && !request.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); if (bundle) { asset = bundle.LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } if (IsCacheAssetBundle) { if (!AssetBundles.ContainsKey(info.AssetBundleName)) { AssetBundles.Add(info.AssetBundleName, bundle); } } else { bundle.Unload(false); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "请求:" + request.url + " 未下载到AB包!"); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "请求:" + request.url + " 遇到网络错误:" + request.error + "!"); } } } #endif } DateTime endTime = DateTime.Now; Log.Info(string.Format("异步加载资源{0}[{1}模式]:\r\n{2}\r\n等待耗时:{3}秒 加载耗时:{4}秒" , asset ? "成功" : "失败" , LoadMode.ToString() , LoadMode == ResourceLoadMode.Resource ? info.GetResourceFullPath() : info.GetAssetBundleFullPath(AssetBundleRootPath) , (waitTime - beginTime).TotalSeconds , (endTime - waitTime).TotalSeconds)); if (asset) { DataSetInfo dataSet = info as DataSetInfo; if (dataSet != null && dataSet.Data != null) { asset.Cast <DataSetBase>().Fill(dataSet.Data); } loadDoneAction?.Invoke(asset as T); } asset = null; _isLoading = false; }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || (ExperimentsToggle.EnableInScenarios && mode == (LoadMode)11)) //11 is some new mode not implemented in ICities... { LoggingWrapper.Log("Loading mod"); CimTools.CimToolsHandler.CimToolBase.Changelog.DownloadChangelog(); CimTools.CimToolsHandler.CimToolBase.XMLFileOptions.Load(); if (!ExperimentsToggle.GhostMode) { if (_dateTimeGameObject == null) { _dateTimeGameObject = new GameObject("DateTimeBar"); } if (_mainUIGameObject == null) { _mainUIGameObject = new GameObject("RushHourUI"); EventPopupManager popupManager = EventPopupManager.Instance; } if (_dateTimeBar == null) { _dateTimeBar = _dateTimeGameObject.AddComponent <DateTimeBar>(); _dateTimeBar.Initialise(); } if (!_simulationRegistered) { SimulationManager.RegisterSimulationManager(_simulationManager); _simulationRegistered = true; LoggingWrapper.Log("Simulation hooked"); } Redirect(); Detours = new List <Detour>(); bool detourFailed = false; try { var methodToReplace = typeof(TransportLineAI).GetMethod("SimulationStep", new[] { typeof(ushort), typeof(NetNode).MakeByRefType() }); var methodToReplaceWith = typeof(CustomTransportLineAI).GetMethod("CustomNodeSimulationStep"); if (methodToReplace == null) { Log.Info("methodToReplace == null"); } if (methodToReplaceWith == null) { Log.Info("methodToReplaceWith == null"); } var detour = new Detour(methodToReplace, methodToReplaceWith); Detours.Add(detour); } catch (Exception ex) { detourFailed = true; } Log.Info("Redirection TransportTool::RenderOverlay calls"); detourFailed = false; try { var methodToReplace = typeof(TransportManager).GetMethod("RenderLines", BindingFlags.NonPublic | BindingFlags.Instance); var methodToReplaceWith = typeof(TransportLineRenderer).GetMethod("CustomRenderLines", BindingFlags.NonPublic | BindingFlags.Instance); if (methodToReplace == null) { Log.Info("methodToReplace == null"); } if (methodToReplaceWith == null) { Log.Info("methodToReplaceWith == null"); } var detour = new Detour(methodToReplace, methodToReplaceWith); Log.Info("Redirection TransportLineAI::RenderOverlay calls step 2"); Detours.Add(detour); } catch (Exception ex) { Log.Error("Could not redirect TransportTool::RenderOverlay " + ex.Message); detourFailed = true; } } } else { Debug.Log("Rush Hour is not set to start up in this mode. " + mode.ToString()); } }
public void OnLevelLoaded(LoadMode mode) { try { Log.Message("ModCorral.OnLevelLoaded() " + mode.ToString()); if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame) { if (mcButton == null) // if not created yet { // add button to the end of the TSBar MainToolstrip (UITabStrip) UIView uiv = UIView.GetAView(); if (uiv != null) { UITabstrip ts = uiv.FindUIComponent <UITabstrip>("MainToolstrip"); if (ts != null) { UIButton policiesButton = ts.Find <UIButton>("Policies"); // we use this as a template to get 'most' of what we need set up mcButton = ts.AddTab("ModCorral", policiesButton, false); // find the panel added in the ts tabcontainer foreach (UIComponent c in ts.tabContainer.components) { if (c.name.Contains("ModCorral")) { TabPanel = c as UIPanel; c.clipChildren = false; c.opacity = 0; // otherwise our panel gets clicks obscured when it's in the same place... break; } } // initial position info StartingAbsPosY = ts.absolutePosition.y - 20; // get rid of hardcoded 20... ts.eventSelectedIndexChanged += ts_eventSelectedIndexChanged; if (mcButton != null) { StartingAbsPosX = mcButton.absolutePosition.x; mcButton.tooltip = "Open Mod Corral"; mcButton.eventTooltipShow += (component, param) => { param.tooltip.relativePosition = new Vector3(param.tooltip.relativePosition.x + 25, param.tooltip.relativePosition.y + 10, param.tooltip.relativePosition.z); }; mcButton.foregroundSpriteMode = UIForegroundSpriteMode.Scale; mcButton.scaleFactor = 0.6f; // to fit a little better when using options sprites mcButton.normalFgSprite = "Options"; mcButton.hoveredFgSprite = "OptionsHovered"; mcButton.focusedFgSprite = "OptionsFocused"; mcButton.pressedFgSprite = "OptionsPressed"; mcButton.disabledFgSprite = "OptionsDisabled"; mcButton.eventClick += mcButton_eventClick; mcButton.clipChildren = false; UIPanel fscont = uiv.FindUIComponent <UIPanel>("FullScreenContainer"); if (fscont != null) { // create our ui panel mcPanel = (ModCorralUI)fscont.AddUIComponent(typeof(ModCorralUI)); } else { Log.Message("no fullscreencontainer"); } if (mcPanel != null) { mcPanel.transform.parent = fscont.transform; mcPanel.initialize(); //mcPanel.anchor = UIAnchorStyle.All; mcPanel.isVisible = false; } ModCorralConfigDialog = (ConfigDialog)uiv.AddUIComponent(typeof(ConfigDialog)); ModCorralConfigDialog.ParentPanel = mcPanel; ModCorralConfigDialog.isVisible = false; } } else { Log.Message("failed to find maintoolstrip"); } } } // add any buttons that might have been registered before we got created if (CorralRegistration.RegisteredMods != null) { foreach (ModRegistrationInfo mri in CorralRegistration.RegisteredMods) { if (!mri.IsButtonInitialized()) { if (mri is ToggleModRegistrationInfo) { ToggleModRegistrationInfo tmri = mri as ToggleModRegistrationInfo; tmri.ToggleButton = mcPanel.ScrollPanel.AddAToggleButton(tmri); } else { mri.ModButton = mcPanel.ScrollPanel.AddAButton(mri); } } } UpdateNewCount(); } } } catch (Exception ex) { Log.Error("ModCorral.OnLevelLoaded() Exception: " + ex.Message); } }
/// <summary> /// 加载资源(异步) /// </summary> /// <typeparam name="T">资源类型</typeparam> /// <param name="info">资源信息标记</param> /// <param name="loadingAction">加载中事件</param> /// <param name="loadDoneAction">加载完成事件</param> /// <param name="isPrefab">是否是加载预制体</param> /// <param name="parent">预制体加载完成后的父级</param> /// <param name="isUI">是否是加载UI</param> /// <returns>加载协程迭代器</returns> public IEnumerator LoadAssetAsync <T>(ResourceInfoBase info, HTFAction <float> loadingAction, HTFAction <T> loadDoneAction, bool isPrefab, Transform parent, bool isUI) where T : UnityEngine.Object { float beginTime = Time.realtimeSinceStartup; //单线加载,如果其他地方在加载资源,则等待 if (_isLoading) { yield return(_loadWait); } //轮到本线路加载资源 _isLoading = true; //等待相关依赖资源的加载 yield return(LoadDependenciesAssetBundleAsync(info.AssetBundleName)); float waitTime = Time.realtimeSinceStartup; UnityEngine.Object asset = null; if (LoadMode == ResourceLoadMode.Resource) { ResourceRequest request = Resources.LoadAsync <T>(info.ResourcePath); while (!request.isDone) { loadingAction?.Invoke(request.progress); yield return(null); } asset = request.asset; if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:Resources文件夹中不存在资源 " + info.ResourcePath + "!"); } } else { #if UNITY_EDITOR if (IsEditorMode) { loadingAction?.Invoke(1); yield return(null); asset = AssetDatabase.LoadAssetAtPath <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:路径中不存在资源 " + info.AssetPath + "!"); } } else { yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); if (AssetBundles.ContainsKey(info.AssetBundleName)) { asset = AssetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } } } #else yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); if (AssetBundles.ContainsKey(info.AssetBundleName)) { asset = AssetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath + " !"); } } #endif } float endTime = Time.realtimeSinceStartup; Log.Info(string.Format("异步加载资源{0}[{1}模式]:\r\n{2}\r\n等待耗时:{3}秒 加载耗时:{4}秒" , asset ? "成功" : "失败" , LoadMode.ToString() , LoadMode == ResourceLoadMode.Resource ? info.GetResourceFullPath() : info.GetAssetBundleFullPath(AssetBundleRootPath) , waitTime - beginTime , endTime - waitTime)); if (asset) { DataSetInfo dataSet = info as DataSetInfo; if (dataSet != null && dataSet.Data != null) { asset.Cast <DataSetBase>().Fill(dataSet.Data); } loadDoneAction?.Invoke(asset as T); } else { loadDoneAction?.Invoke(null); } asset = null; //本线路加载资源结束 _isLoading = false; }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); Debug.Log("[PropLineTool, hereafter PLT]: start PropLineToolMod.OnLevelLoaded"); m_loadMode = mode; m_onLevelLoadedCount++; Debug.Log("[PLT]: Build Version: " + BUILD_VERSION); string _ordinal = Util.OrdinalSuffix(m_onLevelLoadedCount); Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): This is the " + m_onLevelLoadedCount + _ordinal + " time this method has been called, and the LoadMode is " + mode.ToString() + "."); Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): ItemClass.Availabilty of TMC tool controller is " + ToolsModifierControl.toolController.m_mode.ToString() + "."); bool _initializeToolMan = false; _initializeToolMan = ToolMan.ToolMan.Initialize(); //PropLineTool Initialization PropLineTool.PopulateRandIntArray(0, 10000); if (_initializeToolMan == true) { Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): ToolMan.Initialize() returned true."); Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): Adding/Initializing UI components..."); if (optionPanel == null) { optionPanel = (UIView.GetAView().AddUIComponent(typeof(UIOptionPanel)) as UIOptionPanel); } if (basicControlPanel == null) { basicControlPanel = (UIView.GetAView().AddUIComponent(typeof(UIBasicControlPanel)) as UIBasicControlPanel); } Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): UI components addition/initialization finished."); //debug purposes only //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("[DEBUG] Prop Line Tool [PLT] Success in Initialization", "Prop Line Tool succeeded in registering itself with the game's tool controllers!", false); } else { Debug.LogError("[PLT]: PropLineToolMod.OnLevelLoaded(): ToolMan.Initialize() returned false."); //special thanks to RushHour.Compatibility for this UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Prop Line Tool [PLT] Failed to Initialize", "Prop Line Tool failed to register itself with the game's tool controllers. Please save your output_log from this game session and post a link to it on the workshop page for PLT.", true); } Debug.Log("[PLT]: end PropLineToolMod.OnLevelLoaded"); }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); try { if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 0) { Helper.dbgLog("LoadMode:" + mode.ToString()); } if (Mod.IsEnabled == true & Mod.IsRedirectActive == false) { // only setup redirect when in a real game if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame) { if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("Map or Asset modes not detcted"); } Mod.SetupRedirects(); //setup the redirects. if (Mod.IsGuiEnabled) { SetupGui(); } //setup gui if we're enabled. } } else if (Mod.IsEnabled == false & Mod.IsRedirectActive == true) { //This should never happen. if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("Redirects were active when mod disabled?"); } Mod.ReverseRedirects(); //attempt to revert redirects if (Mod.IsGuiEnabled) { RemoveGui(); } } } catch(Exception ex) { Helper.dbgLog("Error:", ex, true); } }
public override void OnLevelLoaded(LoadMode mode) { LastSaveUsedPacking = false; if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) { Logger.dbgLog("Map LoadMode:" + mode.ToString() + " " + DateTime.Now.ToString(Mod.DTMilli)); } try { if (Mod.IsEnabled == true & Mod.IsSetupActive == false) { //should rarely, if ever, reach here as should be taken care of in onCreated(). // if we ran tried to run setup here we could but our Array was not expanded // during the load deserialize process that came before us. Hence an attempt to save will produce // a problem during custom serialze save as it'll exception error cause the buffer wasn't expanded. // Will maybe enhance custom_serialzer to check for bigger buffer first, // though let's avoid that problem entirely here. if (mode != LoadMode.LoadAsset & mode != LoadMode.NewAsset) //fire only on non Assett modes, we don't want it to get setup on assett mode anyway. { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) { Logger.dbgLog(" AssetModeNotDetcted"); } string strmsg = "[TreeUnlimiter:OnLevelLoaded] *** Enabled but not setup yet, why did this happen??\n" + "Did OnCreated() not fire?? did redirections exception error?\n If you see this please contact author or make sure other mods did not cause a critical errors prior to this one during the load process." + "\n We are now going to disable this mod from running during this map load attempt."; Logger.dbgLog(strmsg); DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, strmsg); //1.2.0f3_Build007 above noted Bug - Mod.Setup(); } } if (Mod.IsEnabled == true & Mod.IsSetupActive == true) { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) { Logger.dbgLog("Enabled and setup already.(expected)"); } if (mode == LoadMode.LoadAsset || mode == LoadMode.NewAsset) { //if we are asseteditor then revert the redirects, and reset the treemanager data. if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) { Logger.dbgLog("AssetModeDetcted, removing redirects and resetting treemanager"); } //1.6.0 commented out these 2 lines //ResetTreeMananger(Mod.DEFAULT_TREE_COUNT, Mod.DEFAULT_TREEUPDATE_COUNT, true); //Mod.ReveseSetup(); if (mode == LoadMode.NewAsset & (Singleton <TreeManager> .instance.m_treeCount < 0)) { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled()) { Logger.dbgLog("AssetModeDetcted, Treecount is less < then 0 !"); } ; //{ Singleton<TreeManager>.instance.m_treeCount = 0; } } } if (mode == LoadMode.NewMap || mode == LoadMode.LoadMap || mode == LoadMode.NewGame || mode == LoadMode.LoadMap || mode == LoadMode.NewGameFromScenario || mode == LoadMode.NewScenarioFromGame || mode == LoadMode.NewScenarioFromMap) { //total hack to address wierd behavior of -1 m_treecount and 0 itemcount // this hack attempts to jimmy things up the way things appear without the mod loaded in the map editor. // somehow the defaulting of 1 'blank' item doesn't get set correctly when using redirected functions. // really would still like to remove this hack and find actual cause. // uint inum; if (Singleton <TreeManager> .instance.m_trees.ItemCount() == 0 & Singleton <TreeManager> .instance.m_treeCount == -1) { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) { Logger.dbgLog(" New or LoadMap Detected & itemcount==0 treecount == -1"); } //removed for 1 vs 0 fix in Deserialize routine that was causing hack problem. // if (Singleton<TreeManager>.instance.m_trees.CreateItem(out inum)) // { // if (OptionsWrapper<Configuration>.Options.IsLoggingEnabled() == true) { Debug.Log("[TreeUnlimiter:OnLevelLoaded] New or Loadmap Detected - Added padding, createditem# " + inum.ToString()); } // Singleton<TreeManager>.instance.m_treeCount = (int)(Singleton<TreeManager>.instance.m_trees.ItemCount() - 1u); // if (OptionsWrapper<Configuration>.Options.IsLoggingEnabled() == true) { Debug.Log("[TreeUnlimiter:OnLevelLoaded] New or Loadmap Detected - treecount updated: " + Singleton<TreeManager>.instance.m_treeCount.ToString()); } // } } } } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() == true) //Debugging crap for the above stated hack. { if (Singleton <SimulationManager> .instance.m_metaData != null) { Logger.dbgLog(String.Format("Mapname: {0} Cityname: {1}", Singleton <SimulationManager> .instance.m_metaData.m_MapName, Singleton <SimulationManager> .instance.m_metaData.m_CityName)); } TreeManager TreeMgr = Singleton <TreeManager> .instance; int mtreecountr = TreeMgr.m_treeCount; uint mtreebuffsize = TreeMgr.m_trees.m_size; int mtreebuffleg = TreeMgr.m_trees.m_buffer.Length; uint mtreebuffcount = TreeMgr.m_trees.ItemCount(); int mupdtreenum = TreeMgr.m_updatedTrees.Length; int mburntreenum = TreeMgr.m_burningTrees.m_size; Logger.dbgLog("Debugging-TreeManager: treecount=" + mtreecountr.ToString() + " msize=" + mtreebuffsize.ToString() + " mbuffleg=" + mtreebuffleg.ToString() + " buffitemcount=" + mtreebuffcount.ToString() + " UpdatedTreesSize=" + mupdtreenum.ToString() + " burntrees=" + mburntreenum.ToString() + "\r\n"); //Debug.Log("[TreeUnlimiter:OnLevelLoaded] Done. ModStatus: " + Mod.IsEnabled.ToString() + " RedirectStatus: " + Mod.IsSetupActive.ToString()); } } catch (Exception ex) { Logger.dbgLog("Onlevelload Exception:", ex, true); } base.OnLevelLoaded(mode); }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); CurrentLoadMode = mode; try { if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 0) { Helper.dbgLog("LoadMode:" + mode.ToString()); } if (Mod.IsEnabled == true) { // only setup redirect when in a real game if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || mode==LoadMode.LoadMap ||mode==LoadMode.NewMap ) { if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("Asset modes not detcted"); } if (Mod.IsGuiEnabled) { SetupGui(); } //setup gui if we're enabled. } } else { //This should never happen. if (Mod.DEBUG_LOG_ON) { Helper.dbgLog("We fired when we were not even enabled active??"); } if (Mod.IsGuiEnabled) { RemoveGui(); } } } catch(Exception ex) { Helper.dbgLog("Error:", ex, true); } }
/// <summary> /// Optional /// This core function will get called just after the Level - aka your map has been fully loaded. /// That means the game data has all been read from your file and the simulation is ready to go. /// </summary> /// <param name="mode">a LoadMode enum (ie newgame,newmap,loadgame,loadmap,newasset,loadassett)</param> public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); //call the original implemenation first if does anything... it doesn't actually but whatever maybe some day it might. CurrentLoadMode = mode; //save this guy for later. try { if (SomeModName.DEBUG_LOG_ON && SomeModName.DEBUG_LOG_LEVEL > 0) { Logger.dbgLog("LoadMode:" + mode.ToString()); } if (SomeModName.isEnabled == true) { // only setup gui when in a real game, not in the asset editor if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || mode==LoadMode.LoadMap ||mode==LoadMode.NewMap ) { if (SomeModName.DEBUG_LOG_ON) { Logger.dbgLog("Asset modes not detcted, setting up gui."); } SetupGui(); //setup gui } } else { //This should technically never happen, but why not account for it anyway. if (SomeModName.DEBUG_LOG_ON) { Logger.dbgLog("We fired when we were not even enabled active??"); } RemoveGui(); } } catch(Exception ex) { Logger.dbgLog("Error:", ex, true); } }