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; }
/* ********** * * 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 static void initialize() { if (Camera.main == null) { GameObject camera = new GameObject(); camera.AddComponent <Camera>(); camera.name = "MainCamera"; camera.tag = "MainCamera"; GameObject.DontDestroyOnLoad(camera); } RenderSettings.ambientLight = Color.white; 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; }
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); }
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 static void createMap() { GameObject go = GameObject.Instantiate(IsoSettingsManager.getInstance().getIsoSettings().defaultMapPrefab) as GameObject; Selection.activeObject = go; }
public void updateTextures() { float scale = Mathf.Sqrt(2f) / IsoSettingsManager.getInstance().getIsoSettings().defautTextureScale.width; 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); Mesh mesh = this.GetComponent <MeshFilter>().mesh; 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 = new Material(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; }
public void OnSceneGUI(SceneView scene) { if (setPerspective) { /* Selection.transforms */ setPerspective = false; 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; if (fixView) { fixedRotation = Quaternion.Euler(angle, 45, 0); } scene.Repaint(); } if (fixView) { scene.LookAtDirect(scene.pivot, fixedRotation); } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); if (Event.current.isMouse) { if (Event.current.button == 0) { if (Event.current.type == EventType.MouseDown) { startCreatingCells(); } else if (Event.current.type == EventType.MouseUp) { endCreatingCells(); } else { createCell(); } } else if (Event.current.button == 1) { if (Event.current.type == EventType.MouseDown) { startMovingGrid(); } else if (Event.current.type == EventType.MouseUp) { endMovingGrid(); } else { moveGrid(); } } scene.Repaint(); } Vector3 centerGridPoint = map.getMousePositionOverMap(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), Mathf.RoundToInt(gridHeight * 2f) / 2f); map.ghostCell(centerGridPoint, 0.5f); Vector3[] puntos = new Vector3[4]; puntos[0] = new Vector3(centerGridPoint.x - cellSize / 2.0f, centerGridPoint.y, centerGridPoint.z - cellSize / 2.0f); puntos[1] = new Vector3(centerGridPoint.x - cellSize / 2.0f, centerGridPoint.y, centerGridPoint.z + cellSize / 2.0f); puntos[2] = new Vector3(centerGridPoint.x + cellSize / 2.0f, centerGridPoint.y, centerGridPoint.z + cellSize / 2.0f); puntos[3] = new Vector3(centerGridPoint.x + cellSize / 2.0f, centerGridPoint.y, centerGridPoint.z - cellSize / 2.0f); Handles.DrawSolidRectangleWithOutline(puntos, Color.yellow, Color.white); }