// Control Function ----------------------------------------------------------------- void SetIndex(int nIndex) { if (m_Renderer != null) { int nSetIndex = nIndex; int nLoopCount = nIndex / m_nFrameCount; switch (m_PlayMode) { case PLAYMODE.DEFAULT: nSetIndex = nIndex % m_nFrameCount; break; case PLAYMODE.INVERSE: nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 1; break; case PLAYMODE.PINGPONG: { nLoopCount = (nSetIndex / (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); nSetIndex = (nSetIndex % (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); if (m_nFrameCount <= nSetIndex) { nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 2; } break; } case PLAYMODE.RANDOM: break; case PLAYMODE.SELECT: nSetIndex = nIndex % m_nFrameCount; break; } if (nSetIndex == m_nLastIndex) { return; } int uIndex = (nSetIndex + m_nStartFrame) % m_nTilingX; int vIndex = (nSetIndex + m_nStartFrame) / m_nTilingX; Vector2 offset = new Vector2(uIndex * m_size.x, 1.0f - m_size.y - vIndex * m_size.y); if (UpdateMeshUVs(new Rect(offset.x, offset.y, m_size.x, m_size.y)) == false) { // Debug.Log("m_Renderer.material"); m_Renderer.material.mainTextureOffset = offset; m_Renderer.material.mainTextureScale = m_size; } if (m_NcSpriteFactory != null) { m_NcSpriteFactory.OnAnimationChangingFrame(this, m_nLastIndex, nSetIndex, nLoopCount); } m_nLastIndex = nSetIndex; } }
void SetIndex(int nSeqIndex) { if (m_Renderer != null) { int nSetIndex = m_nLastSeqIndex = nSeqIndex; int nLoopCount = nSeqIndex / m_nFrameCount; switch (m_PlayMode) { case PLAYMODE.DEFAULT: { if (m_bLoop) { nSetIndex = CalcPartLoopInfo(nSeqIndex, ref nLoopCount) % m_nFrameCount; } else { nSetIndex = nSeqIndex % m_nFrameCount; } break; } case PLAYMODE.INVERSE: nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 1; break; case PLAYMODE.PINGPONG: { nLoopCount = (nSetIndex / (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); nSetIndex = (nSetIndex % (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); if (m_nFrameCount <= nSetIndex) { nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 2; } break; } case PLAYMODE.RANDOM: break; case PLAYMODE.SELECT: nSetIndex = nSeqIndex % m_nFrameCount; break; } if (nSetIndex == m_nLastIndex) { return; } if (m_TextureType == TEXTURE_TYPE.TileTexture) { int uIndex = (nSetIndex + m_nStartFrame) % m_nTilingX; int vIndex = (nSetIndex + m_nStartFrame) / m_nTilingX; Vector2 offset = new Vector2(uIndex * m_size.x, 1.0f - m_size.y - vIndex * m_size.y); if (UpdateMeshUVsByTileTexture(new Rect(offset.x, offset.y, m_size.x, m_size.y)) == false) { m_Renderer.material.mainTextureOffset = offset; m_Renderer.material.mainTextureScale = m_size; } } else if (m_TextureType == TEXTURE_TYPE.TrimTexture) { UpdateSpriteTexture(nSetIndex, true); } else if (m_TextureType == TEXTURE_TYPE.SpriteFactory) { UpdateFactoryTexture(nSetIndex, true); } if (m_NcSpriteFactoryCom != null) { m_NcSpriteFactoryCom.OnAnimationChangingFrame(this, m_nLastIndex, nSetIndex, nLoopCount); } m_nLastIndex = nSetIndex; } }
void SetIndex(int nSeqIndex) { if (m_Renderer != null) { int nSetIndex = m_nLastSeqIndex = nSeqIndex; int nLoopCount = nSeqIndex / m_nFrameCount; switch (m_PlayMode) { case PLAYMODE.DEFAULT: { if (m_bLoop) { nSetIndex = CalcPartLoopInfo(nSeqIndex, ref nLoopCount) % m_nFrameCount; } else { nSetIndex = nSeqIndex % m_nFrameCount; } break; } case PLAYMODE.INVERSE: nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 1; break; case PLAYMODE.PINGPONG: { nLoopCount = (nSetIndex / (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); nSetIndex = (nSetIndex % (m_nFrameCount * 2 - (nSetIndex == 0 ? 1 : 2))); if (m_nFrameCount <= nSetIndex) { nSetIndex = m_nFrameCount - (nSetIndex % m_nFrameCount) - 2; } break; } case PLAYMODE.RANDOM: break; case PLAYMODE.SELECT: nSetIndex = nSeqIndex % m_nFrameCount; break; } if (nSetIndex == m_nLastIndex) { return; } if (m_TextureType == TEXTURE_TYPE.TileTexture) { int uIndex = (nSetIndex + m_nStartFrame) % m_nTilingX; int vIndex = (nSetIndex + m_nStartFrame) / m_nTilingX; Vector2 offset = new Vector2(uIndex * m_size.x, 1.0f - m_size.y - vIndex * m_size.y); if (UpdateMeshUVsByTileTexture(new Rect(offset.x, offset.y, m_size.x, m_size.y)) == false) { m_Renderer.material.mainTextureOffset = new Vector2(offset.x - ((int)offset.x), offset.y - ((int)offset.y)); m_Renderer.material.mainTextureScale = m_size; AddRuntimeMaterial(m_Renderer.material); } } else if (m_TextureType == TEXTURE_TYPE.TrimTexture) { UpdateSpriteTexture(nSetIndex, true); } else if (m_TextureType == TEXTURE_TYPE.SpriteFactory) { UpdateFactoryTexture(nSetIndex, true); } else if (m_TextureType == TEXTURE_TYPE.MeshUv) { int uIndex = (nSetIndex + m_nStartFrame) % m_nTilingX + 1; int vIndex = m_nTilingY - (nSetIndex + m_nStartFrame) / m_nTilingX - 1; var meshUv = m_MeshFilter.mesh.uv; Vector4[] value = new Vector4[meshUv.Length]; for (int n = 0; n < meshUv.Length; n++) { value[n].x = uIndex; value[n].y = vIndex; value[n].z = 1.0f / m_nTilingX; value[n].w = 1.0f / m_nTilingY; } m_MeshFilter.mesh.SetUVs(1, value.ToList()); } else if (m_TextureType == TEXTURE_TYPE.MeshUvMirror) { int uIndex = (nSetIndex + m_nStartFrame) % m_nTilingX; int vIndex = m_nTilingY - (nSetIndex + m_nStartFrame) / m_nTilingX - 1; var uv = new Vector4(); uv.x = (uIndex + 0) / (float)m_nTilingX; uv.y = (vIndex + 0) / (float)m_nTilingY; uv.z = (uIndex + 1) / (float)m_nTilingX; uv.w = (vIndex + 1) / (float)m_nTilingY; m_MeshFilter.mesh.SetUVs(1, new List <Vector4>() { uv, uv, uv, uv }); } if (m_NcSpriteFactoryCom != null) { m_NcSpriteFactoryCom.OnAnimationChangingFrame(this, m_nLastIndex, nSetIndex, nLoopCount); } if (m_OnChangeFrameComponent != null) { m_OnChangeFrameComponent.SendMessage(m_OnChangeFrameFunction, nSetIndex, SendMessageOptions.DontRequireReceiver); } m_nLastIndex = nSetIndex; } }