Repository navigation
Expand file tree
/
Copy pathEditorViewState.cs
More file actions
51 lines (47 loc) · 1.56 KB
/
Copy pathEditorViewState.cs
File metadata and controls
51 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace UtilityAI {
[Serializable]
public class EditorViewState {
[Serializable]
struct NodeState {
public ScriptableObject ownedScriptableObject;
public Vector2 position;
}
[SerializeField]
[FormerlySerializedAs("states")]
List<NodeState> nodeStates;
public bool TryGet(ScriptableObject obj, out Vector2 pos) {
if (nodeStates != null) {
for (int i = 0; i < nodeStates.Count; ++i) {
var state = nodeStates[i];
if (state.ownedScriptableObject == obj) {
pos = state.position;
return true;
}
}
}
pos = Vector2.zero;
return false;
}
public void Set(ScriptableObject obj, Vector2 pos) {
if (nodeStates == null) {
nodeStates = new List<NodeState>();
}
for (int i = 0; i < nodeStates.Count; ++i) {
var state = nodeStates[i];
if (state.ownedScriptableObject == obj) {
state.position = pos;
nodeStates[i] = state;
return;
}
}
nodeStates.Add(new NodeState() {
ownedScriptableObject = obj,
position = pos
});
}
}
}