コード例 #1
0
ファイル: TDTile.cs プロジェクト: rgpieters/Gladiator-Game
 public UnityEngine.Vector2 UV(UVS uv)
 {
     return(_tileUVs [(int)uv]);
 }
コード例 #2
0
        /// <summary>
        /// Converts the record/s into a Unity GameObject structure with meshes,
        /// materials etc and imports into the scene.
        /// </summary>
        public override void ImportIntoScene()
        {
            // Create an empty gameobject
            UnityGameObject = new GameObject(ID);
            // DuckbearLab: FIX!
            //UnityGameObject.transform.localScale = Vector3.one;

            // Apply transformations
            UnityGameObject.transform.localPosition = Position;
            UnityGameObject.transform.localRotation = Rotation;
            if (Scale != Vector3.one)
            {
                UnityGameObject.transform.localScale = Scale;
            }

            // Assign parent
            if (Parent != null && Parent is InterRecord)
            {
                // DuckbearLab: FIX!
                UnityGameObject.transform.SetParent((Parent as InterRecord).UnityGameObject.transform, false);
                //UnityGameObject.transform.parent = (Parent as InterRecord).UnityGameObject.transform;
            }

            // Add Comment
            if (!string.IsNullOrEmpty(Comment))
            {
                UnityGameObject.AddComponent <UFLT.MonoBehaviours.Comment>().Value = Comment;
            }

            // Processes children
            base.ImportIntoScene();

            // Create mesh
            if (Vertices != null && Vertices.Count > 0)
            {
                Mesh m = new Mesh();
                m.name     = ID;
                m.vertices = VertexPositions.ToArray();
                m.normals  = Normals.ToArray();
                m.uv       = UVS.ToArray();

                // DuckbearLab: Fix for very large meshes
                if (VertexPositions.Count >= ushort.MaxValue)
                {
                    m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
                }

                MeshRenderer mr   = UnityGameObject.AddComponent <MeshRenderer>();
                Material[]   mats = new Material[SubMeshes.Count];
                MeshFilter   mf   = UnityGameObject.AddComponent <MeshFilter>();

                // Set submeshes
                m.subMeshCount = SubMeshes.Count;
                for (int i = 0; i < SubMeshes.Count; i++)
                {
                    mats[i] = SubMeshes[i].Key.UnityMaterial;
                    m.SetTriangles(SubMeshes[i].Value.ToArray(), i);
                }


                // DuckbearLab: OPTIMIZE!
                //mr.materials = mats;
                ;
                {
                    bool equal = true;
                    foreach (var material in mats)
                    {
                        if (material != mats[0])
                        {
                            equal = false;
                        }
                    }

                    if (equal && SubMeshes.Count > 1)
                    {
                        CombineInstance[] combine = new CombineInstance[SubMeshes.Count];
                        for (int i = 0; i < combine.Length; i++)
                        {
                            combine[i].mesh         = m;
                            combine[i].subMeshIndex = i;
                        }
                        var newMesh = new Mesh();
                        newMesh.name = ID;
                        newMesh.CombineMeshes(combine, true, false);
                        m = newMesh;

                        Material[] newMats = new Material[1];
                        newMats[0]   = mats[0];
                        mr.materials = newMats;
                    }
                    else
                    {
                        mr.materials = mats;
                    }
                }

#if UNITY_EDITOR
                UnityEditor.MeshUtility.Optimize(m);
#endif
                mf.mesh = m;
            }
        }