You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.0 KiB
69 lines
2.0 KiB
// This code is part of the Fungus library (https://github.com/snozbot/fungus) |
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) |
|
|
|
using UnityEngine; |
|
|
|
namespace Fungus |
|
{ |
|
/// <summary> |
|
/// Command to store the min or max of 2 values |
|
/// </summary> |
|
[CommandInfo("Math", |
|
"MinMax", |
|
"Command to store the min or max of 2 values")] |
|
[AddComponentMenu("")] |
|
public class MinMax : Command |
|
{ |
|
public enum Function |
|
{ |
|
Min, |
|
Max |
|
} |
|
|
|
[Tooltip("Min Or Max")] |
|
[SerializeField] |
|
protected Function function = Function.Min; |
|
|
|
//[Tooltip("LHS Value ")] |
|
[SerializeField] |
|
protected FloatData inLHSValue, inRHSValue; |
|
|
|
//[Tooltip("Where the result of the function is stored.")] |
|
[SerializeField] |
|
protected FloatData outValue; |
|
|
|
public override void OnEnter() |
|
{ |
|
switch (function) |
|
{ |
|
case Function.Min: |
|
outValue.Value = Mathf.Min(inLHSValue.Value, inRHSValue.Value); |
|
break; |
|
case Function.Max: |
|
outValue.Value = Mathf.Max(inLHSValue.Value, inRHSValue.Value); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
Continue(); |
|
} |
|
|
|
public override string GetSummary() |
|
{ |
|
return function.ToString() + " " + |
|
"out: " + (outValue.floatRef != null ? outValue.floatRef.Key : outValue.Value.ToString()) + |
|
" [" + inLHSValue.Value.ToString() + " - " + inRHSValue.Value.ToString() + "]"; |
|
} |
|
|
|
public override bool HasReference(Variable variable) |
|
{ |
|
return inLHSValue.floatRef == variable || inRHSValue.floatRef == variable || outValue.floatRef == variable; |
|
} |
|
|
|
public override Color GetButtonColor() |
|
{ |
|
return new Color32(235, 191, 217, 255); |
|
} |
|
} |
|
} |