/// <summary> /// Create the View. /// </summary> /// <param name="controller">ViewController that's managing this View.</param> /// <param name="displayMode">Display mode for this View.</param> internal void _Create(ViewController controller, ViewDisplayMode displayMode) { _controller = controller; this.displayMode = displayMode; this.state = ViewState.Creating; OnCreate(); }
/// <summary> /// Sets the parent of this views Transform and calls <code>GetSiblingIndex</code>. /// </summary> /// <param name="viewParent">The parent transform for this View</param> /// <param name="displayMode">The display mode for this View.</param> public virtual void SetParent(Transform viewParent, ViewDisplayMode displayMode) { transform.SetParent(viewParent, false); int siblingIndex = GetSiblingIndex(viewParent, displayMode); if (siblingIndex > -1) { transform.SetSiblingIndex(siblingIndex); } }
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> /// Effects the position of this View within a transform hierarchy, useful when working with Unity UI. The default behaviour is to put all Locations at 0 /// and Overlays at the top. If the view has no parent -1 is returned. /// </summary> /// <returns>The sibling index.</returns> /// <param name="viewParent">The parent transform for this View</param> /// <param name="displayMode">The display mode for this View.</param> public virtual int GetSiblingIndex(Transform viewParent, ViewDisplayMode displayMode) { return(viewParent == null ? -1 : displayMode == ViewDisplayMode.Location ? 0 : viewParent.childCount); }