How to create enum as custom shared variable?

mostlyhuman

Member
Is this possible? I took a stab at it but cant get the syntax correct.

C#:
namespace BehaviorDesigner.Runtime
{
    [System.Serializable]
    public class SharedComparisonTypeEnum : SharedVariable<???>
    {
        public enum ComparisonType { GreaterThan, LessThan, EqualTo, NotEqualTo };
        public static implicit operator SharedComparisonTypeEnum(ComparisonType value) { return new SharedComparisonTypeEnum { Value = value }; }
    }
}
 
Yes, it is possible. You'll want to have ComparisonType outside of the SharedComparisonType class.
 
I created a class to hold public enum definitions and then was able to do this with no errors:

C#:
namespace BehaviorDesigner.Runtime
{
    [System.Serializable]
    public class SharedComparisonTypeEnum : SharedVariable<SharedEnums.ComparisonType>
   {
        public static implicit operator SharedComparisonTypeEnum(SharedEnums.ComparisonType value) { return new SharedComparisonTypeEnum { Value = value }; }
    }
}

But now I am trying to use it in a task, in a switch statement and I dont see how to access the value correctly in the switch. I probably did something wrong in the shared variable script. I tried comparisonType.Value, ComparisonType etc
C#:
namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityVector3
{
    public class AgentToTargetAngleComparison : Action
    {
        public SharedComparisonTypeEnum comparisonType;

        public override TaskStatus OnUpdate()
        {
            switch (comparisonType)
            {
                case comparisonType.???:

Here's my shared enums class if you need to see this too:
C#:
namespace BehaviorDesigner.Runtime
{
    [System.Serializable]
    public class SharedEnums
    {
        public enum ComparisonType { GreaterThan, LessThan, EqualTo, NotEqualTo };
    }
}
 
You should be switching on comparisonType.Value. You can't switch on SharedVariables because it's a class and not an enum.
 
Top