Esempio n. 1
0
        public void SetValue(object value, Type type = null)
        {
            if (value != null)
            {
                ParameterType = type == null?value.GetType().FullName : type.FullName;

                if (ParameterType == typeof(string).FullName)
                {
                    StringValue = value.ToString();
                }
                else if (value is bool || value is Boolean)
                {
                    BoolValue = Convert.ToBoolean(value);
                }
                else if (IsNumeric(ParameterType))
                {
                    NumericValue = Convert.ToSingle(value);
                }
                else if (value is UnityEngine.Object)
                {
                    ObjectUniqueName = ((UnityEngine.Object)value).name;
                }
                else if (value is NPCAffordance)
                {
                    Affordance = (NPCAffordance)value;
                }
                else if (value is NPCAssertion)
                {
                    Assertion = (NPCAssertion)value;
                }
            }
        }
        public static Dictionary <string, MethodInfo> GetAffordances()
        {
            Dictionary <string, MethodInfo> affordances = new Dictionary <string, MethodInfo>();

            // Pick up component's affordances
            foreach (MethodInfo method in typeof(NPCAI).GetMethods())
            {
                if (Attribute.IsDefined(method, typeof(NPCAffordance)))
                {
                    NPCAffordance aff = (NPCAffordance)Attribute.GetCustomAttribute(method, typeof(NPCAffordance));
                    affordances.Add(aff.Name, method);
                }
            }
            // Look for affordances in modules - this does not guarantees an affordance will be usable if the
            // module hasn't been added to the NPCController instance
            foreach (Type mytype in Assembly.GetExecutingAssembly().GetTypes()
                     .Where(mytype => mytype.GetInterfaces().Contains(typeof(INPCModule))))
            {
                foreach (MethodInfo method in mytype.GetMethods())
                {
                    if (Attribute.IsDefined(method, typeof(NPCAffordance)))
                    {
                        NPCAffordance aff = (NPCAffordance)Attribute.GetCustomAttribute(method, typeof(NPCAffordance));
                        affordances.Add(aff.Name, method);
                    }
                }
            }
            return(affordances);
        }
 public override void Initialize(object[] parameters)
 {
     if (parameters[0] is NPCAffordance)
     {
         g_Affordance = (NPCAffordance)parameters[0];
     }
     else
     {
         g_Action = (Func <BEHAVIOR_STATUS>)parameters[0];
     }
 }
 public NPCAction(NPCAffordance Affordance) : base()
 {
     g_Affordance = Affordance;
 }