Exemple #1
0
	static List<SerializablePlant> GetListOfSerializablePlant(){
		List<SerializablePlant> listSerializablePlants = new List<SerializablePlant>();
		Plant[] _plants = GameObject.FindObjectsOfType<Plant>();

		foreach(Plant _plant in _plants){
			SerializablePlant _sp = new SerializablePlant();

			_sp.plantName = _plant.plantName.ToString();
			_sp.productNumber = _plant.productNumber;
			_sp.seedNumber = _plant.seedNumber;

			listSerializablePlants.Add(_sp);
		}
		return listSerializablePlants;
	}
Exemple #2
0
    public void AddNewPlant(Vector3 point)
    {
        //Debug.Log ("add plants to " + point);

        GameObject newPlant = new GameObject();

        newPlant.gameObject.AddComponent <Plant> ();
        newPlant.gameObject.GetComponent <Plant> ().location = point;
        allPlantsList.Add(newPlant);

        GameObject seed = (GameObject)Instantiate(Resources.Load("Seed"));

        seed.transform.position = point;


        /* All possible node types
         * string[] br_intnodes = new string[] { "A", "B", "C", "D", "E" }; // Branching internodes
         * string[] draw_intnodes = new string[] { "F", "G", "H", "I", "J", "K" }; // Internodes that are drawn
         * string[] branch_types = new string[] { "S", "T", "U", "V", "X" }; // Different types of branches
         * string[] delay_nodes = new string[] {}; // Instead of draw_intnodes?  */

        int numNodes = Random.Range(1, 6);

        string[] br_intnodes = new string[numNodes];
        for (int i = 0; i < numNodes; i++)
        {
            br_intnodes [i] = ((char)(65 + i)).ToString();
        }

        numNodes = Random.Range(1, 7);
        string[] draw_intnodes = new string[numNodes];
        for (int i = 0; i < numNodes; i++)
        {
            draw_intnodes [i] = ((char)(70 + i)).ToString();
        }

        numNodes = Random.Range(1, 5);
        string[] branch_types = new string[numNodes];
        for (int i = 0; i < numNodes; i++)
        {
            branch_types [i] = ((char)(83 + i)).ToString();
        }

        ruleGenerator.AddCFGRule("(BrIn)", br_intnodes);
        ruleGenerator.AddCFGRule("(DrIn)", draw_intnodes);
        ruleGenerator.AddCFGRule("(BrTyp)", branch_types);

        SerializableDictionary <char, string> rules = new SerializableDictionary <char, string> ();

        // Must set rules for all internodes.
        string rule;

        for (int j = 0; j < draw_intnodes.Length; j++)
        {
            rule = ruleGenerator.GenerateRule(draw_intnodes[j][0], 2);
            rules.Add(draw_intnodes [j] [0], rule);
        }
        for (int j = 0; j < br_intnodes.Length; j++)
        {
            rule = ruleGenerator.GenerateRule(br_intnodes[j][0], 3);
            rules.Add(br_intnodes [j] [0], rule);
        }
        for (int j = 0; j < branch_types.Length; j++)
        {
            rule = ruleGenerator.GenerateRule(branch_types [j] [0], 3);
            rules.Add(branch_types [j] [0], rule);
        }
        rules.Add('l', "L");          // Leaves mature over time
        newPlant.gameObject.GetComponent <Plant>().InitNewPlant(
            new Vector3(point.x, 20, point.z), rules, br_intnodes);

        pc.Plants = new SerializablePlant[this.allPlantsList.Count];
        for (int i = 0; i < this.allPlantsList.Count; i++)
        {
            GameObject        g  = this.allPlantsList[i];
            SerializablePlant sp = new SerializablePlant();
            sp.ConvertPlantToSP(g.GetComponent <Plant>());
            pc.Plants[i] = sp;
        }

        pc.Save(Path.Combine(Application.persistentDataPath, "plantData.xml"));
    }