/// <summary> /// Creates a new random tree prefab. /// </summary> /// <param name="propName">Name of prefab</param> /// <returns>New tree prefab</returns> internal static TreeInfo NewRandomTree(string treeName) { // Need valid name. if (treeName == null) { Logging.Error("null tree name for random tree"); return(null); } // Need unique name. if (DuplicateTreeName(treeName)) { Logging.Error("duplicate tree name for random tree"); return(null); } // Instantiate existing tree and use as base for new tree. GameObject treeInstance = Object.Instantiate(PrefabCollection <TreeInfo> .FindLoaded("Tree2variant").gameObject); treeInstance.name = treeName; TreeInfo randomTree = treeInstance.GetComponent <TreeInfo>(); treeInstance.SetActive(false); randomTree.m_prefabInitialized = false; randomTree.InitializePrefab(); // Add new tree to list and return direct reference. randomTrees.Add(randomTree); return(randomTree); }
/// <summary> /// Instantiates a new TreeInfo prefab. /// </summary> /// <param name="treeName">Name to instantiate</param> /// <returns>New tree prefab, or null if instantiation fialed</returns> private static TreeInfo InstantiateTree(string treeName) { // Need valid name. if (treeName == null) { Logging.Error("null tree name for random tree"); return(null); } // Instantiate tree template and use as base for new tree. if (PrefabLists.RandomTreeTemplate != null) { GameObject treeInstance = UnityEngine.Object.Instantiate(PrefabLists.RandomTreeTemplate.gameObject); treeInstance.name = treeName; TreeInfo randomTree = treeInstance.GetComponent <TreeInfo>(); treeInstance.SetActive(false); randomTree.m_isCustomContent = true; randomTree.m_prefabInitialized = false; randomTree.InitializePrefab(); randomTree.m_prefabInitialized = true; return(randomTree); } // If we got here, then we weren't able to find the random tree template. Logging.Error("random tree template not found"); return(null); }