Example #1
0
        /// <summary>
        /// Convert a tree and assign a Pool item to it.
        /// </summary>
        /// <param name="terrain">the terrain.</param>
        /// <param name="treeInstanceID">the tree instance id</param>
        /// <param name="UNTerrain">the UN terrain instance</param>
        public static void ConvertTreeInstance(this Terrain terrain, int treeInstanceID, UNTerrain UNTerrain)
        {
            TreeInstance tree = terrain.terrainData.GetTreeInstance(treeInstanceID);

            Vector3    treeScale    = tree.GetWorldScale();
            Quaternion treeRotation = tree.GetWorldRotation();

            terrain.terrainData.RemoveTreeInstance(treeInstanceID, UNTerrain);

            Vector3 pos = tree.position.LocalToWorld(terrain.terrainData.size, terrain.transform.position);

            UNTerrain.Pool.TryResetOnUID(treeInstanceID, true);
            var item = UNTerrain.Pool.TryPool <HarvestableTIPoolItem>(tree.prototypeIndex, 0, treeInstanceID, true);

            if (item != null)
            {
                item.transform.rotation   = treeRotation;
                item.transform.localScale = treeScale;

                item.MoveItem(pos);
            }
        }