static public Node Create(Wiring.NodeBase runtimeInstance, Type renderer) { var node = CreateInstance(renderer) as Node; node.Initialize(runtimeInstance); return(node); }
// Factory method static public Node Create(Wiring.NodeBase runtimeInstance) { var node = CreateInstance <Node>(); node.Initialize(runtimeInstance); return(node); }
// Initializer (called from the Create method) void Initialize(Wiring.NodeBase runtimeInstance) { hideFlags = HideFlags.DontSave; // Object references _runtimeInstance = runtimeInstance; _serializedObject = new UnityEditor.SerializedObject(runtimeInstance); _serializedPosition = _serializedObject.FindProperty("_wiringNodePosition"); _varlets = _runtimeInstance.GetType() .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(o => o.GetCustomAttribute <VarletAttribute>() != null) .Select(o => _serializedObject.FindProperty(o.Name)) .ToArray(); // Basic information name = runtimeInstance.GetInstanceID().ToString(); position = new Rect(_serializedPosition.vector2Value, Vector2.zero); var nodeColor = runtimeInstance.GetType().GetCustomAttribute <NodeColor>(); if (nodeColor != null) { color = (Graphs.Styles.Color)nodeColor.color; } // Slot initialization PopulateSlots(); }
// Add a node instance to the patch. public void AddNodeInstance(Wiring.NodeBase nodeInstance) { // Append to the hierarchy. nodeInstance.transform.parent = _instance.transform; // Register to this patch representation. var node = new Node(nodeInstance); _nodeList.Add(node); _instanceIDToNodeMap.Add(nodeInstance.GetInstanceID(), node); }
// Constructor public Node(Wiring.NodeBase instance) { _instance = instance; _windowID = _windowCounter++; // Inlets and outlets _inlets = new List <Inlet>(); _outlets = new List <Outlet>(); InitializeInletsAndOutlets(); // Window position _serializedObject = new UnityEditor.SerializedObject(_instance); _serializedPosition = _serializedObject.FindProperty("_wiringNodePosition"); ValidatePosition(); }
// Initializer (called from the Create method) void Initialize(Wiring.NodeBase runtimeInstance) { hideFlags = HideFlags.DontSave; // Object references _runtimeInstance = runtimeInstance; _serializedObject = new UnityEditor.SerializedObject(runtimeInstance); _serializedPosition = _serializedObject.FindProperty("_wiringNodePosition"); // Basic information name = runtimeInstance.GetInstanceID().ToString(); position = new Rect(_serializedPosition.vector2Value, Vector2.zero); // Slot initialization PopulateSlots(); }
// Remove a link between two nodes. public static void RemoveLinkNodes( Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent, Wiring.NodeBase nodeTo, MethodInfo targetMethod ) { var methodName = targetMethod.Name; var eventCount = triggerEvent.GetPersistentEventCount(); for (var i = 0; i < eventCount; i++) { if (nodeTo == triggerEvent.GetPersistentTarget(i) && methodName == triggerEvent.GetPersistentMethodName(i)) { UnityEventTools.RemovePersistentListener(triggerEvent, i); break; } } }
// Try to create a link between two nodes. // Returns true if the link is established successfully. public static bool TryLinkNodes( Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent, Wiring.NodeBase nodeTo, MethodInfo targetMethod ) { // Determine the type of the target action. var actionType = GetUnityActionToInvokeMethod(targetMethod); if (actionType == null) { return(false); // invalid target method type } // Create an action that is bound to the target method. var targetAction = Delegate.CreateDelegate( actionType, nodeTo, targetMethod ); if (triggerEvent is UnityEvent) { // The trigger event has no parameter. // Add the action to the event with a default parameter. if (actionType == typeof(UnityAction)) { UnityEventTools.AddVoidPersistentListener( triggerEvent, (UnityAction)targetAction ); return(true); } if (actionType == typeof(UnityAction <float>)) { UnityEventTools.AddFloatPersistentListener( triggerEvent, (UnityAction <float>)targetAction, 1.0f ); return(true); } } else if (triggerEvent is UnityEvent <float> ) { // The trigger event has a float parameter. // Then the target method should have a float parameter too. if (actionType == typeof(UnityAction <float>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <float>)triggerEvent, (UnityAction <float>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Vector3> ) { // The trigger event has a Vector3 parameter. // Then the target method should have a Vector3 parameter too. if (actionType == typeof(UnityAction <Vector3>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Vector3>)triggerEvent, (UnityAction <Vector3>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Quaternion> ) { // The trigger event has a Quaternion parameter. // Then the target method should have a Quaternion parameter too. if (actionType == typeof(UnityAction <Quaternion>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Quaternion>)triggerEvent, (UnityAction <Quaternion>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Color> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Color>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Color>)triggerEvent, (UnityAction <Color>)targetAction ); return(true); } } return(false); // trigger-target mismatch }
// Get an editor representation of the given node. public Node GetNodeOfInstance(Wiring.NodeBase instance) { return(_instanceIDToNodeMap[instance.GetInstanceID()]); }
// Check if this is a representation of a given instance. public bool IsRepresentationOf(Wiring.NodeBase instance) { return(_instance == instance); }
// Initializer (called from the Create method) void Initialize(Wiring.NodeBase runtimeInstance) { hideFlags = HideFlags.DontSave; // Object references _runtimeInstance = runtimeInstance; _serializedObject = new UnityEditor.SerializedObject(runtimeInstance); _serializedPosition = _serializedObject.FindProperty("_wiringNodePosition"); // Basic information name = runtimeInstance.GetInstanceID().ToString(); position = new Rect(_serializedPosition.vector2Value, Vector2.zero); // Slot initialization PopulateSlots(); }