示例#1
0
        private void CreateViewAsOverlay(System.Type view, object data)
        {
            AbstractView overlay = CreateView(_assetLookup[view], ViewDisplayMode.Overlay) as AbstractView;

            _showingOverlays.Add(overlay);
            overlay._Show(data);
        }
示例#2
0
 /// <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);
     }
 }
示例#3
0
 /// <summary>
 /// Close the specified view.
 /// </summary>
 /// <param name="view">The view to close.</param>
 public void CloseOverlay(AbstractView view)
 {
     if (IsOverlayOpen(view))
     {
         view._Hide();
     }
 }
示例#4
0
        /// <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);
            }
        }
示例#5
0
 /// <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);
     }
 }
示例#6
0
        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)
                {
                    System.Type location = _targetOverlay;
                    object      data     = _targetOverlayData;

                    // clear data
                    _targetOverlay     = null;
                    _targetOverlayData = null;

                    CreateViewAsOverlay(location, data);
                }
            }
            else if (view.displayMode == ViewDisplayMode.Location)
            {
                // process next location is one is queued
                if (view == _currentLocation && _targetLocation != null)
                {
                    System.Type location = _targetLocation;
                    object      data     = _targetLocationData;

                    // clear data
                    _targetLocation     = null;
                    _targetLocationData = null;

                    CreateViewAsLocation(location, data);
                }
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
        public AbstractView GetOverlay(System.Type view)
        {
            int i = 0, l = _showingOverlays.Count;

            for (; i < l; ++i)
            {
                AbstractView overlay = _showingOverlays[i];
                if (overlay.GetType() == view)
                {
                    return(overlay);
                }
            }

            return(null);
        }
示例#11
0
        /// <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);
        }
示例#12
0
        /// <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);
                }
            }
        }
示例#13
0
        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));
            }
        }
示例#14
0
 /// <summary>
 /// Open the specified view as an overlay. You can open multiple overlays of the same view type if required.
 /// </summary>
 /// <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>
 /// <typeparam name="T">The type of view to open as an overlay.</typeparam>
 public void OpenOverlay <T>(object data, AbstractView waitForViewToClose) where T : AbstractView
 {
     OpenOverlay(typeof(T), data, waitForViewToClose);
 }
示例#15
0
 /// <returns><c>true</c> if the specified view is open as an overlay.</returns>
 public bool IsOverlayOpen(AbstractView view)
 {
     return(_showingOverlays.Contains(view));
 }