mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
UPGRADE NOTICE: Removed Init. Use OnEnable instead
OnEnable is a built-in event in Unity, and as such you don't need to override anything. Simply replace 'protected override void Init()' with 'private void OnEnable()'. You can use any access modifier.
This commit is contained in:
parent
d7f5bd2a1a
commit
9e7e7c4c9b
@ -34,6 +34,25 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
private Func<bool> _isDocked;
|
private Func<bool> _isDocked;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method is called automatically on script reload, and ensures that
|
||||||
|
/// all static ports in all nodes match their Node's class' port attributes
|
||||||
|
/// </summary>
|
||||||
|
[InitializeOnLoadMethod]
|
||||||
|
private static void UpdateAllStaticNodePorts() {
|
||||||
|
// Find all Graphs in the project
|
||||||
|
string[] guids = AssetDatabase.FindAssets("t:" + typeof(XNode.NodeGraph).Name);
|
||||||
|
for (int i = 0; i < guids.Length; i++) {
|
||||||
|
string assetpath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||||
|
UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetpath);
|
||||||
|
// Loop through graph asset and search for nodes (nodes exist inside the graph asset as sub-assets)
|
||||||
|
for (int k = 0; k < objs.Length; k++) {
|
||||||
|
XNode.Node node = objs[k] as XNode.Node;
|
||||||
|
if (node != null) node.UpdateStaticPorts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Type[] GetNodeTypes() {
|
public static Type[] GetNodeTypes() {
|
||||||
//Get all classes deriving from Node via reflection
|
//Get all classes deriving from Node via reflection
|
||||||
return GetDerivedTypes(typeof(XNode.Node));
|
return GetDerivedTypes(typeof(XNode.Node));
|
||||||
|
|||||||
@ -5,9 +5,8 @@ using XNode;
|
|||||||
|
|
||||||
public class #SCRIPTNAME# : Node {
|
public class #SCRIPTNAME# : Node {
|
||||||
|
|
||||||
// Use this for initialization
|
// Use OnEnable for initialization
|
||||||
protected override void Init() {
|
private void OnEnable() {
|
||||||
base.Init();
|
|
||||||
#NOTRIM#
|
#NOTRIM#
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -114,11 +114,9 @@ namespace XNode {
|
|||||||
/// <summary> Used during node instantiation to fix null/misconfigured graph during OnEnable/Init. Set it before instantiating a node. Will automatically be unset during OnEnable </summary>
|
/// <summary> Used during node instantiation to fix null/misconfigured graph during OnEnable/Init. Set it before instantiating a node. Will automatically be unset during OnEnable </summary>
|
||||||
public static NodeGraph graphHotfix;
|
public static NodeGraph graphHotfix;
|
||||||
|
|
||||||
protected void OnEnable() {
|
private void Awake() {
|
||||||
if (graphHotfix != null) graph = graphHotfix;
|
if (graphHotfix != null) graph = graphHotfix;
|
||||||
graphHotfix = null;
|
graphHotfix = null;
|
||||||
UpdateStaticPorts();
|
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Update static ports to reflect class fields. This happens automatically on enable. </summary>
|
/// <summary> Update static ports to reflect class fields. This happens automatically on enable. </summary>
|
||||||
@ -126,9 +124,6 @@ namespace XNode {
|
|||||||
NodeDataCache.UpdatePorts(this, ports);
|
NodeDataCache.UpdatePorts(this, ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Initialize node. Called on enable. </summary>
|
|
||||||
protected virtual void Init() { }
|
|
||||||
|
|
||||||
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||||
public void VerifyConnections() {
|
public void VerifyConnections() {
|
||||||
foreach (NodePort port in Ports) port.VerifyConnections();
|
foreach (NodePort port in Ports) port.VerifyConnections();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user