예제 #1
0
 // Use this for initialization
 protected virtual void Start()
 {
     _decision = new DecisionTree <Action>();
     System.Reflection.MethodInfo[] methods = this.GetType().GetMethods();
     foreach (System.Reflection.MethodInfo method in methods)
     {
         if (((ActionMethod[])method.GetCustomAttributes(typeof(ActionMethod), true)).Length > 0)
         {
             _decision.AddAction(new DecisionTree <Action> .Action(method.Name, (Action)Delegate.CreateDelegate(typeof(Action), this, method)));
         }
     }
     foreach (System.Reflection.MethodInfo method in methods)
     {
         if (((PerceptMethod[])method.GetCustomAttributes(typeof(PerceptMethod), true)).Length > 0)
         {
             List <DecisionTree <Action> .Action> actions = new List <DecisionTree <Action> .Action>();
             List <float> weights = new List <float>();
             foreach (ActionLink link in (ActionLink[])method.GetCustomAttributes(typeof(ActionLink), true))
             {
                 DecisionTree <Action> .Action a = _decision.GetAction(link.Name);
                 if (a != null)
                 {
                     actions.Add(a);
                     weights.Add(link.Weight);
                 }
             }
             if (actions.Count > 0)
             {
                 _decision.AddPercept(new DecisionTree <Action> .Percept(method.Name, actions.ToArray(), weights.ToArray()));
             }
         }
     }
 }
예제 #2
0
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     _agent             = GetComponent <AgentController> ();
     _agent.CurrentTask = this;
     _memory            = GetComponent <Memory> ();
     _moving            = GetComponent <Moving> ();
     _inventory         = GetComponent <Inventory>();
     _village           = GameObject.Find("Village").GetComponent <Village>();
     _construction      = _village.GetPrefab("ConstructionSite");
     _target            = null;
     _stockpile         = null;
     _buildingDecision  = new DecisionTree <GameObject>();
     System.Reflection.MethodInfo[] methods = this.GetType().GetMethods();
     foreach (YamlLoader.PropertyElement element in (List <YamlLoader.PropertyElement>)Manager.Instance.Properties.GetElement("BuildingCost").Value)
     {
         _buildingDecision.AddAction(new DecisionTree <GameObject> .Action(element.Name, _village.GetPrefab(element.Name)));
     }
     foreach (System.Reflection.MethodInfo method in methods)
     {
         if (((BuildingChoiceMethod[])method.GetCustomAttributes(typeof(BuildingChoiceMethod), true)).Length > 0)
         {
             List <DecisionTree <GameObject> .Action> actions = new List <DecisionTree <GameObject> .Action>();
             List <float> weights = new List <float>();
             foreach (BuildingChoiceLink link in (BuildingChoiceLink[])method.GetCustomAttributes(typeof(BuildingChoiceLink), true))
             {
                 DecisionTree <GameObject> .Action a = _buildingDecision.GetAction(link.Name);
                 if (a != null)
                 {
                     actions.Add(a);
                     weights.Add(link.Weight);
                 }
             }
             if (actions.Count > 0)
             {
                 _buildingDecision.AddPercept(new DecisionTree <GameObject> .Percept(method.Name, actions.ToArray(), weights.ToArray()));
             }
         }
     }
 }