Exemple #1
0
    protected static PeabrainNode NodeFromJSONHash(Hashtable hash, Peabrain brain)
    {
        string baseType = (String) hash["type"];
        Debug.Log("Trying base type " + baseType);
        //Type type = assem.GetType("Peabrain" + char.ToUpper(baseType[0]) + baseType.Substring(1, baseType.Length - 1));
        //Type type = Type.GetType("Peabrain" + char.ToUpper(baseType[0]) + baseType.Substring(1, baseType.Length - 1));
        //PeabrainNode node = (PeabrainNode) Activator.CreateInstance(type);

        // Unfortunately verbose code for instantiating via string (when using iPhone code stripping)
        PeabrainNode node = null;
        switch (baseType) {
            case "DelegateFilter":
                node = new PeabrainDelegateFilter(); break;
            case "DurationFilter":
                node = new PeabrainDurationFilter(); break;
            case "ProbabilityFilter":
                node = new PeabrainProbabilityFilter(); break;
            case "Router":
                node = new PeabrainRouter(); break;
            case "Selector":
                node = new PeabrainSelector(); break;
            case "Sequence":
                node = new PeabrainSequence(); break;
            case "Task":
                node = new PeabrainTask(); break;
        }

        if (node != null) {
            Debug.Log("Configuring type " + baseType);
            node.ConfigureFromJSONHash(hash, brain);
            Debug.Log("Done with " + baseType);
        }

        return node;
    }
Exemple #2
0
 protected override void ConfigureFromJSONHash(Hashtable hash, Peabrain brain)
 {
     base.ConfigureFromJSONHash(hash, brain);
     if (base.ConfigureDelegateFromJSONHash(hash, brain)) {
         values = (ArrayList) hash["values"];
         if (values == null)
             Debug.Log("[PeabrainRouter] Warning: router has no values with which to route");
     }
 }
 protected override void ConfigureFromJSONHash(Hashtable hash, Peabrain brain)
 {
     base.ConfigureFromJSONHash(hash, brain);
     base.ConfigureDelegateFromJSONHash(hash, brain);
 }
 protected override void ConfigureFromJSONHash(Hashtable hash, Peabrain brain)
 {
     base.ConfigureFromJSONHash(hash, brain);
     baseDuration = (float) hash["duration"];
     random = (float) hash["random"];
 }
Exemple #5
0
 protected bool ConfigureDelegateFromJSONHash(Hashtable hash, Peabrain brain)
 {
     string actionString = (string) hash["action"];
     if (actionString != null) {
         action = Enum.Parse(this.brain.actor.ActionEnum(), actionString);
         return true;
     }
     else {
         Debug.Log("[" + GetType() + "] Warning: no action defined");
         return false;
     }
 }
Exemple #6
0
    protected virtual void ConfigureFromJSONHash(Hashtable hash, Peabrain brain)
    {
        this.brain = brain;

        ArrayList childrenJson = (ArrayList) hash["children"];
        if (childrenJson != null) {
            PeabrainNode[] nodes = new PeabrainNode[childrenJson.Count];
            for (int c = 0; c < childrenJson.Count; c++) {
                nodes[c] = NodeFromJSONHash((Hashtable) childrenJson[c], brain);
            }
            children = nodes;
        }

        description = (string) hash["description"];
    }