public bool RemoveSelectionContainsListner(GameObject go, SelectionContains listener) { if (!SelectionContainsListeners.ContainsKey(go)) { return(false); } return(SelectionContainsListeners[go].Remove(listener)); }
/// <summary> /// Adds a listner for an gameobject. If this gameobject is selected, the listner will be invoked /// </summary> /// <param name="go">the gameobject on which the listener should be registered</param> /// <param name="listener">the listener it self</param> /// <returns>the SelectionContains delgate which was given to this function</returns> public SelectionContains AddSelectionContainsListener(GameObject go, SelectionContains listener) { if (!SelectionContainsListeners.ContainsKey(go)) { SelectionContainsListeners.Add(go, new List <SelectionContains>()); } SelectionContainsListeners[go].Add(listener); return(listener); }
/// <summary> /// Adds an object to the selection, changes the shader and shows and hides the appropriate canvas /// </summary> /// <param name="go">The Gameobject which is added</param> protected void AddObjectToSelection(GameObject go, bool invokeSelectionChangeEvent = true) { if (selectedObjects.Contains(go)) { return; } if (go == null) { return; } Selectable selectable = go.GetComponent <Selectable>(); if (selectable == null) { throw new Exception("You tried to Add an GameObject which hans't a Selectable component on it: (Gameobject: " + go + ")"); } selectable.SetShader(); selectedObjects.Add(go); if (selectedObjects.Count == 1) { ShowObjectUi(selectedObjects.First()); } else if (!eventSystem.IsPointerOverGameObject()) { HideObjectUi(); } if (SelectionContainsListeners.ContainsKey(go)) { foreach (var l in SelectionContainsListeners[go]) { l.Invoke(go, selectedObjects.AsReadOnly()); } } if (invokeSelectionChangeEvent && ChangeSelectionEvent != null) { ChangeSelectionEvent.Invoke(Array.AsReadOnly(new GameObject[] { go }), Array.AsReadOnly(new GameObject[] {}), SelectedObjects); } }