private GameObject InstantiateComponent(PlantComponent newComp, Transform parentCompTransform)
    {
        string prefabPath = ConstantValues.PathPrefabs + "/";

        switch (newComp.componentType)
        {
        case PlantComponentType.Roots:
            prefabPath = prefabPath + ConstantValues.PrefabRoots;
            break;

        case PlantComponentType.Stem:
            prefabPath = prefabPath + ConstantValues.PrefabStem;
            break;

        case PlantComponentType.Leaves:
            prefabPath = prefabPath + ConstantValues.PrefabLeaves;
            break;

        default:
            Debug.LogError("PrefabPath bad");
            break;
        }
        GameObject newCompGO = Instantiate(Resources.Load(prefabPath), parentCompTransform) as GameObject;

        newCompGO.GetComponent <PlantComponentFrontEnd>().PlantComponent = newComp;
        newCompGO.GetComponent <PlantComponentFrontEnd>().parent         = parentCompTransform;
        newCompGO.name = newComp.GetID();
        newCompGO.transform.localPosition = Vector3.up * 0.5f; // TODO: arbitrary amount up so it looks good now
        return(newCompGO);
    }
    /// <summary>
    /// Grows the plant components each tic
    /// </summary>
    /// <param name="frontEnd"></param>
    /// <returns></returns>
    public PlantComponent GrowPlant(PlantComponent comp)
    {
        PlantComponent newComp;

        switch (comp.componentType)
        {
        case PlantComponentType.Roots:
            newComp = new PlantComponent(PlantComponentType.Roots, roots[0].color);
            roots.Add(newComp);
            break;

        case PlantComponentType.Stem:
            newComp = new PlantComponent(PlantComponentType.Stem, stems[0].color);
            stems.Add(newComp);
            break;

        default:
            newComp = new PlantComponent(PlantComponentType.Empty, roots[0].color);
            Debug.LogError("Trying to grow bad component. Empty comp created");
            break;
        }
        newComp.parent = comp;
        Debug.Log("Growing " + newComp.GetID());
        return(newComp);
    }
Beispiel #3
0
    static void InstantiateComponent(PlantComponent comp, Transform plant)
    {
        string prefabType;

        switch (comp.componentType)
        {
        case PlantComponentType.Roots:
            prefabType = ConstantValues.PrefabRoots;
            break;

        case PlantComponentType.Stem:
            prefabType = ConstantValues.PrefabStem;
            break;

        case PlantComponentType.Leaves:
            prefabType = ConstantValues.PrefabLeaves;
            break;

        default:
            prefabType = ConstantValues.PrefabRoots;
            Debug.LogError("Could not instantiate componenet. Prefab type bad");
            break;
        }
        GameObject compGO = Instantiate(Resources.Load(ConstantValues.PathPrefabs + "/" + prefabType)) as GameObject;

        compGO.GetComponent <PlantComponentFrontEnd>().PlantComponent = comp;

        if (comp.componentType != PlantComponentType.Empty)
        {
            if (comp.parent != null)
            {
                Debug.LogError("parent 1: " + comp.parent.GetID());
            }
            if (comp.parent == null)
            {
                compGO.GetComponent <PlantComponentFrontEnd>().parent = plant;
                Debug.Log("parent = plant");
            }
            else
            {
                Debug.LogError("newComp: " + compGO);
                Debug.LogError("parent: " + comp.parent.GetID());
                compGO.GetComponent <PlantComponentFrontEnd>().parent = GameObject.Find(comp.parent.GetID()).transform;
                Debug.Log("parent = " + compGO.GetComponent <PlantComponentFrontEnd>().parent.name);
            }

            compGO.transform.SetParent(compGO.GetComponent <PlantComponentFrontEnd>().parent);
            compGO.name = comp.GetID();
            Debug.Log("instantiated comp name: " + compGO.name);
            compGO.transform.localPosition = Vector3.up * 0.5f; // TODO: arbitrary amount up so it looks good now
        }
    }