private void CreateViewAsOverlay(System.Type view, object data) { AbstractView overlay = CreateView(_assetLookup[view], ViewDisplayMode.Overlay) as AbstractView; _showingOverlays.Add(overlay); overlay._Show(data); }
/// <summary> /// Close the specified view. /// </summary> /// <param name="view">The view to close.</param> public void CloseOverlay(AbstractView view) { if (IsOverlayOpen(view)) { view._Hide(); } }
/// <summary> /// Opens the specified view as an overlay. /// </summary> /// <param name="view">Type of view we want to open.</param> /// <param name="data">Optional data <c>object</c> to be passed onto the view when it's shown.</param> /// <param name="close">Optional view to close before opening the target view.</param> public void OpenOverlay(System.Type view, object data = null, AbstractView waitForViewToClose = null) { if (_controller != null) { _controller.OpenOverlay(view, data, waitForViewToClose); } }
/// <summary> /// Open the specified view as an overlay. You can open multiple overlays of the same view type if required. /// </summary> /// <param name="view">The type of view to open as an overlay.</param> /// <param name="data">Data to pass onto the specified view when it begins to show <c>OnShowStart</c>.</param> /// <param name="waitForViewToClose">If set the <c>ViewController</c> will first hide this view (assuming it's showing as an overlay) before opening the specified view. This mimics the location system.</param> public void OpenOverlay(System.Type view, object data, AbstractView waitForViewToClose) { if (!HasView(view)) { throw new UnityException(string.Format("Invalid view type: {0}", view)); } if (_debug) { Debug.LogFormat("[ViewController] Requesting Overlay: {0}", view.Name); } if (EventViewRequested != null) { EventViewRequested(this, view, ViewDisplayMode.Overlay); } if (waitForViewToClose != null && IsOverlayOpen(waitForViewToClose)) { _targetOverlay = view; _targetOverlayData = data; CloseOverlay(waitForViewToClose); } else { CreateViewAsOverlay(view, data); } }
/// <summary> /// Closes the specified view when showing as an overlay. /// </summary> /// <param name="view">The view we want to close.</param> public void CloseOverlay(AbstractView view) { if (_controller != null) { _controller.CloseOverlay(view); } }
private void CreateViewAsLocation(System.Type view, object data) { // remove last location if (_currentLocation != null) { _lastLocation = _currentLocation.GetType(); } // create next location _currentLocation = CreateView(_assetLookup[view], ViewDisplayMode.Location); _currentLocation._Show(data); }
internal void _OnHideComplete(AbstractView view, bool destroy = true) { if (view == null) { throw new UnityException("View cannot be null"); } if (_debug) { Debug.LogFormat("[ViewController] Hide Complete: {0}, destroy: {1}", view.ToString(), destroy); } if (EventHideComplete != null) { EventHideComplete(this, view.GetType(), view.displayMode); } if (destroy) { view.DestroyView(); } if (view.displayMode == ViewDisplayMode.Overlay) { // remove overlay from showing list if (_showingOverlays.Contains(view)) { _showingOverlays.Remove(view); } // process next overlay if one is queued if (_targetOverlay != null) { CreateViewAsOverlay(_targetOverlay, _targetOverlayData); // clear data _targetOverlay = null; _targetOverlayData = null; } } else if (view.displayMode == ViewDisplayMode.Location) { // process next location is one is queued if (view == _currentLocation && _targetLocation != null) { CreateViewAsLocation(_targetLocation, _targetLocationData); // clear data _targetLocation = null; _targetLocationData = null; } } }
internal void _OnHideStart(AbstractView view) { if (_debug) { Debug.LogFormat("[ViewController] Hide Start: {0}", view.ToString()); } if (view != null && EventHideStart != null) { EventHideStart(this, view.GetType(), view.displayMode); } }
internal void _OnShowComplete(AbstractView view) { if (_debug) { Debug.LogFormat("[ViewController] Show Complete: {0}", view.ToString()); } if (view != null && EventShowComplete != null) { EventShowComplete(this, view.GetType(), view.displayMode); } }
public static void CreateViewAsset(SerializedProperty property, AbstractView view) { string assetPath = AssetDatabase.GetAssetPath(view); SerializedProperty propertyViewTypeID = property.FindPropertyRelative("viewTypeID"); SerializedProperty propertyResourcePath = property.FindPropertyRelative("resourcePath"); SerializedProperty propertyAssetID = property.FindPropertyRelative("assetID"); propertyViewTypeID.stringValue = view.GetType().AssemblyQualifiedName; propertyResourcePath.stringValue = UViewEditorUtils.GetResourcePath(assetPath); propertyAssetID.stringValue = AssetDatabase.AssetPathToGUID(assetPath); }
/// <returns><c>true</c> if the specified view type is open as an overlay.</returns> /// <param name="view">Type of view.</param> public bool IsOverlayOpen(System.Type view) { int i = 0, l = _showingOverlays.Count; for (; i < l; ++i) { AbstractView overlay = _showingOverlays[i]; if (overlay.GetType() == view) { return(true); } } return(false); }
public void UpdateLoadedViews() { _loadedViews.Clear(); Object[] gameObjects = Resources.FindObjectsOfTypeAll(typeof(AbstractView)); int i = 0, l = gameObjects.Length; for (; i < l; ++i) { AbstractView view = gameObjects[i] as AbstractView; if (!EditorUtility.IsPersistent(view)) { _loadedViews.Add(view.GetType(), view); } } }
public static void Rebuild(SerializedProperty propertyViewAssets) { int i = 0, l = propertyViewAssets.arraySize; for (; i < l; ++i) { SerializedProperty propertyViewAsset = propertyViewAssets.GetArrayElementAtIndex(i); SerializedProperty propertyAssetID = propertyViewAsset.FindPropertyRelative("assetID"); string assetPath = AssetDatabase.GUIDToAssetPath(propertyAssetID.stringValue); AbstractView view = AssetDatabase.LoadAssetAtPath <AbstractView>(assetPath); if (view != null) { CreateViewAsset(propertyViewAsset, view); } } }
/// <summary> /// Close the specified view. /// </summary> /// <param name="view">The type of view to close.</param> public void CloseOverlay(System.Type view) { if (!HasView(view)) { throw new UnityException(string.Format("Invalid view type: {0}", view)); } int i = _showingOverlays.Count - 1; for (; i >= 0; --i) { AbstractView o = _showingOverlays[i]; if (o.GetType() == view) { CloseOverlay(o); } } }
public static void RemoveViewAssets(SerializedProperty property) { SerializedProperty propertyAssetID = property.FindPropertyRelative("assetID"); string assetPath = AssetDatabase.GUIDToAssetPath(propertyAssetID.stringValue); AbstractView view = AssetDatabase.LoadAssetAtPath <AbstractView>(assetPath); if (view != null) { MonoScript script = MonoScript.FromMonoBehaviour(view); string scriptPath = AssetDatabase.GetAssetPath(script); AssetDatabase.DeleteAsset(scriptPath); } AssetDatabase.DeleteAsset(assetPath); AssetDatabase.Refresh(); }
private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused) { SerializedProperty propertyViewAsset = serializedProperty.GetArrayElementAtIndex(index); SerializedProperty propertyViewTypeID = propertyViewAsset.FindPropertyRelative("viewTypeID"); SerializedProperty propertyAssetID = propertyViewAsset.FindPropertyRelative("assetID"); string viewName = UViewEditorUtils.GetViewName(propertyViewTypeID); string assetPath = AssetDatabase.GUIDToAssetPath(propertyAssetID.stringValue); if (UViewEditorUtils.ValidateViewAsset(propertyViewAsset)) { System.Type viewType = System.Type.GetType(propertyViewTypeID.stringValue); AbstractView sceneInstance = _loadedViews.ContainsKey(viewType) ? _loadedViews[viewType] : null; bool existsInScene = sceneInstance != null; EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, rect.height), existsInScene ? string.Format("{0} (Loaded)", viewName) : viewName, existsInScene ? EditorStyles.boldLabel : EditorStyles.label); if (existsInScene && GUI.Button(new Rect(rect.x + rect.width - 55, rect.y, 55, rect.height - 4), "Unload", EditorStyles.miniButton)) { GameObject.DestroyImmediate(sceneInstance.gameObject); } else if (!existsInScene && GUI.Button(new Rect(rect.x + rect.width - 55, rect.y, 55, rect.height - 4), "Load", EditorStyles.miniButton)) { AbstractView viewAsset = AssetDatabase.LoadAssetAtPath <AbstractView>(assetPath); if (viewAsset != null) { AbstractView instance = PrefabUtility.InstantiatePrefab(viewAsset) as AbstractView; instance.SetParent(_propertyViewParent.objectReferenceValue as Transform, ViewDisplayMode.Overlay); Selection.activeGameObject = instance.gameObject; } else { Debug.LogErrorFormat("Unable to load {0} ({1}), missing an AbstractView component", viewName, assetPath); } } } else { EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, rect.height), string.Format("{0} (Asset Missing)", viewName), EditorStyles.boldLabel); requiresRebuild = true; } }
protected virtual AbstractView CreateView(ViewAsset asset, ViewDisplayMode displayMode) { if (_debug) { Debug.LogFormat("[ViewController] Creating View: {0}, displayMode: {1}", asset.viewType.Name, displayMode); } // load the view resource GameObject resource = asset.Load() as GameObject; if (resource != null) { // create an instance of the view resource AbstractView view = (Instantiate(resource) as GameObject).GetComponent <AbstractView>(); if (view == null) { Unload(asset.viewType); throw new UnityException(string.Format("Resource for {0} has no view component attached!", asset.viewType)); } // setup view inside viewParent view.SetParent(viewParent, displayMode); // finish view creation view._Create(this, displayMode); if (EventViewCreated != null) { EventViewCreated(this, asset.viewType, displayMode); } return(view); } else { throw new UnityException(string.Format("Resource not found for: {0}", asset.viewType)); } }
/// <summary> /// Opens the specified view as an overlay. /// </summary> /// <param name="data">Optional data <c>object</c> to be passed onto the view when it's shown.</param> /// <param name="close">Optional view to close before opening the target view.</param> /// <typeparam name="T">Type of view we want to open.</typeparam> public void OpenOverlay <T>(object data = null, AbstractView waitForViewToClose = null) where T : AbstractView { OpenOverlay(typeof(T), data, waitForViewToClose); }
/// <returns><c>true</c> if the specified view is open as an overlay.</returns> public bool IsOverlayOpen(AbstractView view) { return(_showingOverlays.Contains(view)); }
private void DrawViewGUI() { EditorGUILayout.LabelField("Configuration", EditorStyles.boldLabel); EditorGUILayout.PropertyField(_propertyAutoSetup); EditorGUILayout.PropertyField(_propertyDontDestroyOnLoad); EditorGUILayout.PropertyField(_propertyDebug); EditorGUILayout.PropertyField(_propertyViewParent); string[] viewNames = UViewEditorUtils.GetViewNames(_propertyViewAssets, false); string[] viewNamesShort = UViewEditorUtils.GetViewNames(_propertyViewAssets, true); int startLocationIndex = System.Array.IndexOf <string>(viewNames, _propertyStartingLocation.stringValue); startLocationIndex = EditorGUILayout.Popup("Start Location", startLocationIndex, viewNamesShort); _propertyStartingLocation.stringValue = startLocationIndex == -1 ? "" : viewNames[startLocationIndex]; EditorGUILayout.Space(); EditorGUILayout.Space(); bool locked = EditorApplication.isCompiling && EditorPrefs.HasKey(UViewEditorUtils.KEY_SCRIPT_PATH); EditorGUI.BeginDisabledGroup(locked); _viewList.requiresRebuild = false; _viewList.UpdateLoadedViews(); _viewList.DoLayoutList(); if (_viewList.requiresRebuild && !_attemptedRebuild) { Debug.LogWarning("Views missing or changed, rebuilding..."); UViewEditorUtils.Rebuild(_propertyViewAssets); _viewList.requiresRebuild = false; _attemptedRebuild = true; } EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.LabelField("Add Existing", GUILayout.Width(80)); GameObject viewGameObject = EditorGUILayout.ObjectField(null, typeof(GameObject), false) as GameObject; if (viewGameObject != null) { AbstractView view = viewGameObject.GetComponent <AbstractView>(); if (view != null) { // TODO: check this view isn't already in the list _showInvalidWarning = false; int index = _propertyViewAssets.arraySize; _propertyViewAssets.InsertArrayElementAtIndex(index); UViewEditorUtils.CreateViewAsset(_propertyViewAssets.GetArrayElementAtIndex(index), view as AbstractView); } else { _showInvalidWarning = true; } } if (GUILayout.Button("Create New", GUILayout.Width(100))) { UViewEditorUtils.ContextCreateView(); } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); if (GUILayout.Button("Rebuild List", GUILayout.Width(110))) { _attemptedRebuild = false; UViewEditorUtils.Rebuild(_propertyViewAssets); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); if (_showInvalidWarning) { EditorGUILayout.HelpBox("Asset must have an AbstractView component attached", MessageType.Warning); } EditorGUILayout.Space(); if (locked) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.HelpBox("Creating View...", MessageType.Info); } }