public override Object getCellPrefabFor(GameObject cell) { PrefabType type = PrefabUtility.GetPrefabType(cell); if (type == PrefabType.PrefabInstance) { return(PrefabUtility.GetPrefabObject(cell)); } Cell c = cell.GetComponent <Cell>(); string path = "Assets/CellPrefabs/" + Mathf.CeilToInt(c.Properties.height) + "/"; Object prefab = null; if (AssetDatabase.IsValidFolder(path)) { string[] prefabs = AssetDatabase.FindAssets(c.Properties.ToString(), new string[] { path }); if (prefabs != null && prefabs.Length > 0) { prefab = AssetDatabase.LoadAssetAtPath(prefabs[0], typeof(Object)); } } else { AssetDatabase.CreateFolder("Assets/CellPrefabs", Mathf.CeilToInt(c.Properties.height) + ""); } if (prefab == null) { prefab = PrefabUtility.CreateEmptyPrefab(path); CellProperties properties = c.Properties; /*Material myMat = new Material(Shader.Find("Transparent/Cutout/Diffuse")); * texture.filterMode = FilterMode.Point; * myMat.SetTexture("_MainTex", texture); * this.GetComponent<Renderer>().sharedMaterial = myMat;*/ } return(prefab); }
// Deserialization moment void Awake() { #if UNITY_EDITOR if (Application.isEditor && !Application.isPlaying) { // Code to prevent losing information from old versions if (faces != null && faces.Length != 0) { // The first time i have to initialize those FaceNoSC[] nfaces = new FaceNoSC[faces.Length]; for (int i = 0; i < faces.Length; i++) { if (faces[i] == null) { // Debug.Log("Null face detected at " + this + " at map " + Map); break; } nfaces[i] = new FaceNoSC(); nfaces[i].Texture = faces[i].Texture; nfaces[i].TextureMapping = faces[i].TextureMapping; } this.properties = new CellProperties(height, topType, cellTopRotation, 1, faces != null ? nfaces : new FaceNoSC[0]); Debug.Log("No era null"); faces = null; } } #endif // This will prevent older versions to lose face information about textures. /*if (this.faces == null) { * faces = new Face[faceTextures.Length]; * for (int i = 0; i< faces.Length; i++) { * faces[i].Texture = faceTextures[i]; * faces[i].TextureMapping = faceMappings[i]; * } * faceTextures = null; * faceMappings = null; * } */ }
private static void extractFacesFromMesh(Mesh mesh, CellProperties properties) { int numLateralFaces = Mathf.CeilToInt(properties.height) * 4; //Numero de vertices de la ultima capa int[] topFacesNumVertex = (properties.top == CellTopType.flat) ? new int[1] { 4 } : new int[4] { 3, 4, 3, 4 }; int verticesForThisFace; int totalVertices = 0; for (int i = 0; i < numLateralFaces + topFacesNumVertex.Length; i++) { // Calculamos cuantos vertices tendra la cara. Si es lateral 4 y sino, los que esten preestablecidos. verticesForThisFace = (i < numLateralFaces) ? 4 : topFacesNumVertex[i - numLateralFaces]; FaceNoSC.extractFaceInfoFromMesh(mesh, verticesForThisFace, totalVertices, properties.faces[i]); totalVertices += verticesForThisFace; } }
public override void Generate(CellProperties properties) { faces = regenerateFaces(properties.faces, properties.height, properties.top, properties.width, properties.orientation); texture = getTextureAndGenerateUVs(faces); mesh = generateMeshFromFaces(faces); }
public abstract void Generate(CellProperties properties);