Esempio n. 1
0
        /// <summary>
        /// Setup the <c>ViewController</c> so it's ready to use. If a starting location is set that view
        /// will be created and shown.
        /// </summary>
        /// <param name="startLocation">Type of view to start the location system in.</param>
        public void Setup(System.Type startLocation)
        {
            if (IsSetup)
            {
                return;
            }

            if (_dontDestroyOnLoad)
            {
                DontDestroyOnLoad(gameObject);
            }

            _assetLookup     = new Dictionary <System.Type, ViewAsset>();
            _showingOverlays = new List <AbstractView> ();

            int i = 0, l = _viewAssets.Count;

            for (; i < l; ++i)
            {
                ViewAsset asset = _viewAssets[i];

                System.Type viewType = asset.viewType;
                if (viewType == null)
                {
                    Debug.LogWarningFormat("Invalid View, try rebuilding the ViewController: {0}", asset.viewTypeID);
                }
                else
                {
                    _assetLookup.Add(asset.viewType, asset);
                }
            }

            IsSetup = true;

            if (startLocation != null)
            {
                ChangeLocation(startLocation, null);
            }
        }
Esempio n. 2
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));
            }
        }