Created
June 3, 2018 03:35
-
-
Save Frooxius/4951a6e68d985491b9414e6a161e2425 to your computer and use it in GitHub Desktop.
LogiX Nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[NodeName("+")] | |
[NodeOverload("Add")] | |
[Category("LogiX/Operators")] | |
public class Add_Float : DualInputOperator<float> | |
{ | |
public readonly Input<float> A; | |
public readonly Input<float> B; | |
public override float Content { get { return A.EvaluateRaw() + B.EvaluateRaw(); } } | |
protected override Type OtherVariant { get { return typeof(AddMulti_Float); } } | |
} | |
[NodeName("+")] | |
[NodeOverload("AddMulti")] | |
[HiddenNode] | |
[Category("LogiX/Operators")] | |
public class AddMulti_Float : MultiInputOperator<float> | |
{ | |
public override float Content | |
{ | |
get | |
{ | |
if(Operands.Count == 0) | |
return default(float); | |
var sum = Operands.GetElement(0).EvaluateRaw(); | |
for(int i = 1; i < Operands.Count; i++) | |
sum += Operands.GetElement(i).EvaluateRaw(); | |
return sum; | |
} | |
} | |
protected override Type OtherVariant { get { return typeof(Add_Float); } } | |
} | |
[NodeName("+")] | |
[NodeOverload("Add")] | |
[Category("LogiX/Operators")] | |
public class Add_Int : DualInputOperator<int> | |
{ | |
public readonly Input<int> A; | |
public readonly Input<int> B; | |
public override int Content { get { return A.EvaluateRaw() + B.EvaluateRaw(); } } | |
protected override Type OtherVariant { get { return typeof(AddMulti_Int); } } | |
} | |
[NodeName("--")] | |
[NodeOverload("Dec")] | |
[Category("LogiX/Operators")] | |
public class Dec_Int : LogixOperator<int> | |
{ | |
public readonly Input<int> A; | |
public override int Content { get { return (int)(A.EvaluateRaw()-1); } } | |
} | |
[NodeOverload("Sin")] | |
[Category("LogiX/Math")] | |
public class Sin_Float : LogixOperator<float> | |
{ | |
public readonly Input<float> N; | |
public override float Content { get { return MathX.Sin(N.EvaluateRaw()); } } | |
} | |
[Category("LogiX/String")] | |
public class IndexOfString : LogixOperator<int> | |
{ | |
public readonly Input<string> Str; | |
public readonly Input<string> Part; | |
public override int Content { get { return Str.EvaluateRaw().IndexOf(Part.EvaluateRaw()); } } | |
} | |
[Category("LogiX/String")] | |
public class Substring : LogixOperator<string> | |
{ | |
public readonly Input<string> Str; | |
public readonly Input<int> StartIndex; | |
public readonly Input<int> Length; | |
public override string Content | |
{ | |
get | |
{ | |
var str = Str.EvaluateRaw(); | |
// propagate without change | |
if (string.IsNullOrEmpty(str)) | |
return str; | |
var start = StartIndex.EvaluateRaw(); | |
var length = Length.EvaluateRaw(str.Length); | |
// clamp to the beginning | |
// TODO!!! Issue a warning? | |
if (start < 0) | |
start = 0; | |
// empty | |
if (start >= str.Length) | |
return ""; | |
return str.Substring(start, Math.Min(str.Length - start, length)); | |
} | |
} | |
} | |
[Category("LogiX/Playback")] | |
[NodeName("Playback State")] | |
public class PlaybackReadState : LogixNode | |
{ | |
public readonly Input<IPlayable> Source; | |
public readonly Output<bool> IsPlaying; | |
public readonly Output<bool> Loop; | |
public readonly Output<float> Position; | |
public readonly Output<float> NormalizedPosition; | |
public readonly Output<float> ClipLength; | |
public readonly Output<float> Speed; | |
protected override void OnEvaluate() | |
{ | |
var playable = Source.EvaluateRaw(); | |
if(playable != null) | |
{ | |
IsPlaying.Value = playable.IsPlaying; | |
Loop.Value = playable.Loop; | |
Position.Value = playable.Position; | |
NormalizedPosition.Value = playable.NormalizedPosition; | |
ClipLength.Value = playable.ClipLength; | |
Speed.Value = playable.Speed; | |
} | |
else | |
{ | |
// for consistency | |
IsPlaying.Value = false; | |
Loop.Value = false; | |
Position.Value = 0f; | |
NormalizedPosition.Value = 0f; | |
ClipLength.Value = 0f; | |
Speed.Value = 0f; | |
} | |
} | |
protected override void OnCommonUpdate() | |
{ | |
var source = Source.Evaluate(); | |
if (source != null && source.IsPlaying) | |
NotifyInputChange(); | |
} | |
} | |
[NodeName("If")] | |
[Category("LogiX/Flow")] | |
public class IfNode : LogixNode | |
{ | |
public readonly Impulse True; | |
public readonly Impulse False; | |
public readonly Input<bool> Condition; | |
[ImpulseTarget] | |
public void Run() | |
{ | |
if (Condition.Evaluate()) | |
True.Trigger(); | |
else | |
False.Trigger(); | |
} | |
} | |
[NodeName("Delay")] | |
[Category("LogiX/Flow")] | |
public class DelayNode : LogixNode | |
{ | |
public readonly Impulse Impulse; | |
public readonly Input<float> Delay; | |
[ImpulseTarget] | |
public void Trigger() | |
{ | |
StartCoroutine(DelayImpulse(Delay.Evaluate())); | |
} | |
IEnumerator<Context> DelayImpulse(float delay) | |
{ | |
yield return Context.WaitForSeconds(delay); | |
Impulse.Trigger(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment