/// <summary> /// Called by the scene controller, loads animations from the loaded or imported scene /// </summary> internal void LoadAnimations(int characterDicKey, ReadOnlyDictionary <int, ObjectCtrlInfo> loadedItems) { try { PluginData ExtendedData = ExtendedSave.GetSceneExtendedDataById(PluginNameInternal); //Version 1 save data if (ExtendedData?.data != null && ExtendedData.data.ContainsKey("AnimationInfo")) { List <AnimationControllerInfo> AnimationControllerInfoList = ((object[])ExtendedData.data["AnimationInfo"]).Select(x => AnimationControllerInfo.Unserialize((byte[])x)).ToList(); foreach (var AnimInfo in AnimationControllerInfoList) { //See if this is the right character if (AnimInfo.CharDicKey != characterDicKey) { continue; } ObjectCtrlInfo linkedItem = loadedItems[AnimInfo.ItemDicKey]; if (AnimInfo.Version.IsNullOrEmpty()) { AddLinkV1(AnimInfo.IKPart, linkedItem); } else { AddLink(AnimInfo.IKPart, linkedItem); } } } //Version 2 save data else { var data = GetExtendedData(); if (data?.data != null) { if (data.data.TryGetValue("LinksV1", out var loadedLinksV1) && loadedLinksV1 != null) { foreach (var link in (Dictionary <object, object>)loadedLinksV1) { AddLinkV1((string)link.Key, loadedItems[(int)link.Value]); } } if (data.data.TryGetValue("Links", out var loadedLinks) && loadedLinks != null) { foreach (var link in (Dictionary <object, object>)loadedLinks) { AddLink((string)link.Key, loadedItems[(int)link.Value]); } } if (data.data.TryGetValue("Eyes", out var loadedEyeLink) && loadedEyeLink != null) { AddEyeLink(loadedItems[(int)loadedEyeLink]); } if (data.data.TryGetValue("Neck", out var loadedNeckLink) && loadedNeckLink != null) { AddNeckLink(loadedItems[(int)loadedNeckLink]); } } } Logger.Log(LogLevel.Debug, $"Loaded KK_AnimationController animations for character {ChaControl.chaFile.parameter.fullname.Trim()}"); } catch (Exception ex) { Logger.Log(LogLevel.Error | LogLevel.Message, "Could not load KK_AnimationController animations."); Logger.Log(LogLevel.Error, ex.ToString()); } }
/// <summary> /// Scene has to be fully loaded for all characters and objects to exist in the game /// </summary> private void SceneLoaded(Scene s, LoadSceneMode lsm) { if (s.name == "StudioNotification" && LoadClicked) { LoadClicked = false; try { IKObjectInfoList.Clear(); PluginData ExtendedData = ExtendedSave.GetSceneExtendedDataById(PluginName); if (ExtendedData != null && ExtendedData.data.ContainsKey("AnimationInfo")) { List <AnimationControllerInfo> AnimationControllerInfoList; AnimationControllerInfoList = ((object[])ExtendedData.data["AnimationInfo"]).Select(x => AnimationControllerInfo.Unserialize((byte[])x)).ToList(); foreach (var AnimInfo in AnimationControllerInfoList) { IKObjectInfo LoadedAnimInfo = new IKObjectInfo(); var Character = Singleton <Studio.Studio> .Instance.dicObjectCtrl.Where(x => x.Key == AnimInfo.CharDicKey).Select(x => x.Value as OCIChar).First(); LoadedAnimInfo.CharacterKey = AnimInfo.CharDicKey; LoadedAnimInfo.CharacterObject = GameObject.Find(Character.charInfo.name); LoadedAnimInfo.IKPart = AnimInfo.IKPart; LoadedAnimInfo.IKTarget = Character.listIKTarget.Where(x => x.boneObject.name == AnimInfo.IKPart).First(); var LinkedItem = Singleton <Studio.Studio> .Instance.dicObjectCtrl.Where(x => x.Key == AnimInfo.ItemDicKey).Select(x => x.Value).First(); switch (LinkedItem) { case OCIItem Item: LoadedAnimInfo.ObjectKey = Item.objectInfo.dicKey; LoadedAnimInfo.SelectedObject = Item.childRoot.gameObject; break; case OCIFolder Folder: LoadedAnimInfo.ObjectKey = Folder.objectInfo.dicKey; LoadedAnimInfo.SelectedObject = Folder.childRoot.gameObject; break; case OCIRoute Route: LoadedAnimInfo.ObjectKey = Route.objectInfo.dicKey; LoadedAnimInfo.SelectedObject = Route.childRoot.gameObject; break; } IKObjectInfoList.Add(LoadedAnimInfo); } } Logger.Log(LogLevel.Debug, "Loaded KK_AnimationController animations"); } catch (Exception ex) { Logger.Log(LogLevel.Error | LogLevel.Message, "Could not load KK_AnimationController animations."); Logger.Log(LogLevel.Error, ex.ToString()); } } }