private static void OCIItem_OnDelete(OCIItem __instance) { var controller = MEStudio.GetSceneController(); if (controller != null) { controller.ItemDeleteEvent(__instance.objectInfo.dicKey); } }
private static void OCIItem_Visible(OCIItem __instance, bool value) { var controller = MEStudio.GetSceneController(); if (controller != null) { controller.ItemVisibleEvent(__instance.objectInfo.dicKey, value); } }
private static void WorkspaceCtrl_OnSelectSingle() { if (!MaterialEditorUI.Visible) { return; } var controller = MEStudio.GetSceneController(); if (controller == null) { return; } MEStudio.Instance.UpdateUI(); }
private void Start() { Instance = this; SceneManager.sceneLoaded += (s, lsm) => InitStudioUI(s.name); StudioSaveLoadApi.RegisterExtraBehaviour <SceneController>(MaterialEditorPlugin.PluginGUID); }
internal static void OCIItemOnDelete(OCIItem __instance) => MEStudio.GetSceneController()?.ItemDeleteEvent(__instance.objectInfo.dicKey);
internal static void OCIItemVisible(OCIItem __instance, bool value) => MEStudio.GetSceneController()?.ItemVisibleEvent(__instance.objectInfo.dicKey, value);
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(); MaterialShaderList.Clear(); TextureDictionary.Clear(); } if (data == null) { return; } if (operation == SceneOperationKind.Clear) { 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).ToDictionary(pair => pair.Key, pair => new TextureContainer(pair.Value)); } } if (operation == SceneOperationKind.Import) { if (data.data.TryGetValue(nameof(TextureDictionary), out var texDic) && texDic != null) { foreach (var x in MessagePackSerializer.Deserialize <Dictionary <int, byte[]> >((byte[])texDic)) { importDictionary[x.Key] = SetAndGetTextureID(x.Value); } } } if (data.data.TryGetValue(nameof(MaterialShaderList), out var shaderProperties) && shaderProperties != null) { foreach (var loadedProperty in MessagePackSerializer.Deserialize <List <MaterialShader> >((byte[])shaderProperties)) { if (loadedItems.TryGetValue(loadedProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { bool setShader = SetShader(ociItem.objectItem, loadedProperty.MaterialName, loadedProperty.ShaderName); bool setRenderQueue = SetRenderQueue(ociItem.objectItem, loadedProperty.MaterialName, loadedProperty.RenderQueue); if (setShader || setRenderQueue) { MaterialShaderList.Add(new MaterialShader(MEStudio.GetObjectID(objectCtrlInfo), loadedProperty.MaterialName, loadedProperty.ShaderName, loadedProperty.ShaderNameOriginal, loadedProperty.RenderQueue, loadedProperty.RenderQueueOriginal)); } } } } if (data.data.TryGetValue(nameof(RendererPropertyList), out var rendererProperties) && rendererProperties != null) { foreach (var loadedProperty in MessagePackSerializer.Deserialize <List <RendererProperty> >((byte[])rendererProperties)) { if (loadedItems.TryGetValue(loadedProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { if (SetRendererProperty(ociItem.objectItem, loadedProperty.RendererName, loadedProperty.Property, int.Parse(loadedProperty.Value))) { RendererPropertyList.Add(new RendererProperty(MEStudio.GetObjectID(objectCtrlInfo), loadedProperty.RendererName, loadedProperty.Property, loadedProperty.Value, loadedProperty.ValueOriginal)); } } } } if (data.data.TryGetValue(nameof(MaterialFloatPropertyList), out var materialFloatProperties) && materialFloatProperties != null) { foreach (var loadedProperty in MessagePackSerializer.Deserialize <List <MaterialFloatProperty> >((byte[])materialFloatProperties)) { if (loadedItems.TryGetValue(loadedProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { if (SetFloat(ociItem.objectItem, loadedProperty.MaterialName, loadedProperty.Property, loadedProperty.Value)) { MaterialFloatPropertyList.Add(new MaterialFloatProperty(MEStudio.GetObjectID(objectCtrlInfo), loadedProperty.MaterialName, loadedProperty.Property, loadedProperty.Value, loadedProperty.ValueOriginal)); } } } } if (data.data.TryGetValue(nameof(MaterialColorPropertyList), out var materialColorProperties) && materialColorProperties != null) { foreach (var loadedProperty in MessagePackSerializer.Deserialize <List <MaterialColorProperty> >((byte[])materialColorProperties)) { if (loadedItems.TryGetValue(loadedProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { if (SetColor(ociItem.objectItem, loadedProperty.MaterialName, loadedProperty.Property, loadedProperty.Value)) { MaterialColorPropertyList.Add(new MaterialColorProperty(MEStudio.GetObjectID(objectCtrlInfo), loadedProperty.MaterialName, loadedProperty.Property, loadedProperty.Value, loadedProperty.ValueOriginal)); } } } } if (data.data.TryGetValue(nameof(MaterialTexturePropertyList), out var materialTextureProperties) && materialTextureProperties != null) { foreach (var loadedProperty in MessagePackSerializer.Deserialize <List <MaterialTextureProperty> >((byte[])materialTextureProperties)) { if (loadedItems.TryGetValue(loadedProperty.ID, out ObjectCtrlInfo objectCtrlInfo) && objectCtrlInfo is OCIItem ociItem) { int?texID = null; if (operation == SceneOperationKind.Import) { if (loadedProperty.TexID != null) { texID = importDictionary[(int)loadedProperty.TexID]; } } else { texID = loadedProperty.TexID; } MaterialTextureProperty newTextureProperty = new MaterialTextureProperty(MEStudio.GetObjectID(objectCtrlInfo), loadedProperty.MaterialName, loadedProperty.Property, texID, loadedProperty.Offset, loadedProperty.OffsetOriginal, loadedProperty.Scale, loadedProperty.ScaleOriginal); bool setTex = false; if (newTextureProperty.TexID != null) { setTex = SetTexture(ociItem.objectItem, newTextureProperty.MaterialName, newTextureProperty.Property, newTextureProperty.Texture); } bool setOffset = SetTextureOffset(ociItem.objectItem, newTextureProperty.MaterialName, newTextureProperty.Property, newTextureProperty.Offset); bool setScale = SetTextureScale(ociItem.objectItem, newTextureProperty.MaterialName, newTextureProperty.Property, newTextureProperty.Scale); if (setTex || setOffset || setScale) { MaterialTexturePropertyList.Add(newTextureProperty); } } } } }