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.
119 lines
3.4 KiB
119 lines
3.4 KiB
/*This script has been, partially or completely, generated by the Fungus.GenerateVariableWindow*/ |
|
using UnityEngine; |
|
|
|
|
|
namespace Fungus |
|
{ |
|
// <summary> |
|
/// Get or Set a property of a Vector2 component |
|
/// </summary> |
|
[CommandInfo("Property", |
|
"Vector2", |
|
"Get or Set a property of a Vector2 component")] |
|
[AddComponentMenu("")] |
|
public class Vector2Property : BaseVariableProperty |
|
{ |
|
//generated property |
|
public enum Property |
|
{ |
|
X, |
|
Y, |
|
Normalized, |
|
Magnitude, |
|
SqrMagnitude, |
|
} |
|
|
|
|
|
[SerializeField] |
|
protected Property property; |
|
|
|
[SerializeField] |
|
[VariableProperty(typeof(Vector2Variable))] |
|
protected Vector2Variable vector2Var; |
|
|
|
[SerializeField] |
|
[VariableProperty(typeof(FloatVariable), |
|
typeof(Vector2Variable))] |
|
protected Variable inOutVar; |
|
|
|
public override void OnEnter() |
|
{ |
|
var iof = inOutVar as FloatVariable; |
|
var iov2 = inOutVar as Vector2Variable; |
|
|
|
|
|
var target = vector2Var.Value; |
|
|
|
switch (getOrSet) |
|
{ |
|
case GetSet.Get: |
|
switch (property) |
|
{ |
|
case Property.X: |
|
iof.Value = target.x; |
|
break; |
|
case Property.Y: |
|
iof.Value = target.y; |
|
break; |
|
case Property.Normalized: |
|
iov2.Value = target.normalized; |
|
break; |
|
case Property.Magnitude: |
|
iof.Value = target.magnitude; |
|
break; |
|
case Property.SqrMagnitude: |
|
iof.Value = target.sqrMagnitude; |
|
break; |
|
default: |
|
Debug.Log("Unsupported get or set attempted"); |
|
break; |
|
} |
|
|
|
break; |
|
case GetSet.Set: |
|
switch (property) |
|
{ |
|
case Property.X: |
|
target.x = iof.Value; |
|
break; |
|
case Property.Y: |
|
target.y = iof.Value; |
|
break; |
|
default: |
|
Debug.Log("Unsupported get or set attempted"); |
|
break; |
|
} |
|
|
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
Continue(); |
|
} |
|
|
|
public override string GetSummary() |
|
{ |
|
if (inOutVar == null) |
|
{ |
|
return "Error: no variable set to push or pull data to or from"; |
|
} |
|
|
|
return getOrSet.ToString() + " " + property.ToString(); |
|
} |
|
|
|
public override Color GetButtonColor() |
|
{ |
|
return new Color32(235, 191, 217, 255); |
|
} |
|
|
|
public override bool HasReference(Variable variable) |
|
{ |
|
if (vector2Var == variable || inOutVar == variable) |
|
return true; |
|
|
|
return false; |
|
} |
|
|
|
} |
|
} |