public override void Update() { if (selectingBlock) { if (Input.GetKeyDown(KeyCode.Escape)) { selectingBlock = false; Hide(false); } if (Input.GetMouseButtonDown(1)) // Right click { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition) , out hit)) { var obj = hit.transform; var b = obj.GetComponent <BlockBehaviour>(); if (b != null) { block = b.Guid; selectingBlock = false; Hide(false); OnBlockSelected?.Invoke(GetBlock()); } } } } }
/// <summary> /// Deletes an existing block from the diagram /// </summary> /// <param name="temp">The block to delete from the diagram</param> public void DeleteBlock(IConnectable temp) { // Remove from the renderables var obj = _objectMapping[temp]; _renderables.RemoveAt(_renderables.IndexOfValue(obj)); // Remove any objects that cannot be deleted normally // attached to this object. var cobj = obj as IDrawableIConnectable; if (cobj != null) { foreach (var mo in cobj.MappedObjects) { if (!mo.CanDelete) { _renderables.RemoveAt(_renderables.IndexOfValue(mo)); } } } // All other deletable objects are cleared by the Core before removing the parent // Change highlight as needed if (_lastSelect == obj) { _lastSelect = null; } if (_currentSelect == obj) { _currentSelect = null; _lastSelect = null; OnBlockSelected?.Invoke(this, null); } // Trigger a re-draw Render(); }
/// <summary> /// Selects a given object /// </summary> /// <param name="obj">The object to select</param> /// <returns>True if a render refresh needs to be performed</returns> private bool SelectObject(DrawableObject obj) { var needRefresh = false; _currentSelect = obj; // Highlight the selected object if (_lastSelect != null) { _lastSelect.Highlighted = false; needRefresh = true; } if (_currentSelect != null) { _currentSelect.Highlighted = true; needRefresh = true; } if (_currentSelect is IDrawableIConnectable) { OnBlockSelected?.Invoke(this, ((IDrawableIConnectable)_currentSelect).GetObject()); } return(needRefresh); }
public void OnPointerDown(PointerEventData eventData) { OnBlockSelected?.Invoke(this); }