Showing 402 changed files with 315 additions and 27,637 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Documentation~/recipes-sample.md
Expand Up @@ -551,7 +551,7 @@ public class TemperatureAndTimePart : BaseModelUIPart
base.PostBuildPartUI();

var stylesheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(
"Packages/com.unity.graphtools.foundation/Samples/Recipes/Editor/UI/Stylesheets/BakeNodePart.uss");
"Assets/MarcosPereira/TerrainGraph/GraphToolsFoundation/Samples/Recipes/Editor/UI/Stylesheets/BakeNodePart.uss");

if (stylesheet != null)
{
Expand Down
Expand Up @@ -9,13 +9,21 @@ static string[] OnWillSaveAssets(string[] paths)
{
foreach (var path in paths)
{
// Ignore scene assets, which would throw exception
// "Do not use ReadObjectThreaded on scene objects!"
if (typeof(SceneAsset) == AssetDatabase.GetMainAssetTypeAtPath(path))
{
continue;
}

var assets = AssetDatabase.LoadAllAssetsAtPath(path);

foreach (var graphAssetModel in assets.OfType<IGraphAssetModel>())
{
graphAssetModel.Dirty = false;
}
}

return paths;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorCommon/Utility/AssetHelper.cs
Expand Up @@ -2,6 +2,6 @@ namespace UnityEditor.GraphToolsFoundation.Overdrive
{
static class AssetHelper
{
internal const string AssetPath = "Packages/com.unity.graphtools.foundation/Editor/";
internal const string AssetPath = "Assets/MarcosPereira/TerrainGraph/GraphToolsFoundation/Editor/";
}
}
@@ -0,0 +1,84 @@
using System;
using UnityEngine.UIElements;

namespace UnityEditor.GraphToolsFoundation.Overdrive
{
/// <summary>
/// A part to build the UI for the variable properties.
/// </summary>
public class BlackboardVariablePropertiesPart : BaseModelUIPart
{
public static readonly string ussClassName = "ge-blackboard-variable-properties-part";

public static readonly string blackboardVariablePropertiesPartCreationContext = nameof(BlackboardVariablePropertiesPart);

/// <summary>
/// Creates a new instance of the <see cref="BlackboardVariablePropertiesPart"/> class.
/// </summary>
/// <param name="name">The name of the part.</param>
/// <param name="model">The model displayed in this part.</param>
/// <param name="ownerElement">The owner of the part.</param>
/// <param name="parentClassName">The class name of the parent.</param>
/// <returns>A new instance of <see cref="BlackboardVariablePropertiesPart"/>.</returns>
public static BlackboardVariablePropertiesPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
{
if (model is IVariableDeclarationModel)
{
return new BlackboardVariablePropertiesPart(name, model, ownerElement, parentClassName);
}

return null;
}

protected GraphElement m_VariablePropertiesView;

/// <inheritdoc />
public override VisualElement Root => m_VariablePropertiesView;

/// <summary>
/// Initializes a new instance of the <see cref="BlackboardVariablePropertiesPart"/> class.
/// </summary>
/// <param name="name">The name of the part.</param>
/// <param name="model">The model displayed in this part.</param>
/// <param name="ownerElement">The owner of the part.</param>
/// <param name="parentClassName">The class name of the parent.</param>
protected BlackboardVariablePropertiesPart(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
: base(name, model, ownerElement, parentClassName) { }

/// <inheritdoc />
protected override void BuildPartUI(VisualElement parent)
{
m_VariablePropertiesView = GraphElementFactory.CreateUI<GraphElement>(m_OwnerElement.View,
m_OwnerElement.CommandDispatcher, m_Model, blackboardVariablePropertiesPartCreationContext);
m_VariablePropertiesView.AddToClassList(ussClassName);
m_VariablePropertiesView.AddToClassList(m_ParentClassName.WithUssElement(PartName));

m_VariablePropertiesView.AddToView(m_OwnerElement.View);

if (parent is BlackboardRow row)
row.PropertiesSlot.Add(m_VariablePropertiesView);
else
parent.Add(m_VariablePropertiesView);
}

/// <inheritdoc />
protected override void UpdatePartFromModel()
{
m_VariablePropertiesView.UpdateFromModel();
}

/// <inheritdoc />
protected override void PartOwnerAddedToView()
{
m_VariablePropertiesView.AddToView(m_OwnerElement.View);
base.PartOwnerAddedToView();
}

/// <inheritdoc />
protected override void PartOwnerRemovedFromView()
{
m_VariablePropertiesView.RemoveFromView();
base.PartOwnerRemovedFromView();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Editor/GraphElements/ModelUI/GraphElement.cs
@@ -1,4 +1,5 @@
using System;
#pragma warning disable // Prevent warnings from showing in console. This is not our code.

using UnityEditor.GraphToolsFoundation.Overdrive.Bridge;
using UnityEngine;
using UnityEngine.UIElements;
Expand Down
Expand Up @@ -48,8 +48,9 @@ protected IconTitleProgressPart(string name, IGraphElementModel model, IModelUI
{
if (model.IsCollapsible())
{
var collapseButtonPart = NodeCollapseButtonPart.Create(collapseButtonPartName, model, ownerElement, ussClassName);
PartList.AppendPart(collapseButtonPart);
// Commented out - we do not want the collapse buton.
// var collapseButtonPart = NodeCollapseButtonPart.Create(collapseButtonPartName, model, ownerElement, ussClassName);
// PartList.AppendPart(collapseButtonPart);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Editor/GraphElements/ModelUI/Port.cs
@@ -1,3 +1,5 @@
#pragma warning disable // Prevent warnings from showing in console. This is not our code.

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
9 changes: 8 additions & 1 deletion Editor/GraphElements/Shortcuts/ShortcutEventBase.cs
Expand Up @@ -51,7 +51,14 @@ public static ShortcutEventBase<T> GetPooled(ShortcutStage stage)
protected override void Init()
{
base.Init();
MousePosition = GraphViewStaticBridge.GetMousePosition();

// Commented out, was causing exception:
// MissingMethodException: UnityEngine.Vector2
// UnityEngine.UIElements.PointerDeviceState.GetPointerPosition(int)
// UnityEditor.GraphToolsFoundation.Overdrive.ShortcutEventBase`1[T].Init ()
//
// MousePosition = GraphViewStaticBridge.GetMousePosition();

this.SetEventPropagationToNormal();
}

Expand Down
8 changes: 7 additions & 1 deletion Editor/GraphElements/Views/GraphView.cs
Expand Up @@ -1775,15 +1775,21 @@ void RebuildAll(GraphToolState state)
}

int index = 0;
bool needRepair = false;
foreach (var edge in graphModel.EdgeModels)
{
if (!CreateEdgeUI(edge))
{
Debug.LogWarning($"Edge {index} cannot be restored: {edge}");
Debug.LogWarning($"Edge {index} cannot be restored: {edge}. Repairing model...");
needRepair = true;
}
index++;
}

if (needRepair) {
graphModel.Repair();
}

var placemats = new List<GraphElement>();
foreach (var placematModel in state.GraphViewState.GraphModel.GetSortedPlacematModels())
{
Expand Down
39 changes: 22 additions & 17 deletions Editor/GraphElements/Windows/GraphViewEditorWindow.cs
Expand Up @@ -436,23 +436,28 @@ void OnLockStateChanged(bool locked)
// we want more granular control and register it manually
void OnGlobalSelectionChange()
{
// if we're in Locked mode, keep current selection
if (Locked)
return;

foreach (var onboardingProvider in m_BlankPage?.OnboardingProviders ?? Enumerable.Empty<OnboardingProvider>())
{
if (onboardingProvider.GetGraphAndObjectFromSelection(CommandDispatcher, Selection.activeObject, out var graphAssetModel, out var boundObject))
{
SetCurrentSelection(graphAssetModel, OpenMode.Open, boundObject);
return;
}
}

if (Selection.activeObject is IGraphAssetModel graph && CanHandleAssetType(graph))
{
SetCurrentSelection(graph, OpenMode.Open);
}
// Edit: Do not change graph when selecting different asset.
// We want to close the terrain graph editor window before switching
// graphs due to how previews are refreshed with an async task.
// Switching graphs with an existing window causes an exception.

// // if we're in Locked mode, keep current selection
// if (Locked)
// return;

// foreach (var onboardingProvider in m_BlankPage?.OnboardingProviders ?? Enumerable.Empty<OnboardingProvider>())
// {
// if (onboardingProvider.GetGraphAndObjectFromSelection(CommandDispatcher, Selection.activeObject, out var graphAssetModel, out var boundObject))
// {
// SetCurrentSelection(graphAssetModel, OpenMode.Open, boundObject);
// return;
// }
// }

// if (Selection.activeObject is IGraphAssetModel graph && CanHandleAssetType(graph))
// {
// SetCurrentSelection(graph, OpenMode.Open);
// }
}

public void SetCurrentSelection(IGraphAssetModel graphAssetModel, OpenMode mode, GameObject boundObject = null)
Expand Down
9 changes: 9 additions & 0 deletions Editor/InternalBridge/GraphViewStaticBridge.cs
Expand Up @@ -240,7 +240,9 @@ public static void SetNextVertex(this MeshWriteData md, Vector3 pos, Vector2 uv,
Color32 flags = new Color32((byte)VertexFlags.IsGraphViewEdge, 0, 0, 0);
md.SetNextVertex(new Vertex() { position = pos, uv = uv, tint = tint, ids = ids, flags = flags });
#else
#pragma warning disable CS0618 // obsolete warning
Color32 flags = new Color32(0, 0, 0, (byte)VertexFlags.LastType);
#pragma warning restore
md.SetNextVertex(new Vertex() { position = pos, uv = uv, tint = tint, idsFlags = flags });
#endif
}
Expand Down Expand Up @@ -287,7 +289,14 @@ internal static void ChangeMouseCursorTo(this VisualElement ve, int internalCurs

public static Vector2 GetMousePosition()
{
#if UNITY_2021_1_OR_NEWER
return PointerDeviceState.GetPointerPosition(
PointerId.mousePointerId,
contextType: ContextType.Editor
);
#else
return PointerDeviceState.GetPointerPosition(PointerId.mousePointerId);
#endif
}

public static void SetEventPropagationToNormal(this EventBase e)
Expand Down
1 change: 1 addition & 0 deletions Editor/InternalBridge/InternalBridge.asmdef
@@ -1,5 +1,6 @@
{
"name": "Unity.InternalAPIEngineBridge.015",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
Expand Down
8 changes: 8 additions & 0 deletions Editor/Model/BasicModel/ConstantNodeModel.cs
Expand Up @@ -55,13 +55,21 @@ public bool IsLocked
/// <returns>A clone of this instance.</returns>
public ConstantNodeModel Clone()
{
#if UNITY_EDITOR

if (GetType() == typeof(ConstantNodeModel))
{
return new ConstantNodeModel { Value = Value.CloneConstant() };
}
var clone = Activator.CreateInstance(GetType());
EditorUtility.CopySerializedManagedFieldsOnly(this, clone);
return (ConstantNodeModel)clone;

#else

throw new Exception("Unavailable outside editor.");

#endif
}

/// <inheritdoc />
Expand Down
7 changes: 5 additions & 2 deletions Editor/Model/BasicModel/EdgeModel.cs
Expand Up @@ -126,8 +126,11 @@ public virtual void SetPorts(IPortModel toPortModel, IPortModel fromPortModel)
FromPort = fromPortModel;
ToPort = toPortModel;

toPortModel.NodeModel.OnConnection(toPortModel, fromPortModel);
fromPortModel.NodeModel.OnConnection(fromPortModel, toPortModel);
// Marcos: Made it so event is only triggered after edges have been
// updated.
//
// toPortModel.NodeModel.OnConnection(toPortModel, fromPortModel);
// fromPortModel.NodeModel.OnConnection(fromPortModel, toPortModel);
}

/// <inheritdoc />
Expand Down
10 changes: 10 additions & 0 deletions Editor/Model/BasicModel/GraphModel.cs
Expand Up @@ -72,11 +72,15 @@ public Type StencilType
get => m_StencilType;
set
{
#if UNITY_EDITOR
if (value == null)
value = DefaultStencilType;

Assert.IsTrue(typeof(IStencil).IsAssignableFrom(value));

m_StencilType = value;
Stencil = InstantiateStencil(StencilType);
#endif
}
}

Expand Down Expand Up @@ -645,6 +649,12 @@ public IEdgeModel CreateEdge(IPortModel toPort, IPortModel fromPort, Serializabl

var edgeModel = InstantiateEdge(toPort, fromPort, guid);
AddEdge(edgeModel);

// Marcos: Made it so event is only triggered after edges have been
// updated.
toPort.NodeModel.OnConnection(toPort, fromPort);
fromPort.NodeModel.OnConnection(fromPort, toPort);

return edgeModel;
}

Expand Down