public void InitCanavas() { this.Canvas = new Canvas() { Width = CHARACTER_COLUMNS * BRAILLE_WIDTH_DISP, Height = CHARACTER_ROWS * BRAILLE_HEIGHT_DISP, Margin = new Thickness(MARGIN_WIDTH_DISP, MARGIN_HEIGHT_DISP, MARGIN_WIDTH_DISP, MARGIN_HEIGHT_DISP), Background = Brushes.Transparent, UseLayoutRounding = true, Cursor = Cursors.IBeam, IsEnabled = true }; window.PreviewKeyDown += new KeyEventHandler(KeyPressed); window.TextInput += new TextCompositionEventHandler(TextInput); Canvas.MouseLeftButtonDown += new MouseButtonEventHandler(LeftMouseButtonPressed); this.EditorContainer.Children.Add(Canvas); for (int i = 0; i < CHARACTER_ROWS; i++) { for (int j = 0; j < CHARACTER_COLUMNS; j++) { double xPos = j * BRAILLE_WIDTH_DISP + BRAILLE_WIDTH_DISP / 4; double yPos = i * BRAILLE_HEIGHT_DISP + BRAILLE_HEIGHT_DISP / 2; TextBlock letter = new TextBlock(); letter.UseLayoutRounding = true; letter.Text = " "; Ellipse dot = new Ellipse(); dot.Style = DotStyle; letter.Style = LetterStyle; Canvas.SetLeft(letter, xPos); Canvas.SetTop(letter, yPos - 3 * FACTOR); Canvas.SetLeft(dot, xPos); Canvas.SetTop(dot, yPos); Letters[i, j] = letter; Dots[i, j] = dot; Canvas.Children.Add(dot); Canvas.Children.Add(letter); } } for (int i = 0; i < CHARACTER_ROWS; i++) { Symbols[i] = new List <BrailleSymbolSlotPosition>(); Characters[i] = new List <BrailleCharacter>(); } Cursor = new EditorCursor(window, Canvas); }
public void Init(EditableMesh mesh, MeshSelection sel, EditorCursor cursor) { m_EditMesh = mesh; m_MeshTr = m_EditMesh.transform; m_Selection = sel; m_Cursor = cursor; m_WorldPos = m_MeshTr.position; m_WorldRot = m_MeshTr.rotation; //m_PivotOp = PivotOp.Midian; //m_Orient = Orientation.Local; MeshUndoer.AddDeleMeshModified(this._OnMeshModified); m_Selection.evtSelectionChanged += this._OnSelectionChanged; EditorCursor.evtCursorPosChanged += this._OnCursorPosChanged; }
void OnSceneGUI() { EditorCursor cursor = (EditorCursor)target; Handles.color = Color.red; if (cursor.load) { cursor.load = false; LevelScript scriptLoaded = Resources.Load <LevelScript>(cursor.savePath); if (scriptLoaded) { cursor.events = scriptLoaded.events; } else { Debug.Log("Could not load LevelScript"); } return; } if (cursor.add) { if (cursor.addAt <= cursor.events.Length && cursor.addAt >= 0) { LevelScript.LevelEvent[] temp = cursor.events; cursor.events = new LevelScript.LevelEvent[cursor.events.Length + 1]; int ptr = 0; for (; ptr < cursor.addAt; ptr++) { cursor.events[ptr] = temp[ptr]; } cursor.events[ptr++] = new LevelScript.LevelEvent(); for (; ptr <= temp.Length; ptr++) { cursor.events[ptr] = temp[ptr - 1]; } } cursor.add = false; return; } if (cursor.remove) { if (cursor.removeAt < cursor.events.Length && cursor.removeAt >= 0 && cursor.events.Length > 0) { LevelScript.LevelEvent[] temp = cursor.events; cursor.events = new LevelScript.LevelEvent[cursor.events.Length - 1]; int ptr = 0; for (; ptr < cursor.removeAt; ptr++) { cursor.events[ptr] = temp[ptr]; } ptr++; for (; ptr < temp.Length; ptr++) { cursor.events[ptr - 1] = temp[ptr]; } } cursor.remove = false; return; } //get mouse position: Vector2 mousePosition = Event.current.mousePosition; mousePosition.y = SceneView.currentDrawingSceneView.camera.pixelHeight - mousePosition.y; mousePosition = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(mousePosition + new Vector2(0f, -70f)) * 1.25f; EditorGUI.BeginChangeCheck(); float size = Camera.current != null ? SceneView.currentDrawingSceneView.camera.orthographicSize : 10; cursor.transform.position = mousePosition; Handles.Label(mousePosition + new Vector2(0.05f, 0.1f) * size, "x: " + mousePosition.x + "\ny: " + mousePosition.y); if (cursor.save) { Debug.Log("save"); cursor.scriptToSave = CreateInstance <LevelScript>(); cursor.scriptToSave.events = cursor.events; AssetDatabase.CreateAsset(cursor.scriptToSave, "Assets/Resources/" + cursor.savePath + ".asset"); AssetDatabase.SaveAssets(); cursor.save = false; } EditorGUI.EndChangeCheck(); }