/** switches to a certain layer indexed by n. * The current (old) layer will be removed from it's parent with 'cleanup:YES'. */ public override void OnEnter() { if (m_nEnabledLayer == -1 && m_pLayers.Count > 0) { SwitchTo(0); } else if (m_nEnabledLayer != -1) { if (m_InAction != null) { m_pLayers[m_nEnabledLayer].RunAction(m_InAction.Copy()); } } base.OnEnter(); }
/** switches to a certain layer indexed by n. * The current (old) layer will be removed from it's parent with 'cleanup:YES'. */ /// <summary> /// Swtich to the given index layer and use the given action after the layer is /// added to the scene. /// </summary> /// <param name="n"></param> public void SwitchTo(int n) { Debug.Assert(n < m_pLayers.Count, "Invalid index in MultiplexLayer switchTo message"); CCLayer outLayer = m_pLayers[m_nEnabledLayer]; if (m_OutAction != null) { outLayer.RunAction( CCSequence.FromActions( (CCFiniteTimeAction)m_OutAction.Copy(), new CCCallFunc(() => RemoveChild(outLayer, true)) ) ); } else { RemoveChild(outLayer, true); } m_nEnabledLayer = n; AddChild(m_pLayers[n]); if (m_InAction != null) { m_pLayers[n].RunAction(m_InAction.Copy()); } }
/// <summary> /// Swtich to the given index layer and use the given action after the layer is /// added to the parent. The parameter can be the index or it can be the tag of the layer. /// </summary> /// <param name="n">Send in NoLayer to hide all multiplexed layers. Otherwise, send in a tag or the logical index of the /// layer to show.</param> /// <returns>The layer that is going to be shown. This can return null if the SwitchTo layer is NoLayer</returns> public CCLayer SwitchTo(int n) { if (n != -1) { if (m_nEnabledLayer == n || m_nEnabledLayer == (n + kTagOffsetForUniqueness)) { // no-op if (m_nEnabledLayer == -1) { return(null); } return(m_pLayers[m_nEnabledLayer]); } } if (m_nEnabledLayer != -1) { CCLayer outLayer = null; if (m_pLayers.ContainsKey(m_nEnabledLayer)) { outLayer = m_pLayers[m_nEnabledLayer]; if (m_OutAction != null) { outLayer.RunAction( new CCSequence( (CCFiniteTimeAction)m_OutAction.Copy(), new CCCallFunc(() => RemoveChild(outLayer, true)) ) ); } else { RemoveChild(outLayer, true); } } // We have no enabled layer at this point m_nEnabledLayer = NoLayer; } // When NoLayer, the multiplexer shows nothing. if (n == NoLayer) { ShowFirstLayerOnEnter = false; return(null); } if (!m_pLayers.ContainsKey(n)) { int f = n + kTagOffsetForUniqueness; if (m_pLayers.ContainsKey(f)) { n = f; } else { // Invalid index - layer not found return(null); } } // Set the active layer AddChild(m_pLayers[n]); m_nEnabledLayer = n; // Run the in-action on the new layer if (m_InAction != null) { m_pLayers[n].RunAction(m_InAction.Copy()); } return(m_pLayers[m_nEnabledLayer]); }