private void OnActorEntryClicked(HierarchyActorEntry entry, HierarchyActorEntry.ActionType actionType) { if (onActorEntryClicked != null) { onActorEntryClicked(entry, actionType); } }
void OnActorEntryClicked(HierarchyActorEntry entry, HierarchyActorEntry.ActionType actionType) { // The user has clicked on an actor in the list. VoosActor actor = engine.GetActor(entry.GetActorName()); if (actor == null) { // Shouldn't happen. Debug.LogError("Clicked on actor that doesn't exist " + entry.GetActorName() + ". Bug?"); return; } if (selectCallback != null) { selectCallback(actor); selectCallback = null; return; } switch (actionType) { case HierarchyActorEntry.ActionType.SELECT: if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { AddActorToSelection(actor); } else { SelectActor(actor); } break; case HierarchyActorEntry.ActionType.INFO: SelectActor(actor, true); break; case HierarchyActorEntry.ActionType.MOVE: ToggleActorOffstage(actor); break; } }
private void OnActorClicked(HierarchyActorEntry entry, HierarchyActorEntry.ActionType actionType) { // TODO: we should not need to have actionType passed in CloseAndReturn(true, entry.GetActorName()); }
// NOTE: If this list contains a null, it will render as "[None]" and will be selectable. // This is useful if you want a "No actor" option to be on the list (if this is an actor picker). public void SetActors(IEnumerable <VoosActor> actors, bool sortByDistance = false) { // Lazily get EditMain if we're going to need it. if (sortByDistance) { Util.FindIfNotSet(this, ref editMain); } List <ActorInfo> actorInfos = new List <ActorInfo>(); foreach (VoosActor actor in actors) { if (actor != null && actor.IsSystemActor()) { // System actors don't appear on the list. continue; } actorInfos.Add(new ActorInfo(actor, editMain)); } actorInfos.Sort((a, b) => { // No actor. if (a.hierarchyPath.Count == 0) { return(-1); } if (b.hierarchyPath.Count == 0) { return(1); } // We want to sort by name / distance, but also make sure children are below parents. // Do this by comparing the children of the lowest common ancestor. // Go down the hierarchies until they are not the same. int i = 0; while (i + 1 < a.hierarchyPath.Count && i + 1 < b.hierarchyPath.Count && a.hierarchyPath[i].name == b.hierarchyPath[i].name) { i++; } if (a.hierarchyPath[i].name == b.hierarchyPath[i].name) { // One actor is the parent of another. Put the parent first. return(a.hierarchyPath.Count.CompareTo(b.hierarchyPath.Count)); } // The hierarchies have diverged. Now compare their names / distances. if (sortByDistance && editMain != null) { return(a.hierarchyPath[i].distance.CompareTo(b.hierarchyPath[i].distance)); } else { return(a.hierarchyPath[i].displayName.CompareTo(b.hierarchyPath[i].displayName)); } }); for (int i = 0; i < actorInfos.Count; i++) { HierarchyActorEntry entry; if (i < entries.Count) { // Recycle entry entry = entries[i]; } else { // Create new entry from template. GameObject clone = GameObject.Instantiate(entryPrefab); clone.SetActive(true); clone.transform.SetParent(listEntryParent.transform, false); entry = clone.GetComponent <HierarchyActorEntry>(); entry.EnableActionButtons(enableActionButtons); entry.SetDisableLockedActors(disableLockedActors); entry.AddClickListener(OnActorEntryClicked); entries.Add(entry); entry.onDrag += onActorDrag; } entry.SetActor(actorInfos[i].actor, actorInfos[i].hierarchyPath.Count - 1); entry.SetHighlighted(false); } // Delete unused entries. while (entries.Count > actorInfos.Count) { HierarchyActorEntry entry = entries[entries.Count - 1]; entry.RemoveClickListener(OnActorEntryClicked); entry.onDrag -= onActorDrag; GameObject.Destroy(entry.gameObject); entries.RemoveAt(entries.Count - 1); } UpdateDrag(); }