/// <summary> /// Creates mesh and material for this enemy. /// </summary> /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param> /// <param name="archive">Texture archive index derived from type and gender.</param> private void AssignMeshAndMaterial(DaggerfallUnity dfUnity, int archive) { // Get mesh filter if (meshFilter == null) { meshFilter = GetComponent <MeshFilter>(); } // Vertices for a 1x1 unit quad // This is scaled to correct size depending on facing and orientation float hx = 0.5f, hy = 0.5f; Vector3[] vertices = new Vector3[4]; vertices[0] = new Vector3(hx, hy, 0); vertices[1] = new Vector3(-hx, hy, 0); vertices[2] = new Vector3(hx, -hy, 0); vertices[3] = new Vector3(-hx, -hy, 0); // Indices int[] indices = new int[6] { 0, 1, 2, 3, 2, 1, }; // Normals Vector3 normal = Vector3.Normalize(Vector3.up + Vector3.forward); Vector3[] normals = new Vector3[4]; normals[0] = normal; normals[1] = normal; normals[2] = normal; normals[3] = normal; // Create mesh Mesh mesh = new Mesh(); mesh.name = string.Format("MobileEnemyMesh"); mesh.vertices = vertices; mesh.triangles = indices; mesh.normals = normals; // Assign mesh meshFilter.sharedMesh = mesh; // Seek textures from mods TextureReplacement.SetEnemyImportedTextures(archive, GetComponent <MeshFilter>(), ref summary.ImportedTextures); // Create material Material material; if (summary.ImportedTextures.HasImportedTextures) { material = MaterialReader.CreateStandardMaterial(MaterialReader.CustomBlendMode.Cutout); } else { material = dfUnity.MaterialReader.GetMaterialAtlas( archive, 0, 4, 1024, out summary.AtlasRects, out summary.AtlasIndices, 4, true, 0, false, true); } // Set new enemy material GetComponent <MeshRenderer>().sharedMaterial = material; }