From 01b6c61a1b2aad22340815be487b35fd3339cac8 Mon Sep 17 00:00:00 2001 From: Cibbi <12004047+Cibbi@users.noreply.github.com> Date: Sun, 25 May 2025 21:52:10 +0200 Subject: [PATCH] Random ass ui fixes --- Editor/Editors/Elements/CodeViewElement.cs | 4 +-- .../Editors/Elements/ModuleInspectorList.cs | 32 +++++++++++-------- .../Editors/Inspectors/ModularShaderEditor.cs | 1 + Editor/Scriptables/TemplateAssetImporter.cs | 8 ++--- .../TemplateCollectionAssetImporter.cs | 10 +++--- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Editor/Editors/Elements/CodeViewElement.cs b/Editor/Editors/Elements/CodeViewElement.cs index 25fcb51..db2113f 100644 --- a/Editor/Editors/Elements/CodeViewElement.cs +++ b/Editor/Editors/Elements/CodeViewElement.cs @@ -68,7 +68,6 @@ public string Text _listView.itemsSource = _textLines; float width =((_textLines.Length == 0 ? 0 : _textLines.Max(x => x.Length)) + _digits + 1) * 10; - _listView.contentContainer.style.width = width; } } @@ -86,12 +85,11 @@ public CodeViewElement() { ScrollView s = new ScrollView(ScrollViewMode.Horizontal); _listView = new ListView(); - _listView.itemHeight = 15; + _listView.fixedItemHeight = 15; _listView.AddToClassList("unity-base-text-field__input"); _listView.AddToClassList("unity-text-field__input"); _listView.AddToClassList("unity-base-field__input"); _listView.style.flexGrow = 1; - _listView.contentContainer.style.flexGrow = 1; Func makeItem = () => new LineItem(); Action bindItem = (e, i) => (e as LineItem).SetText(i+1, _textLines[i], _digits); diff --git a/Editor/Editors/Elements/ModuleInspectorList.cs b/Editor/Editors/Elements/ModuleInspectorList.cs index 8be1fad..f338169 100644 --- a/Editor/Editors/Elements/ModuleInspectorList.cs +++ b/Editor/Editors/Elements/ModuleInspectorList.cs @@ -120,13 +120,7 @@ public void UpdateList() _listContainer.text = _array.displayName; CreateDrop(); - _loadedModules = new List(); - for (int i = 0; i < _array.arraySize; i++) - { - if (_array.GetArrayElementAtIndex(i).objectReferenceValue != null) - _loadedModules.Add(((ShaderModule)_array.GetArrayElementAtIndex(i).objectReferenceValue)?.Id); - } - + ReloadLoadedModulesIds(); for (int i = 0; i < _array.arraySize; i++) @@ -145,16 +139,12 @@ public void UpdateList() moduleItem.Add(objectField); moduleItem.Add(infoLabel); - objectField.RegisterCallback>(x => - { + objectField.RegisterValueChangedCallback(x => { var newValue = (ShaderModule)x.newValue; var oldValue = (ShaderModule)x.previousValue; - if (oldValue != null) - _loadedModules.Remove(oldValue.Id); - if (newValue != null) - _loadedModules.Add(newValue.Id); - + ReloadLoadedModulesIds(); + for (int j = 0; j < _array.arraySize; j++) { var element = ((ObjectField)x.target).parent.parent.parent.ElementAt(j*2+1).ElementAt(1); @@ -165,6 +155,9 @@ public void UpdateList() CheckModuleValidity((ShaderModule)_array.GetArrayElementAtIndex(j).objectReferenceValue, label, element); } }); + + /*objectField.RegisterCallback>(x => + );*/ var item = new InspectorListItem(this, moduleItem, _array, index, _showElementsButtons); item.removeButton.RegisterCallback((evt) => RemoveItem(index)); @@ -179,6 +172,16 @@ public void UpdateList() _listContainer.Add(_addButton); } + private void ReloadLoadedModulesIds() + { + _loadedModules = new List(); + for (int i = 0; i < _array.arraySize; i++) + { + if (_array.GetArrayElementAtIndex(i).objectReferenceValue != null) + _loadedModules.Add(((ShaderModule)_array.GetArrayElementAtIndex(i).objectReferenceValue)?.Id); + } + } + private void CreateDrop() { VisualElement dropArea = new VisualElement(); @@ -212,6 +215,7 @@ private void CheckModuleValidity(ShaderModule newValue, Label infoLabel, VisualE if (newValue != null) { var moduleId = newValue.Id; + if (_loadedModules.Count(y => y.Equals(moduleId)) > 1) problems.Add("The module is duplicate"); diff --git a/Editor/Editors/Inspectors/ModularShaderEditor.cs b/Editor/Editors/Inspectors/ModularShaderEditor.cs index 274f1a7..05d5bc9 100644 --- a/Editor/Editors/Inspectors/ModularShaderEditor.cs +++ b/Editor/Editors/Inspectors/ModularShaderEditor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; diff --git a/Editor/Scriptables/TemplateAssetImporter.cs b/Editor/Scriptables/TemplateAssetImporter.cs index 26c62eb..4687119 100644 --- a/Editor/Scriptables/TemplateAssetImporter.cs +++ b/Editor/Scriptables/TemplateAssetImporter.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; -using UnityEditor.Experimental.AssetImporters; + using UnityEngine; namespace VRLabs.ModularShaderSystem @@ -11,10 +11,10 @@ namespace VRLabs.ModularShaderSystem /// /// Scripted importer for the template asset /// - [ScriptedImporter(1, MSSConstants.TEMPLATE_EXTENSION)] - public class TemplateAssetImporter : ScriptedImporter + [UnityEditor.AssetImporters.ScriptedImporter(1, MSSConstants.TEMPLATE_EXTENSION)] + public class TemplateAssetImporter : UnityEditor.AssetImporters.ScriptedImporter { - public override void OnImportAsset(AssetImportContext ctx) + public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx) { var subAsset = ScriptableObject.CreateInstance(); subAsset.Template = File.ReadAllText(ctx.assetPath); diff --git a/Editor/Scriptables/TemplateCollectionAssetImporter.cs b/Editor/Scriptables/TemplateCollectionAssetImporter.cs index 9464671..e76f1c8 100644 --- a/Editor/Scriptables/TemplateCollectionAssetImporter.cs +++ b/Editor/Scriptables/TemplateCollectionAssetImporter.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using UnityEditor.Experimental.AssetImporters; + using UnityEngine; namespace VRLabs.ModularShaderSystem @@ -11,10 +11,10 @@ namespace VRLabs.ModularShaderSystem /// /// Scripted importer for the template collection. /// - [ScriptedImporter(1, MSSConstants.TEMPLATE_COLLECTION_EXTENSION)] - public class TemplateColletionAssetImporter : ScriptedImporter + [UnityEditor.AssetImporters.ScriptedImporter(1, MSSConstants.TEMPLATE_COLLECTION_EXTENSION)] + public class TemplateColletionAssetImporter : UnityEditor.AssetImporters.ScriptedImporter { - public override void OnImportAsset(AssetImportContext ctx) + public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx) { var subAsset = ScriptableObject.CreateInstance(); @@ -61,7 +61,7 @@ public override void OnImportAsset(AssetImportContext ctx) ctx.SetMainObject(subAsset); } - private static void SaveSubAsset(AssetImportContext ctx, TemplateCollectionAsset asset, StringBuilder builder, string name) + private static void SaveSubAsset(UnityEditor.AssetImporters.AssetImportContext ctx, TemplateCollectionAsset asset, StringBuilder builder, string name) { var templateAsset = ScriptableObject.CreateInstance(); templateAsset.Template = builder.ToString();