protected override void OnSceneLoad(SceneOperationKind operation, ReadOnlyDictionary <int, ObjectCtrlInfo> loadedItems) { var data = GetExtendedData(); if (operation == SceneOperationKind.Clear || operation == SceneOperationKind.Load) { RendererPropertyList.Clear(); MaterialFloatPropertyList.Clear(); MaterialColorPropertyList.Clear(); MaterialTexturePropertyList.Clear(); TextureDictionary.Clear(); } if (data == null) { return; } var importDictionary = new Dictionary <int, int>(); if (operation == SceneOperationKind.Load) { if (data.data.TryGetValue(nameof(TextureDictionary), out var texDic) && texDic != null) { TextureDictionary = MessagePackSerializer.Deserialize <Dictionary <int, byte[]> >((byte[])texDic); } } else if (operation == SceneOperationKind.Import) { if (data.data.TryGetValue(nameof(TextureDictionary), out var texDic) && texDic != null) { Dictionary <int, byte[]> importTextureDictionary = MessagePackSerializer.Deserialize <Dictionary <int, byte[]> >((byte[])texDic); foreach (var x in importTextureDictionary) { importDictionary[x.Key] = SetAndGetTextureID(x.Value); } } } else if (operation == SceneOperationKind.Clear) { return; } if (data.data.TryGetValue(nameof(RendererPropertyList), out var rendererProperties) && rendererProperties != null) { var loadedRendererProperties = MessagePackSerializer.Deserialize <List <RendererProperty> >((byte[])rendererProperties); foreach (var loadedRendererProperty in loadedRendererProperties) { if (loadedItems.TryGetValue(loadedRendererProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var renderer in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { if (renderer.NameFormatted() == loadedRendererProperty.RendererName) { RendererPropertyList.Add(new RendererProperty(GetObjectID(objectCtrlInfo), loadedRendererProperty.RendererName, loadedRendererProperty.Property, loadedRendererProperty.Value, loadedRendererProperty.ValueOriginal)); SetRendererProperty(renderer, loadedRendererProperty.Property, int.Parse(loadedRendererProperty.Value)); } } } } } if (data.data.TryGetValue(nameof(MaterialFloatPropertyList), out var materialFloatProperties) && materialFloatProperties != null) { var loadedMaterialFloatProperties = MessagePackSerializer.Deserialize <List <MaterialFloatProperty> >((byte[])materialFloatProperties); foreach (var loadedMaterialFloatProperty in loadedMaterialFloatProperties) { if (loadedItems.TryGetValue(loadedMaterialFloatProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var rend in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { foreach (var mat in rend.materials) { if (mat.NameFormatted() == loadedMaterialFloatProperty.MaterialName && mat.HasProperty($"_{loadedMaterialFloatProperty.Property}") && FloatProperties.Contains(loadedMaterialFloatProperty.Property)) { var valueOriginal = mat.GetFloat($"_{loadedMaterialFloatProperty.Property}").ToString(); MaterialFloatPropertyList.Add(new MaterialFloatProperty(GetObjectID(objectCtrlInfo), loadedMaterialFloatProperty.MaterialName, loadedMaterialFloatProperty.Property, loadedMaterialFloatProperty.Value, valueOriginal)); SetFloatProperty(ociItem.objectItem, mat, loadedMaterialFloatProperty.Property, loadedMaterialFloatProperty.Value, ObjectType.StudioItem); } } } } } } if (data.data.TryGetValue(nameof(MaterialColorPropertyList), out var materialColorProperties) && materialColorProperties != null) { var loadedMaterialColorProperties = MessagePackSerializer.Deserialize <List <MaterialColorProperty> >((byte[])materialColorProperties); foreach (var loadedMaterialColorProperty in loadedMaterialColorProperties) { if (loadedItems.TryGetValue(loadedMaterialColorProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var rend in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { foreach (var mat in rend.materials) { if (mat.NameFormatted() == loadedMaterialColorProperty.MaterialName && mat.HasProperty($"_{loadedMaterialColorProperty.Property}") && ColorProperties.Contains(loadedMaterialColorProperty.Property)) { var valueOriginal = mat.GetColor($"_{loadedMaterialColorProperty.Property}"); MaterialColorPropertyList.Add(new MaterialColorProperty(GetObjectID(objectCtrlInfo), loadedMaterialColorProperty.MaterialName, loadedMaterialColorProperty.Property, loadedMaterialColorProperty.Value, valueOriginal)); SetColorProperty(ociItem.objectItem, mat, loadedMaterialColorProperty.Property, loadedMaterialColorProperty.Value, ObjectType.StudioItem); } } } } } } if (data.data.TryGetValue(nameof(MaterialTexturePropertyList), out var materialTextureProperties) && materialTextureProperties != null) { var loadedMaterialTextureProperties = MessagePackSerializer.Deserialize <List <MaterialTextureProperty> >((byte[])materialTextureProperties); foreach (var loadedMaterialTextureProperty in loadedMaterialTextureProperties) { if (loadedItems.TryGetValue(loadedMaterialTextureProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var rend in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { foreach (var mat in rend.materials) { if (mat.NameFormatted() == loadedMaterialTextureProperty.MaterialName && mat.HasProperty($"_{loadedMaterialTextureProperty.Property}") && TextureProperties.Contains(loadedMaterialTextureProperty.Property)) { int texID = operation == SceneOperationKind.Import ? importDictionary[loadedMaterialTextureProperty.TexID] : loadedMaterialTextureProperty.TexID; MaterialTextureProperty newTextureProperty = new MaterialTextureProperty(GetObjectID(objectCtrlInfo), loadedMaterialTextureProperty.MaterialName, loadedMaterialTextureProperty.Property, texID); MaterialTexturePropertyList.Add(newTextureProperty); SetTextureProperty(ociItem.objectItem, mat, newTextureProperty.Property, newTextureProperty.Texture, ObjectType.StudioItem); } } } } } } }
protected override void OnSceneLoad(SceneOperationKind operation, ReadOnlyDictionary <int, ObjectCtrlInfo> loadedItems) { var data = GetExtendedData(); if (operation == SceneOperationKind.Clear || operation == SceneOperationKind.Load) { StudioItemRendererPropertyList.Clear(); StudioItemMaterialFloatPropertyList.Clear(); StudioItemMaterialColorPropertyList.Clear(); } if (data == null) { return; } if (data.data.TryGetValue("RendererProperties", out var rendererProperties) && rendererProperties != null) { var loadedRendererProperties = MessagePackSerializer.Deserialize <List <RendererProperty> >((byte[])rendererProperties); foreach (var loadedRendererProperty in loadedRendererProperties) { if (loadedItems.TryGetValue(loadedRendererProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var renderer in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { if (renderer.NameFormatted() == loadedRendererProperty.RendererName) { StudioItemRendererPropertyList.Add(new RendererProperty(GetObjectID(objectCtrlInfo), loadedRendererProperty.RendererName, loadedRendererProperty.Property, loadedRendererProperty.Value, loadedRendererProperty.ValueOriginal)); SetRendererProperty(renderer, loadedRendererProperty.Property, int.Parse(loadedRendererProperty.Value)); } } } } } if (data.data.TryGetValue("MaterialFloatProperties", out var materialFloatProperties) && materialFloatProperties != null) { var loadedMaterialFloatProperties = MessagePackSerializer.Deserialize <List <MaterialFloatProperty> >((byte[])materialFloatProperties); foreach (var loadedMaterialFloatProperty in loadedMaterialFloatProperties) { if (loadedItems.TryGetValue(loadedMaterialFloatProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var rend in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { foreach (var mat in rend.materials) { if (mat.HasProperty($"_{loadedMaterialFloatProperty.Property}") && FloatProperties.Contains(loadedMaterialFloatProperty.Property)) { var valueOriginal = mat.GetFloat($"_{loadedMaterialFloatProperty.Property}").ToString(); StudioItemMaterialFloatPropertyList.Add(new MaterialFloatProperty(GetObjectID(objectCtrlInfo), loadedMaterialFloatProperty.MaterialName, loadedMaterialFloatProperty.Property, loadedMaterialFloatProperty.Value, valueOriginal)); SetFloatProperty(ociItem.objectItem, mat, loadedMaterialFloatProperty.Property, loadedMaterialFloatProperty.Value); } } } } } } if (data.data.TryGetValue("MaterialColorProperties", out var materialColorProperties) && materialColorProperties != null) { var loadedMaterialColorProperties = MessagePackSerializer.Deserialize <List <MaterialColorProperty> >((byte[])materialColorProperties); foreach (var loadedMaterialColorProperty in loadedMaterialColorProperties) { if (loadedItems.TryGetValue(loadedMaterialColorProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { foreach (var rend in ociItem.objectItem.GetComponentsInChildren <Renderer>()) { foreach (var mat in rend.materials) { if (mat.HasProperty($"_{loadedMaterialColorProperty.Property}") && ColorProperties.Contains(loadedMaterialColorProperty.Property)) { var valueOriginal = mat.GetColor($"_{loadedMaterialColorProperty.Property}"); StudioItemMaterialColorPropertyList.Add(new MaterialColorProperty(GetObjectID(objectCtrlInfo), loadedMaterialColorProperty.MaterialName, loadedMaterialColorProperty.Property, loadedMaterialColorProperty.Value, valueOriginal)); SetColorProperty(ociItem.objectItem, mat, loadedMaterialColorProperty.Property, loadedMaterialColorProperty.Value); } } } } } } }