/* ********** * * CRUD Zone * * ********** */ public GameObject addCell(Vector3 position) { checkTransform(); // Creating the gameObject #if UNITY_EDITOR GameObject go = UnityEditor.PrefabUtility.InstantiatePrefab(IsoSettingsManager.getInstance().getIsoSettings().defaultCellPrefab) as GameObject; #else GameObject go = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultCellPrefab); #endif // Getting the localPosition position = m_transform.InverseTransformPoint(position); // Setting base properties Cell cell = go.GetComponent <Cell>(); cell.Map = this; cell.transform.localPosition = new Vector3(position.x, 0, position.z); cell.Height = position.y; cell.Width = cellSize; cell.forceRefresh(); //Añado la celda al conjunto de celdas //La refresco updateCell(cell, true); return(go); }
public void ghostCell(Vector3 position, float intensity) { checkTransform(); if (ghost == null || ghostType != 1) { removeGhost(); ghostType = 1; instanciatingGhost = true; ghost = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultCellPrefab) as GameObject; ghost.name = "Ghost"; ghost.hideFlags = HideFlags.HideAndDontSave; ghost.GetComponent <Cell>().Map = this; instanciatingGhost = false; } // Getting the localPosition position = m_transform.InverseTransformPoint(position); Cell cell = ghost.GetComponent <Cell>(); cell.Width = cellSize; //La refresco Vector2 coords = getCoords(position); cell.Height = position.y; cell.transform.localPosition = new Vector3((coords.x + 0.5f) * cellSize, 0, (coords.y + 0.5f) * cellSize); Material mat = new Material(Shader.Find("Transparent/Diffuse")); mat.color = new Color(mat.color.r, mat.color.g, mat.color.b, intensity); ghost.GetComponent <Renderer>().sharedMaterial = mat; }
public static void createMap(MenuCommand menuCommand) { #if UNITY_EDITOR GameObject go = UnityEditor.PrefabUtility.InstantiatePrefab(IsoSettingsManager.getInstance().getIsoSettings().defaultMapPrefab) as GameObject; #else GameObject go = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultMapPrefab); #endif Selection.activeObject = go; }
public GameObject addDecoration(Vector3 position, int angle, bool parallel, bool centered, IsoDecoration dec) { GameObject newdecoration = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultDecorationPrefab) as GameObject; newdecoration.name = "Decoration (clone)"; newdecoration.GetComponent <Renderer>().sharedMaterial = new Material(Shader.Find("Transparent/Cutout/Diffuse")); newdecoration.GetComponent <Decoration>().Father = this; Decoration der = newdecoration.GetComponent <Decoration>(); der.IsoDec = dec; der.setParameters(position, angle, parallel, centered); return(newdecoration); }
void Start() { base.Start(); if (Camera.main == null) { GameObject camera = new GameObject(); camera.AddComponent <Camera>(); camera.AddComponent <AudioListener>(); camera.name = "MainCamera"; camera.tag = "MainCamera"; } if (initializeCameraOnStart) { Camera.main.orthographic = true; Texture2D baseTile = IsoSettingsManager.getInstance().getIsoSettings().defautTextureScale; float angle = 30; if (baseTile != null) { float angulo = Mathf.Rad2Deg * Mathf.Acos(baseTile.height / (baseTile.width * 1f)); angle = 90f - angulo; } Camera.main.transform.rotation = Quaternion.Euler(angle, 45, 0); separation = new Vector3(0, 0, distance); separation = Quaternion.Euler(angle, 45, 0) * separation; speed = Vector3.zero; } if (this.look == null) { Player player = FindObjectOfType <Player>(); if (player != null) { this.look = player.gameObject; MapManager.getInstance().setActiveMap(player.Entity.Position.Map); } } Flush(); RenderSettings.ambientLight = Color.black; }
private void setPerspective(SceneView scene) { /* Selection.transforms */ float angle = 30; Texture baseTile = IsoSettingsManager.getInstance().getIsoSettings().defautTextureScale; if (baseTile != null) { float angulo = Mathf.Rad2Deg * Mathf.Acos(baseTile.height / (baseTile.width * 1f)); angle = 90f - angulo; } scene.LookAtDirect(scene.pivot, Quaternion.Euler(angle, 45, 0)); scene.orthographic = true; scene.Repaint(); }
void OnEnable() { this.map = (Map)target; /*this.modules = new MapEditorModule[]{ * new NothingModule(), * new EditModule(), * new PaintModule(), * new DecorateModule(), * new EntityModule() * };*/ List <MapEditorModule> modules = new List <MapEditorModule>(); var type = typeof(MapEditorModule); Assembly[] assembly = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly a in assembly) { foreach (Type t in a.GetTypes()) { if (type.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract) { modules.Add(Activator.CreateInstance(t) as MapEditorModule); } } } modules.Sort(new ModuleComparision()); this.modules = modules.ToArray() as MapEditorModule[]; this.selected = 0; toolBarStyle = new GUIStyle(); toolBarStyle.margin = new RectOffset(50, 50, 5, 10); IsoSettings iso = IsoSettingsManager.getInstance().getIsoSettings(); if (!iso.Configured) { IsoSettingsPopup.ShowIsoSettingsPopup(iso); } }
public GameObject addGhost(Vector3 position, int angle, bool parallel, bool centered, IsoDecoration dec, float intensity) { if (this.ghost == null) { ghost = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultDecorationPrefab) as GameObject; ghost.name = "GhostDer"; ghost.hideFlags = HideFlags.HideAndDontSave; Material ghostMaterial = new Material(Shader.Find("Transparent/Diffuse")); ghostMaterial.color = new Color(ghostMaterial.color.r, ghostMaterial.color.g, ghostMaterial.color.b, intensity); ghost.GetComponent <Renderer>().sharedMaterial = ghostMaterial; } Decoration der = ghost.GetComponent <Decoration>(); der.Father = this; der.IsoDec = dec; der.setParameters(position, angle, parallel, centered); return(this.ghost); }
public void updateTextures(bool regenerateMesh) { float scale = Mathf.Sqrt(2f) / IsoSettingsManager.getInstance().getIsoSettings().defautTextureScale.width; if (regenerateMesh) { Mesh mesh = new Mesh(); mesh.vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, 0), new Vector3(0.5f, 0.5f, 0), new Vector3(0.5f, -0.5f, 0), new Vector3(-0.5f, 0.5f, 0) }; mesh.uv = new Vector2[] { Vector2.zero, Vector2.one, new Vector2(1, 0), new Vector2(0, 1) }; mesh.triangles = new int[] { 0, 1, 2, 3, 1, 0 }; mesh.normals = new Vector3[] { new Vector3(0, 0, -0.5f), new Vector3(0, 0, -0.5f), new Vector3(0, 0, -0.5f), new Vector3(0, 0, -0.5f) }; mesh.RecalculateBounds(); mesh.RecalculateTangents(); this.GetComponent <MeshFilter>().sharedMesh = mesh; this.transform.localScale = new Vector3(isoDec.getTexture().width *scale / ((float)isoDec.nCols), (isoDec.getTexture().height *scale) / ((float)isoDec.nRows), 1); if (!parallel) { this.transform.localScale = new Vector3(this.transform.localScale.x, this.transform.localScale.y / Mathf.Sin(45f), 1); } else { if (this.angle == 0) { this.transform.localScale = new Vector3(this.transform.localScale.x, this.transform.localScale.y * 2f, 1); } else { this.transform.localScale = new Vector3(Mathf.Sqrt(2f * (this.transform.localScale.x * this.transform.localScale.x)), this.transform.localScale.y / Mathf.Sin(45f), 1); if (quadVertices == null) { quadVertices = new Vector3[mesh.vertices.Length]; for (int i = 0; i < mesh.vertices.Length; i++) { quadVertices[i] = new Vector3(mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z); } } Vector3[] vertices = new Vector3[quadVertices.Length]; for (int i = 0; i < quadVertices.Length; i++) { vertices[i] = new Vector3(quadVertices[i].x, quadVertices[i].y, quadVertices[i].z); } float xprima = this.transform.localScale.x; float omega = xprima * 0.57735026f; float gamma = omega / (this.transform.localScale.y * Mathf.Sqrt(2)); Vector3 bajada = new Vector3(0, gamma, 0); if (this.angle == 2) { vertices[0] -= bajada; vertices[3] -= bajada; } else if (this.angle == 1) { vertices[1] -= bajada; vertices[2] -= bajada; } mesh.vertices = vertices; this.GetComponent <MeshFilter>().sharedMesh = mesh; } } } Material myMat = this.GetComponent <Renderer>().sharedMaterial; myMat.mainTextureScale = new Vector2(1f / ((float)isoDec.nCols), 1f / ((float)isoDec.nRows)); myMat.mainTextureOffset = new Vector2(0, 1 - 1f / ((float)isoDec.nRows)); myMat.SetTexture("_MainTex", isoDec.getTexture()); this.GetComponent <Renderer>().sharedMaterial = myMat; int x = tile % (isoDec.nCols); int y = Mathf.FloorToInt(tile / (float)isoDec.nCols); this.GetComponent <Renderer>().sharedMaterial.mainTextureOffset = new Vector2((x / ((float)isoDec.nCols)), (y / ((float)isoDec.nRows))); }