public void Render(Rect pos, T currentObj, Action <T> onUpdated, Func <T, bool> filter = null) { // render content var content = currentObj == null ? new GUIContent("None") : _showIcon ? new GUIContent(currentObj.name, Icons.ByComponent(currentObj, IconSize.Small, IconColor)) : new GUIContent(currentObj.name); // render drawer var id = GUIUtility.GetControlID(FocusType.Keyboard, pos); var objectFieldButton = GUI.skin.GetStyle("ObjectFieldButton"); var suffixButtonPos = new Rect(pos.xMax - 19f, pos.y + 1, 19f, pos.height - 2); EditorGUIUtility.SetIconSize(new Vector2(12f, 12f)); // handle click if (Event.current.type == EventType.MouseDown && pos.Contains(Event.current.mousePosition)) { if (currentObj != null && !suffixButtonPos.Contains(Event.current.mousePosition)) { // click on ping var mb = currentObj as MonoBehaviour; if (mb) { EditorGUIUtility.PingObject(mb.gameObject); } } else { // click on picker _itemPickDropdownState ??= new AdvancedDropdownState(); var dropdown = new ItemSearchableDropdown <T>( _itemPickDropdownState, _tableComp, _pickerTitle, onUpdated, filter ); dropdown.Show(pos); } } if (Event.current.type == EventType.Repaint) { EditorStyles.objectField.Draw(pos, content, id, DragAndDrop.activeControlID == id, pos.Contains(Event.current.mousePosition)); objectFieldButton.Draw(suffixButtonPos, GUIContent.none, id, DragAndDrop.activeControlID == id, suffixButtonPos.Contains(Event.current.mousePosition)); } }
private void RenderPlayfieldElement(TableAuthoring tableAuthoring, SwitchListData switchListData, Rect cellRect, Action <SwitchListData> updateAction) { if (GUI.Button(cellRect, switchListData.PlayfieldItem, EditorStyles.objectField) || GUI.Button(cellRect, "", GUI.skin.GetStyle("IN ObjectField"))) { if (_itemPickDropdownState == null) { _itemPickDropdownState = new AdvancedDropdownState(); } var dropdown = new ItemSearchableDropdown <ISwitchableAuthoring>( _itemPickDropdownState, tableAuthoring, "Switchable Items", item => { switchListData.PlayfieldItem = item.Name; updateAction(switchListData); } ); dropdown.Show(cellRect); } }
private void RenderDestinationElementDevice(TableAuthoring tableAuthoring, WireListData wireListData, Rect cellRect, Action <WireListData> updateAction) { if (GUI.Button(cellRect, wireListData.DestinationDevice, EditorStyles.objectField) || GUI.Button(cellRect, "", GUI.skin.GetStyle("IN ObjectField"))) { if (_destinationElementDeviceDropdownState == null) { _destinationElementDeviceDropdownState = new AdvancedDropdownState(); } var dropdown = new ItemSearchableDropdown <ICoilDeviceAuthoring>( _destinationElementDeviceDropdownState, tableAuthoring, "Coil Devices", item => { wireListData.DestinationDevice = item.Name; updateAction(wireListData); } ); dropdown.Show(cellRect); } }
private void RenderSourceElementPlayfield(TableAuthoring tableAuthoring, WireListData wireListData, Rect cellRect, Action <WireListData> updateAction) { if (GUI.Button(cellRect, wireListData.SourcePlayfieldItem, EditorStyles.objectField) || GUI.Button(cellRect, "", GUI.skin.GetStyle("IN ObjectField"))) { if (_sourceElementDeviceDropdownState == null) { _sourceElementDeviceDropdownState = new AdvancedDropdownState(); } var dropdown = new ItemSearchableDropdown <ISwitchAuthoring>( _sourceElementDeviceDropdownState, tableAuthoring, "Switch Items", item => { wireListData.SourcePlayfieldItem = item.Name; updateAction(wireListData); } ); dropdown.Show(cellRect); } }