Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Editor/Editors/Elements/CodeViewElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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<VisualElement> makeItem = () => new LineItem();
Action<VisualElement, int> bindItem = (e, i) => (e as LineItem).SetText(i+1, _textLines[i], _digits);
Expand Down
32 changes: 18 additions & 14 deletions Editor/Editors/Elements/ModuleInspectorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ public void UpdateList()
_listContainer.text = _array.displayName;
CreateDrop();

_loadedModules = new List<string>();
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++)
Expand All @@ -145,16 +139,12 @@ public void UpdateList()
moduleItem.Add(objectField);
moduleItem.Add(infoLabel);

objectField.RegisterCallback<ChangeEvent<Object>>(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);
Expand All @@ -165,6 +155,9 @@ public void UpdateList()
CheckModuleValidity((ShaderModule)_array.GetArrayElementAtIndex(j).objectReferenceValue, label, element);
}
});

/*objectField.RegisterCallback<ChangeEvent<Object>>(x =>
);*/

var item = new InspectorListItem(this, moduleItem, _array, index, _showElementsButtons);
item.removeButton.RegisterCallback<PointerUpEvent>((evt) => RemoveItem(index));
Expand All @@ -179,6 +172,16 @@ public void UpdateList()
_listContainer.Add(_addButton);
}

private void ReloadLoadedModulesIds()
{
_loadedModules = new List<string>();
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();
Expand Down Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions Editor/Editors/Inspectors/ModularShaderEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
Expand Down
8 changes: 4 additions & 4 deletions Editor/Scriptables/TemplateAssetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor.Experimental.AssetImporters;

using UnityEngine;

namespace VRLabs.ModularShaderSystem
Expand All @@ -11,10 +11,10 @@ namespace VRLabs.ModularShaderSystem
/// <summary>
/// Scripted importer for the template asset
/// </summary>
[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<TemplateAsset>();
subAsset.Template = File.ReadAllText(ctx.assetPath);
Expand Down
10 changes: 5 additions & 5 deletions Editor/Scriptables/TemplateCollectionAssetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor.Experimental.AssetImporters;

using UnityEngine;

namespace VRLabs.ModularShaderSystem
{
/// <summary>
/// Scripted importer for the template collection.
/// </summary>
[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<TemplateCollectionAsset>();

Expand Down Expand Up @@ -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>();
templateAsset.Template = builder.ToString();
Expand Down