Skip to content

Commit 24ff872

Browse files
committed
Added link to scene API and fixed object field scene references
1 parent 905fb75 commit 24ff872

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

Assets/Examples/GraphBehaviour.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ public class GraphBehaviour : MonoBehaviour
66
{
77
public BaseGraph graph;
88

9-
void Start()
9+
protected virtual void OnEnable()
1010
{
1111
if (graph == null)
1212
graph = ScriptableObject.CreateInstance<BaseGraph>();
13+
14+
graph.LinkToScene(gameObject.scene);
1315
}
1416
}

Assets/com.alelievr.NodeGraphProcessor/Editor/BaseGraphWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public void InitializeGraph(BaseGraph graph)
9898
AssetDatabase.SaveAssets();
9999
// Unload the graph
100100
graphUnloaded?.Invoke(this.graph);
101-
102-
if(this.graph.name != "") // Only if it has a file name (GraphBehaviour graphs doesn't have one). This is a temporary solution.
101+
102+
if (!this.graph.IsLinkedToScene())
103103
Resources.UnloadAsset(this.graph);
104104
}
105105

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseNodeView.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,13 @@ protected VisualElement AddControlField(FieldInfo field, string label = null, bo
709709
UpdateOtherFieldValue(field, newValue);
710710
}, showInputDrawer ? "" : label);
711711

712-
/*if(owner.graph.name != "")
712+
// Disallow picking scene objects when the graph is not linked to a scene
713+
if (!owner.graph.IsLinkedToScene())
713714
{
714-
// TODO: Scene Graph vs Asset Graph distinction for scene picking
715-
// If this is a graph file
716715
var objectField = element.Q<ObjectField>();
717-
// Check field is an ObjectField
718-
if(objectField != null)
719-
// Disallow picking scene objects
716+
if (objectField != null)
720717
objectField.allowSceneObjects = false;
721-
}*/
718+
}
722719

723720
if (!fieldControlsMap.TryGetValue(field, out var inputFieldList))
724721
inputFieldList = fieldControlsMap[field] = new List<VisualElement>();

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/ExposedParameterFieldFactory.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ public VisualElement GetParameterValueField(ExposedParameter parameter, Action<o
6767
oldParameterValues[parameter] = parameter.value;
6868
}));
6969

70-
/*if(this.graph.name != "")
70+
// Disallow picking scene objects when the graph is not linked to a scene
71+
if (!this.graph.IsLinkedToScene())
7172
{
72-
// TODO: Scene Inspector vs Asset Inspector distinction for scene picking
73-
// If this is a graph file
74-
var objectField = view.Q<ObjectField>();
75-
// Check field is an ObjectField
76-
if(objectField != null)
77-
// Disallow picking scene objects
78-
objectField.allowSceneObjects = false;
79-
}*/
73+
var objectField = view.Q<ObjectField>();
74+
if (objectField != null)
75+
objectField.allowSceneObjects = false;
76+
}
8077
return view;
8178
}
8279

Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using System;
66
using UnityEngine.Serialization;
7+
using UnityEngine.SceneManagement;
78

89
namespace GraphProcessor
910
{
@@ -123,6 +124,9 @@ public class BaseGraph : ScriptableObject, ISerializationCallbackReceiver
123124
[System.NonSerialized]
124125
Dictionary< BaseNode, int > computeOrderDictionary = new Dictionary< BaseNode, int >();
125126

127+
[NonSerialized]
128+
Scene linkedScene;
129+
126130
//graph visual properties
127131
public Vector3 position = Vector3.zero;
128132
public Vector3 scale = Vector3.one;
@@ -676,6 +680,15 @@ public bool SetParameterValue(string name, object value)
676680
/// <returns>value</returns>
677681
public T GetParameterValue< T >(string name) => (T)GetParameterValue(name);
678682

683+
/// <summary>
684+
/// Link the current graph to the scene in parameter, allowing the graph to pick and serialize objects from the scene.
685+
/// </summary>
686+
/// <param name="scene">Target scene to link</param>
687+
public void LinkToScene(Scene scene)
688+
=> linkedScene = scene;
689+
690+
public bool IsLinkedToScene() => linkedScene.IsValid();
691+
679692
HashSet<BaseNode> infiniteLoopTracker = new HashSet<BaseNode>();
680693
int UpdateComputeOrderBreadthFirst(int depth, BaseNode node)
681694
{

0 commit comments

Comments
 (0)