Skip to content

Commit 28fe37d

Browse files
author
Dogukan Erenel MacPRO
committed
* Added widget delegates on add input / remove input / add output and remove output
1 parent 2882020 commit 28fe37d

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

Scripts/Widgets/Widget.cs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ public abstract class Data
5353
/// <param name="data"></param>
5454
public delegate void OnReceiveData(Data data);
5555

56+
/// <summary>
57+
/// The callback on input connection added.
58+
/// </summary>
59+
public delegate void OnInputAdded(Input input);
60+
/// <summary>
61+
/// The callback on input connection removed.
62+
/// </summary>
63+
public delegate void OnInputRemoved(Input input);
64+
/// <summary>
65+
/// The callback on output connection added.
66+
/// </summary>
67+
public delegate void OnOutputAdded(Output output);
68+
/// <summary>
69+
/// The callback on output connection removed.
70+
/// </summary>
71+
public delegate void OnOutputRemoved(Output output);
72+
5673
/// <summary>
5774
/// This object handles input on a widget.
5875
/// </summary>
@@ -131,6 +148,16 @@ public override string ToString()
131148
/// The delegate to the receiver function, this is set when Start() is called on this input.
132149
/// </summary>
133150
public OnReceiveData DataReceiver { get; private set; }
151+
/// <summary>
152+
/// Gets or sets the on output added callback
153+
/// </summary>
154+
/// <value>The on output added.</value>
155+
public OnOutputAdded OnOutputAdded { get; set; }
156+
/// <summary>
157+
/// Gets or sets the on output removed callback
158+
/// </summary>
159+
/// <value>The on output removed.</value>
160+
public OnOutputRemoved OnOutputRemoved { get; set; }
134161
#endregion
135162

136163
#region Public Functions
@@ -146,6 +173,8 @@ public bool AddOutput(Output output)
146173
if (m_Connections.Contains(output))
147174
return false;
148175
m_Connections.Add(output);
176+
if (OnOutputAdded != null)
177+
OnOutputAdded.Invoke(output);
149178
return true;
150179
}
151180
/// <summary>
@@ -155,7 +184,10 @@ public bool AddOutput(Output output)
155184
/// <returns></returns>
156185
public bool RemoveOutput(Output output)
157186
{
158-
return m_Connections.Remove(output);
187+
bool success = m_Connections.Remove(output);
188+
if (success && OnOutputRemoved != null)
189+
OnOutputRemoved.Invoke(output);
190+
return success;
159191
}
160192

161193
/// <summary>
@@ -374,6 +406,16 @@ public bool IsConnected
374406
/// If true, allows more than one input to be connected to this output.
375407
/// </summary>
376408
public bool AllowMany { get; private set; }
409+
/// <summary>
410+
/// Gets or sets the on input added callback
411+
/// </summary>
412+
/// <value>The on input added.</value>
413+
public OnInputAdded OnInputAdded { get; set; }
414+
/// <summary>
415+
/// Gets or sets the on input removed callback
416+
/// </summary>
417+
/// <value>The on input removed.</value>
418+
public OnInputRemoved OnInputRemoved { get; set; }
377419
#endregion
378420

379421
#region Public Functions
@@ -430,7 +472,8 @@ public bool AddConnection(Input input)
430472
c.Start(this);
431473
c.TargetInput = input;
432474
m_Connections.Add(c);
433-
475+
if (OnInputAdded != null)
476+
OnInputAdded.Invoke(input);
434477
return true;
435478
}
436479

@@ -453,7 +496,8 @@ public bool AddConnection(GameObject targetObject, string targetConnection = nul
453496
if (!c.ResolveTargetInput())
454497
return false; // couldn't resolve a input
455498
m_Connections.Add(c);
456-
499+
if (OnInputAdded != null)
500+
OnInputAdded.Invoke(c.TargetInput);
457501
return true;
458502
}
459503

@@ -464,7 +508,10 @@ public bool AddConnection(GameObject targetObject, string targetConnection = nul
464508
/// <returns></returns>
465509
public bool RemoveConnection(Connection c)
466510
{
467-
return m_Connections.Remove(c);
511+
bool success = m_Connections.Remove(c);
512+
if (success && OnInputRemoved != null)
513+
OnInputRemoved.Invoke(c.TargetInput);
514+
return success;
468515
}
469516
#endregion
470517

0 commit comments

Comments
 (0)