Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions Editor/Code/CSharpPreviewWindow/CSharpPreviewWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,54 @@ public static void Open()
window = win;
}

private IGraph SelectedGraph;

private void OnEnable()
{
window = this;
Selection.selectionChanged += OnSelectionChanged;
OnSelectionChanged();
UpdateCodeDisplay();

GraphWindow.activeContextChanged += ActiveContextChanged;

var activeContext = GraphWindow.activeContext;
if (activeContext != null)
{
ActiveContextChanged(activeContext);
}
}

private void OnDisable()
{
Selection.selectionChanged -= OnSelectionChanged;
if (SelectedGraph != null)
{
SelectedGraph.elements.CollectionChanged -= WatchElements;
}
GraphWindow.activeContextChanged -= ActiveContextChanged;
}

private void ActiveContextChanged(IGraphContext context)
{
if (context == null) return;

if (SelectedGraph != null)
{
SelectedGraph.elements.CollectionChanged -= WatchElements;
}

SelectedGraph = context.graph;

SelectedGraph.elements.CollectionChanged += WatchElements;
}

private void WatchElements()
{
if (!Serialization.isSerializing)
RefreshPreview();
else
EditorApplication.delayCall += () => RefreshPreview();
}

private void OnSelectionChanged()
Expand Down
20 changes: 16 additions & 4 deletions Editor/Code/Descriptors/Nodes/AssetFieldUnitDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,34 @@ public AssetFieldUnitDescriptor(AssetFieldUnit target) : base(target)

protected override string DefinedSurtitle()
{
return target.field.parentAsset.title;
if (target.field)
return target.field.parentAsset.title;
else
return base.DefinedSurtitle();
}

protected override EditorTexture DefinedIcon()
{
return target.field.type.Icon();
if (target.field)
return target.field.type.Icon();
else
return BoltCore.Icons.errorState;
}

protected override string DefinedTitle()
{
return target.field.parentAsset.title + "." + target.field.FieldName;
if (target.field)
return target.field.parentAsset.title + "." + target.field.FieldName;
else
return "No Field Assigned";
}

protected override string DefinedShortTitle()
{
return target.field.FieldName;
if (target.field)
return target.field.FieldName;
else
return base.DefinedShortTitle();
}
}

Expand Down
8 changes: 7 additions & 1 deletion Editor/Code/Editors/ClassAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UnityObject = UnityEngine.Object;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEngine.Assemblies;

namespace Unity.VisualScripting.Community.CSharp
{
Expand Down Expand Up @@ -45,7 +46,12 @@ protected override void OnExtendedVerticalHeaderGUI()

private void GetAllInheritableTypes()
{
inheritTypes ??= AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(t =>
#if UNITY_6000_4_OR_NEWER
Assembly[] assemblies = CurrentAssemblies.GetLoadedAssemblies().ToArray();
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
#endif
inheritTypes ??= assemblies.SelectMany(a => a.GetTypes()).Where(t =>
t.Is().Inheritable() &&
!NameUtility.TypeHasSpecialName(t)
).ToArray();
Expand Down
5 changes: 5 additions & 0 deletions Editor/Code/Editors/DelegateAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Unity.VisualScripting.Community.Libraries.CSharp;
using System.Linq;
using System.Reflection;
using UnityEngine.Assemblies;

namespace Unity.VisualScripting.Community.CSharp
{
Expand Down Expand Up @@ -40,7 +41,11 @@ static Type[] BuildDelegateTypeCache()
{
List<Type> list = new List<Type>();

#if UNITY_6000_4_OR_NEWER
Assembly[] assemblies = CurrentAssemblies.GetLoadedAssemblies().ToArray();
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
#endif

for (int a = 0; a < assemblies.Length; a++)
{
Expand Down
9 changes: 8 additions & 1 deletion Editor/Code/Editors/InterfaceAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ParameterModifier = Unity.VisualScripting.Community.Libraries.CSharp.ParameterModifier;
using System;
using System.Collections;
using UnityEngine.Assemblies;

namespace Unity.VisualScripting.Community.CSharp
{
Expand Down Expand Up @@ -43,7 +44,13 @@ protected override void OnEnable()
}
shouldUpdate = true;

allTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes()).ToArray();
#if UNITY_6000_4_OR_NEWER
Assembly[] assemblies = CurrentAssemblies.GetLoadedAssemblies().ToArray();
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
#endif

allTypes = assemblies.SelectMany(assembly => assembly.GetTypes()).ToArray();

CacheConstrainedAttributes();
}
Expand Down
11 changes: 9 additions & 2 deletions Editor/Code/Editors/MemberTypeAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Unity.VisualScripting.Community.Utility;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assemblies;
using ParameterModifier = Unity.VisualScripting.Community.Libraries.CSharp.ParameterModifier;

namespace Unity.VisualScripting.Community.CSharp
Expand All @@ -19,7 +20,7 @@ public abstract class MemberTypeAssetEditor<TMemberTypeAsset, TMemberTypeGenerat
where TMethodDeclaration : MethodDeclaration
where TConstructorDeclaration : ConstructorDeclaration
{

[NonSerialized]
public Dictionary<string, object> AttributeParameters;

protected Metadata attributes;
Expand Down Expand Up @@ -712,7 +713,13 @@ protected override void OnEnable()

if (Target.icon == null) Target.icon = DefaultIcon();

allTypes = AppDomain.CurrentDomain.GetAssemblies()
#if UNITY_6000_4_OR_NEWER
Assembly[] assemblies = CurrentAssemblies.GetLoadedAssemblies().ToArray();
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
#endif

allTypes = assemblies
.SelectMany(assembly => assembly.GetTypes()).ToArray();

CacheConstrainedAttributes();
Expand Down
13 changes: 6 additions & 7 deletions Editor/Code/Generators/BaseGraphGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private void GenerateEventMethods(ClassGenerator @class)
if (i != 0) writer.NewLine();
WriteMethodBody(unit, data, inner);
}
});
}).NewLine();
}

if (focusFalseUnits.Count > 0)
Expand All @@ -452,7 +452,7 @@ private void GenerateEventMethods(ClassGenerator @class)
if (i != 0) writer.NewLine();
WriteMethodBody(unit, data, inner);
}
});
}).NewLine();
}
});

Expand All @@ -478,7 +478,7 @@ private void GenerateEventMethods(ClassGenerator @class)
if (i != 0) writer.NewLine();
WriteMethodBody(unit, data, inner);
}
});
}).NewLine();
}

if (pauseFalseUnits.Count > 0)
Expand All @@ -493,7 +493,7 @@ private void GenerateEventMethods(ClassGenerator @class)
if (i != 0) writer.NewLine();
WriteMethodBody(unit, data, inner);
}
});
}).NewLine();
}
});

Expand Down Expand Up @@ -553,7 +553,6 @@ Unit is OnApplicationResume ||
specialUnitCode = GenerateSpecialUnitCode(@class, false);
}
#endif

if (isCoroutine)
{
string coroutineMethodName = GetMethodName(unit, true);
Expand Down Expand Up @@ -588,7 +587,7 @@ Unit is OnApplicationResume ||

if (!methodBodies.TryGetValue(unityMethodName, out var unityMethod))
{
unityMethod = MethodGenerator.Method(AccessModifier.Private, MethodModifier.None, typeof(void), unityMethodName);
unityMethod = MethodGenerator.Method(generator?.AccessModifier ?? AccessModifier.Private, MethodModifier.None, typeof(void), unityMethodName);
unityMethod.SetOwner(Unit);
if (Unit is BoltNamedAnimationEvent || Unit is BoltAnimationEvent || Unit is BoltUnityEvent)
{
Expand Down Expand Up @@ -656,7 +655,7 @@ Unit is OnApplicationResume ||

if (!methodBodies.TryGetValue(unityMethodName, out var method))
{
method = MethodGenerator.Method(AccessModifier.Private, MethodModifier.None, typeof(void), unityMethodName);
method = MethodGenerator.Method(generator?.AccessModifier ?? AccessModifier.Private, MethodModifier.None, typeof(void), unityMethodName);
method.SetOwner(Unit);
if (Unit is BoltNamedAnimationEvent || Unit is BoltAnimationEvent || Unit is BoltUnityEvent)
{
Expand Down
1 change: 0 additions & 1 deletion Editor/Code/Generators/GameObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Unity.VisualScripting.Community.CSharp
{
[Serializable]
[CodeGenerator(typeof(GameObject))]
public sealed class GameObjectGenerator : BaseGraphGenerator<GameObject>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using Unity.VisualScripting;
using System;
using Unity.VisualScripting.Community.Libraries.CSharp;

namespace Unity.VisualScripting.Community.CSharp
{
[NodeGenerator(typeof(AddListItem))]
Expand Down
14 changes: 8 additions & 6 deletions Editor/Code/Generators/Nodes/Control/CooldownGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ protected override void GenerateControlInternal(ControlInput input, ControlGener
return;
}

if (input == Unit.reset)
{
writer.WriteIndented();
writer.InvokeMember(variableName.VariableHighlight(), "ResetCooldown");
writer.WriteEnd(EndWriteOptions.LineEnd);
return;
}

if (!data.scopeGeneratorData.TryGetValue(Unit.enter, out _))
{
data.scopeGeneratorData.Add(Unit.enter, true);
Expand All @@ -66,12 +74,6 @@ protected override void GenerateControlInternal(ControlInput input, ControlGener
writer.Action(() => GenerateValue(Unit.unscaledTime, data, writer)));
writer.WriteEnd(EndWriteOptions.LineEnd);
}
else if (input == Unit.reset)
{
writer.WriteIndented();
writer.InvokeMember(variableName.VariableHighlight(), "ResetCooldown");
writer.WriteEnd(EndWriteOptions.LineEnd);
}

GenerateActionMethod(Unit.exitReady, data, writer);
GenerateActionMethod(Unit.exitNotReady, data, writer);
Expand Down
Loading