コード例 #1
0
        public static Node CreateChild(Context context, Node parent, int ordinal)
        {
            int[]   path = GetChildPath(parent.path, ordinal);
            int[]   neighborBranches;
            int[][] neighborPaths;
            GetNeighborPaths(path, parent.branch.index, out neighborBranches, out neighborPaths);

            GameObject gameObject = new GameObject("Chunk " + string.Join("", path));

            gameObject.transform.SetParent(parent.branch.gameObject.transform, false);
            MeshFilter   meshFilter   = gameObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>();

            meshRenderer.enabled        = false;
            meshRenderer.sharedMaterial = context.constants.material;
            Context.Depth depth = context.depths[parent.depth.index + 1];

            return(new Node
            {
                parent = parent,
                children = null,
                path = path,
                neighborBranches = neighborBranches,
                neighborPaths = neighborPaths,
                branch = parent.branch,
                depth = depth,
                offset = parent.offset + childOffsetVectors[ordinal] * depth.scale,
                gameObject = gameObject,
                mesh = null,
                meshFilter = meshFilter,
                meshRenderer = meshRenderer,
                meshRequest = null,
                meshRequestCancellation = null
            });
        }
コード例 #2
0
        public static Node CreateRoot(Context.Constants constants, Context.Depth depth, Context.Branch branch)
        {
            GameObject gameObject = new GameObject("Chunk");

            gameObject.transform.SetParent(branch.gameObject.transform, false);
            MeshFilter   meshFilter   = gameObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>();

            meshRenderer.enabled        = false;
            meshRenderer.sharedMaterial = constants.material;

            int[]   path = new int[0];
            int[]   neighborBranches;
            int[][] neighborPaths;
            GetNeighborPaths(path, branch.index, out neighborBranches, out neighborPaths);

            return(new Node
            {
                parent = null,
                children = null,
                path = path,
                neighborBranches = neighborBranches,
                neighborPaths = neighborPaths,
                branch = branch,
                depth = depth,
                offset = Vector2.zero,
                gameObject = gameObject,
                mesh = null,
                meshFilter = meshFilter,
                meshRenderer = meshRenderer,
                meshRequest = null,
                meshRequestCancellation = null
            });
        }