示例#1
0
        public static GameObject CreateGameObject(string resourceName, UnityMeshInfo unityMeshInfo)
        {
            var gameObject = (GameObject)Instantiate(Resources.Load(resourceName));

            var mesh = gameObject.GetComponent <MeshFilter>().mesh;

            mesh.Clear();
            mesh.vertices  = unityMeshInfo.Vertices;
            mesh.triangles = unityMeshInfo.Triangles;
            mesh.uv        = unityMeshInfo.Uv;
            mesh.colors    = Enumerable.Repeat(unityMeshInfo.Color, unityMeshInfo.Uv.Length).ToArray();
            mesh.RecalculateNormals();

            gameObject.GetComponent <MeshCollider>().sharedMesh = mesh;
            gameObject.transform.position = unityMeshInfo.Position;

            return(gameObject);
        }
示例#2
0
    /// <summary>
    /// 初始化UnityMesh渲染相关组件
    /// </summary>
    /// <param name="node"></param>
    /// <param name="componentName"></param>
    /// <param name="mat"></param>
    private void UnityMeshInfoInit(Transform node, string componentName, Material mat)
    {
        UnityMeshInfo unityMeshInfo = new UnityMeshInfo(node, componentName, mat);

        unityMeshInfoDic.Add(unityMeshInfo.componentName, unityMeshInfo);
    }