/// <summary> /// Automatically activate tile system from user selection if appropriate so that /// tool can be selected. /// </summary> private void AutoActivateTileSystem() { ToolUtility.SelectActiveOrParentTileSystem(); if (ToolUtility.ActiveTileSystem == null) { // Okay, no tile system is actually selected. // Select first non-locked if possible; otherwise select first if possible. var tileSystems = ToolUtility.GetAllTileSystemsInScene(); var firstTileSystem = tileSystems.FirstOrDefault(s => s != null && !s.Locked); if (firstTileSystem == null) { firstTileSystem = tileSystems.FirstOrDefault(s => s != null); } if (firstTileSystem != null) { ToolUtility.SelectTileSystem(firstTileSystem); } else { return; } } // When using a tool it only makes sense to have one selected tile system. if (Selection.objects.Length > 1) { Selection.objects = new Object[] { ToolUtility.ActiveTileSystem.gameObject }; } }
private void DrawTileSystemList() { this.AutoInitializeTileSystemsListControl(); Rect scrollViewPosition = new Rect(0, 0, position.width, position.height); scrollViewPosition.yMin = GUILayoutUtility.GetLastRect().yMax; if (Event.current.type == EventType.Repaint) { this.scrollViewPosition = scrollViewPosition; } Rect listControlPosition = new Rect(0, 0, scrollViewPosition.width, this.systemsListControl.CalculateListHeight(this.systemsListAdaptor)); Rect viewRect = listControlPosition; viewRect.height += 7; if (viewRect.height > scrollViewPosition.height) { viewRect.width -= GUI.skin.verticalScrollbar.fixedWidth + GUI.skin.verticalScrollbar.margin.horizontal; } bool isMouseDownEvent = Event.current.type == EventType.MouseDown; try { this.scrollPosition = GUI.BeginScrollView(scrollViewPosition, this.scrollPosition, viewRect); this.systemsListControl.Draw(listControlPosition, this.systemsListAdaptor); GUI.EndScrollView(); } finally { if (isMouseDownEvent) { this.systemsListAdaptor.CanBeginEditingNameOnMouseUp = true; } } // Clear selection when mouse is clicked in empty area of list. if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { if (scrollViewPosition.Contains(Event.current.mousePosition)) { ToolUtility.SelectTileSystem(null); Event.current.Use(); } } }
private void OnKeyboardGUI() { if (Event.current.GetTypeForControl(ReorderableListControl.CurrentListControlID) != EventType.KeyDown) { return; } int index = this.entries.FindIndex(entry => entry.TileSystem == ToolUtility.ActiveTileSystem); int newIndex = index; switch (Event.current.keyCode) { case KeyCode.UpArrow: if (index == -1) { newIndex = this.entries.Count - 1; } else { newIndex = Mathf.Max(0, newIndex - 1); } break; case KeyCode.DownArrow: if (index == -1) { newIndex = 0; } else { newIndex = Mathf.Min(this.entries.Count - 1, newIndex + 1); } break; case KeyCode.Home: newIndex = 0; break; case KeyCode.End: newIndex = this.entries.Count - 1; break; case KeyCode.Delete: if (ToolUtility.ActiveTileSystem != null && !ToolUtility.ActiveTileSystem.Locked) { Undo.DestroyObjectImmediate(ToolUtility.ActiveTileSystem.gameObject); this.RepaintParentWindow(); Event.current.Use(); } break; } // Alter active tile system? if (newIndex != index) { if (this.entries.Count == 0) { ToolUtility.SelectTileSystem(null); } else { if (newIndex < 0) { newIndex = this.entries.Count - 1; } else if (newIndex >= this.entries.Count) { newIndex = 0; } ToolUtility.SelectTileSystem(this.entries[newIndex].TileSystem); } Event.current.Use(); } }
private void DrawItem_TileSystem(Rect position, int index, TileSystem system) { bool isActiveSystem = system == ToolUtility.ActiveTileSystem; int itemControlID = GUIUtility.GetControlID(FocusType.Passive); Rect totalPosition = ReorderableListGUI.CurrentItemTotalPosition; if (this.itemPositions == null || this.itemPositions.Length != this.entries.Count) { this.itemPositions = new Rect[this.entries.Count]; } this.itemPositions[index] = ReorderableListGUI.CurrentItemTotalPosition; Rect eyeButtonPosition = new Rect(position.x, totalPosition.y + (totalPosition.height - 18) / 2f, 21, 18); int eyeButtonControlID = GUIUtility.GetControlID(FocusType.Passive); Rect totalLabelPosition = new Rect(position.x, totalPosition.y, totalPosition.xMax - position.x, totalPosition.height); totalLabelPosition.x += eyeButtonPosition.width + 3; totalLabelPosition.width -= eyeButtonPosition.width + 3; Rect labelPosition = totalLabelPosition; labelPosition.height -= 1; var eventType = Event.current.GetTypeForControl(itemControlID); if (eventType == EventType.Repaint) { GUI.DrawTexture(eyeButtonPosition, system.gameObject.activeInHierarchy ? RotorzEditorStyles.Skin.EyeOpen : RotorzEditorStyles.Skin.EyeShut); string systemName = this.IsEditingName && this.renameIndex == index ? "" : system.name; RotorzEditorStyles.Instance.ListLargeElement.Draw(labelPosition, systemName, false, false, isActiveSystem, false); if (system.Locked) { Rect lockIconPosition = new Rect(labelPosition.xMax - 28, labelPosition.y + 5, 12, 15); GUI.DrawTexture(lockIconPosition, isActiveSystem ? RotorzEditorStyles.Skin.LockActive : RotorzEditorStyles.Skin.Lock); } } if (isActiveSystem) { this.RenameField(labelPosition, system); } if (this.IsEditingName) { return; } switch (eventType) { case EventType.MouseDown: if (Event.current.button == 0) { if (eyeButtonPosition.Contains(Event.current.mousePosition)) { this._wantsToBeginEditingName = false; Undo.RecordObject(system.gameObject, TileLang.ParticularText("Action", "Toggle Visibility")); system.gameObject.SetActive(!system.gameObject.activeSelf); Event.current.Use(); break; } bool wasTileSystemAlreadySelected = isActiveSystem || (Selection.activeGameObject == system.gameObject && Selection.objects.Length == 1); if (!wasTileSystemAlreadySelected) { if (Event.current.clickCount == 1 && totalPosition.Contains(Event.current.mousePosition)) { // Ensure that tile system is selected. ToolUtility.SelectTileSystem(system); } } if (totalLabelPosition.Contains(Event.current.mousePosition)) { this._wantsToBeginEditingName = false; if (Event.current.clickCount == 2) { Selection.objects = new Object[] { system.gameObject }; SceneView.lastActiveSceneView.FrameSelected(); } else { this.mouseDownPosition = Event.current.mousePosition; // Should game object of tile system be selected? if (wasTileSystemAlreadySelected) { this._wantsToBeginEditingName = this.CanBeginEditingNameOnMouseUp; } GUIUtility.hotControl = itemControlID; GUIUtility.keyboardControl = 0; } Event.current.Use(); } } else if (Event.current.button == 1) { if (totalPosition.Contains(Event.current.mousePosition)) { ToolUtility.SelectTileSystem(system); Event.current.Use(); GUIUtility.hotControl = itemControlID; GUIUtility.keyboardControl = 0; } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == itemControlID && Event.current.button == 0) { if (Vector2.Distance(this.mouseDownPosition, Event.current.mousePosition) >= DragThresholdInPixels) { GUIUtility.hotControl = 0; this.StartDrag(system); } Event.current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == itemControlID || GUIUtility.hotControl == eyeButtonControlID) { if (totalPosition.Contains(Event.current.mousePosition)) { if (Event.current.button == 0 && GUIUtility.hotControl == itemControlID) { // Consider entering rename mode? if (isActiveSystem && this._wantsToBeginEditingName) { CallbackSchedulerUtility.SetTimeout(() => { if (this._wantsToBeginEditingName) { this.BeginEditingName(system); } }, 0.5); } } else if (Event.current.button == 1) { this.ShowContextMenu(system); } } GUIUtility.hotControl = 0; Event.current.Use(); } break; } }