// マウスカーソル位置のブロックを取得 private bool GetCursorPoint(out Point point) { point = new Point(); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { point.normal = hit.normal; point.gameObject = hit.transform.gameObject; point.position = EditUtil.ResolvePosition(hit.point - point.normal * 0.25f); point.meshId = (int)hit.textureCoord2.x; return(true); } point.position = Vector3.zero; point.normal = Vector3.zero; point.gameObject = null; return(false); }
public void Update() { bool visible = false; // マウスカーソルの処理 Point point; bool cursorEnabled = this.GetCursorPoint(out point); this.block = null; this.model = null; if (point.gameObject != null) { var layer = point.gameObject.GetComponent <EditLayer>(); if (layer != null) { if (layer == EditManager.Instance.CurrentLayer) { this.block = layer.GetBlock(point.position); } } else { this.model = EditManager.Instance.CurrentLayer.GetModel(point.gameObject); } } switch (EditManager.Instance.GetTool()) { case EditManager.Tool.Block: if (cursorEnabled) { // 手前に立体カーソルを置く visible = true; this.point = EditUtil.ResolvePosition(point.position + new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z)); this.transform.position = this.point; this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.blockDirection), Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.Eraser: case EditManager.Tool.PointSelector: if (cursorEnabled) { // 立体カーソルを置く if (this.block != null) { visible = true; this.point = point.position; this.SetBlock(); this.transform.position = point.position; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } else if (this.model != null) { visible = true; this.point = point.position; this.SetModelBound(this.model); this.transform.position = this.model.position; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } } break; case EditManager.Tool.Brush: case EditManager.Tool.Spuit: if (cursorEnabled && this.block != null) { this.point = point.position; // 面カーソルを置く visible = true; this.panelDirection = EditUtil.VectorToDirection(point.normal); Mesh mesh = this.block.GetMesh(this.panelDirection); if (mesh != null) { // 面が選択されている this.objectSelected = false; this.SetMesh(mesh); } else { mesh = this.block.GetObjectMesh(); if (mesh != null) { // オブジェクトが選択されている this.objectSelected = true; this.SetMesh(mesh); } else { this.SetBlock(); } } Vector3 position = point.position + point.normal * 0.01f; this.transform.position = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y * 2.0f) * 0.5f, Mathf.Round(position.z)); this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.block.direction) + 180.0f, Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.Model: if (cursorEnabled) { // 手前に立体カーソルを置く visible = true; this.point = EditUtil.ResolvePosition(point.position + new Vector3(point.normal.x, point.normal.y * 0.5f, point.normal.z)); this.transform.position = this.point; this.transform.rotation = Quaternion.AngleAxis( EditUtil.DirectionToAngle(this.blockDirection), Vector3.up); this.transform.localScale = Vector3.one; } break; case EditManager.Tool.RoutePath: case EditManager.Tool.MetaInfo: if (cursorEnabled && this.block != null && EditUtil.VectorToDirection(point.normal) == BlockDirection.Yplus ) { this.point = point.position; visible = true; // 面カーソルを置く this.SetPanel(); Vector3 position = point.position + point.normal * 0.01f; this.transform.position = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y * 2.0f) * 0.5f + 0.25f, Mathf.Round(position.z)); this.panelDirection = BlockDirection.Yplus; this.transform.rotation = Quaternion.identity; this.transform.localScale = Vector3.one; } break; } this.visible = visible; this.guide.gameObject.SetActive(visible); }