コード例 #1
0
        /**
         * TODO should be outside
         */
        public BaseNode Produce(BaseNode root)
        {
            Debug.Log(root.GetType());
            if (table.ContainsKey(root.GetType()))
            {
                var schemaTable = table[root.GetType()];

                ProductionOutputSchema chosenSchema = null;
                float schemaValue = -1;
                foreach (var curr in schemaTable)
                {
                    var currSchemaValue = Random.value * curr.Value;
                    if (currSchemaValue > schemaValue)
                    {
                        chosenSchema = curr.Key;
                        schemaValue  = currSchemaValue;
                    }
                }

                if (chosenSchema != null)
                {
                    foreach (var child in chosenSchema.GenerateNodes())
                    {
                        root.AddChild(Produce(child));
                    }
                }
            }

            return(root);
        }
コード例 #2
0
 public void AddRule(System.Type input, ProductionOutputSchema output, float probability = 1)
 {
     if (!table.ContainsKey(input))
     {
         table[input] = new Dictionary <ProductionOutputSchema, float>();
     }
     table[input][output] = probability;
 }