public static void Postfix(LoadAssetPanel __instance, UIListBox ___m_SaveList) { try { // Taken from LoadAssetPanel.OnLoad var selectedIndex = ___m_SaveList.selectedIndex; var getListingMetaDataMethod = typeof(LoadSavePanelBase <CustomAssetMetaData>).GetMethod( "GetListingMetaData", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var listingMetaData = (CustomAssetMetaData)getListingMetaDataMethod.Invoke(__instance, new object[] { selectedIndex }); // Taken from LoadingManager.LoadCustomContent if (listingMetaData.userDataRef != null) { AssetDataWrapper.UserAssetData userAssetData = listingMetaData.userDataRef.Instantiate() as AssetDataWrapper.UserAssetData; if (userAssetData == null) { userAssetData = new AssetDataWrapper.UserAssetData(); } AssetData.OnAssetLoadedImpl(listingMetaData.name, ToolsModifierControl.toolController.m_editPrefabInfo, userAssetData.Data); } } catch (Exception e) { Debug.LogError(e); } }
/// <summary> /// when loading asset from a file, IAssetData.OnAssetLoaded() is called for all assets but the one that is loaded from the file. /// this postfix calls IAssetData.OnAssetLoaded() for asset loaded from file. /// Note: even if new road intanciated based on an AR Road, we still need to do this because /// NetInfo metadata is stored in external array /// also we cannot be sure that it is always instancitated properly. /// </summary> public static void Postfix(LoadAssetPanel __instance, UIListBox ___m_SaveList) { try { // Taken from LoadAssetPanel.OnLoad var selectedIndex = ___m_SaveList.selectedIndex; var listingMetaData = (CustomAssetMetaData)mListingMetaData .Invoke(__instance, new object[] { selectedIndex }); // Taken from LoadingManager.LoadCustomContent if (listingMetaData.userDataRef != null) { AssetDataWrapper.UserAssetData userAssetData = listingMetaData.userDataRef.Instantiate() as AssetDataWrapper.UserAssetData; if (userAssetData == null) { userAssetData = new AssetDataWrapper.UserAssetData(); } Log.Debug($"LoadAssetPanel.OnLoad().Postfix(): Loading asset from load asset panel"); AssetDataExtension.OnAssetLoadedImpl( listingMetaData.name, ToolsModifierControl.toolController.m_editPrefabInfo, userAssetData.Data); var originalInfo = GetOriginalNetInfo(listingMetaData); if (originalInfo) { // OnLoad() calls IntializePrefab() which reverses metadata // and can't be patched because its generic. // so we restore asset metadata here Log.Debug($" restoring original metadata."); AssetDataExtension.OnAssetLoadedImpl( listingMetaData.name, originalInfo, userAssetData.Data); } } NetInfoExtionsion.Ensure_EditedNetInfos(); Log.Debug($"LoadAssetPanel.OnLoad().Postfix() succeeded!"); } catch (Exception ex) { Log.Exception(ex); } }