/// <summary> /// Add a context button to top level menu /// </summary> void AddContextButton(OVRInspectorContextDetails details) { OVRInspectorContextDetails detailsCopy = details; Button button = leftPanel.AddButton(details.GetName(), delegate(Button b) { SelectContextButton(detailsCopy, b); }, buttonPrefab); if (details == currentContext) { SelectContextButton(details, button); } }
/// <summary> /// Register a new context for that will appear on the top level menu. /// </summary> /// <param name="context">Interface that will be used to build UI when this context is activated</param> /// <param name="subContextID">An ID that is passed back to the context. Useful if this interface supports more than one context</param> /// <param name="setCurrent">If true this context will be immediately activiated</param> public void RegisterContext(IOVRInspectorContext context, int subContextID, bool setCurrent = false) { OVRInspectorContextDetails contextDetails = new OVRInspectorContextDetails(context, subContextID); contextList.Add(contextDetails); if (currentContext == null || setCurrent) { ContextActivated(contextDetails); } UpdateTopMenu(); }
/// <summary> /// A context was activated /// </summary> void ContextActivated(OVRInspectorContextDetails contextDetails) { if (contextDetails != currentContext) { if (currentContext != null) { currentContext.SetContextActive(this, false); } currentContext = contextDetails; currentContext.SetContextActive(this, true); UpdateContextMenu(); } }
/// <summary> /// Handler for when a button is pressed /// </summary> void SelectContextButton(OVRInspectorContextDetails contextDetails, Button button = null) { if (lastSelectedContextButton) { lastSelectedContextButton.interactable = true; } lastSelectedContextButton = button; if (lastSelectedContextButton) { lastSelectedContextButton.interactable = false; } ContextActivated(contextDetails); }
/// <summary> /// Add already attached contexts to the meny system /// </summary> void SetupAttachedContexts() { foreach (Transform child in controlsPanel.panel.transform) { if (!IsLabeledDontMove(child.gameObject)) { OVRInspectorContextDetails contextDetails = new OVRInspectorContextDetails(child.gameObject); SetUIMaterials(child); contextList.Add(contextDetails); child.gameObject.SetActive(false); } } if (currentContext == null && contextList.Count > 0) { ContextActivated(contextList[0]); } }
/// <summary> /// Load the panels under this transform as contexts selectable in the top level menu /// </summary> /// <param name="panel">The parent panel</param> /// <param name="markAsSceneSpecific">Should these be marked as scene-specific so we know to remove them later</param> void LoadPanels(Transform panel, bool markAsSceneSpecific) { List <Transform> children = new List <Transform>(); foreach (Transform child in panel) { children.Add(child); } int prevNumContexts = contextList.Count; foreach (Transform child in children) { if (IsLabeledDontMove(child.gameObject)) { continue; } CullPlatformSpecificObjects(child.gameObject); // Move to our main UI panel child.SetParent(controlsPanel.scrollingContent.transform, false); OVRInspectorContextDetails contextDetails = new OVRInspectorContextDetails(child.gameObject); contextList.Add(contextDetails); child.gameObject.SetActive(false); if (markAsSceneSpecific) { sceneSpecificContexts.Add(contextDetails); } } if (contextList.Count > prevNumContexts) { // Activate the first new context ContextActivated(contextList[prevNumContexts]); } // Make sure menu reflects items UpdateTopMenu(); }