//-------------------------------------------------------------------------------------------------------- protected void onPlaying(AnimControl control, int frame, bool isPlaying) { if (mControl.getCurFrameIndex() >= mTextureNameList.Count) { return; } setSpriteName(mTextureNameList[mControl.getCurFrameIndex()], mUseTextureSize); // 使用位置列表进行校正 if (mEffectAlign == EFFECT_ALIGN.POSITION_LIST) { if (mTexturePosList != null && mTexturePosList.Count > 0) { int positionIndex = (int)(frame / (float)mTextureNameList.Count * mTexturePosList.Count + 0.5f); setPosition(mTexturePosList[positionIndex]); } } // 对齐父节点的底部 else if (mEffectAlign == EFFECT_ALIGN.PARENT_BOTTOM) { txUIObject parent = getParent(); if (parent != null) { Vector2 windowSize = getWindowSize(); Vector2 parentSize = parent.getWindowSize(); setPosition(replaceY(getPosition(), (windowSize.y - parentSize.y) * 0.5f)); } } int count = mPlayingCallback.Count; for (int i = 0; i < count; ++i) { mPlayingCallback[i](this, false); } }
// screenCenterAsZero为true表示返回的坐标是以window的中心为原点,false表示已window的左下角为原点 public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject window, bool screenCenterAsZero = true, bool isNGUI = true) { Camera camera = getUICamera(isNGUI); Vector2 cameraSize = new Vector2(camera.pixelWidth, camera.pixelHeight); Vector2 rootSize = getRootSize(isNGUI); screenPos = multiVector2(devideVector2(screenPos, cameraSize), rootSize); // 将坐标转换到以屏幕中心为原点的坐标 screenPos -= rootSize * 0.5f; Vector2 windowPos = screenPos; if (window != null) { txUIObject root = FrameBase.mLayoutManager.getUIRoot(isNGUI); Vector2 parentWorldPosition = devideVector3(window.getWorldPosition(), root.getScale()); windowPos = devideVector2(screenPos - parentWorldPosition, window.getWorldScale()); if (!screenCenterAsZero) { windowPos += window.getWindowSize() * 0.5f; } } else { if (!screenCenterAsZero) { windowPos += rootSize * 0.5f; } } return(windowPos); }
//------------------------------------------------------------------------------------------------------------------------------------------ protected Vector3[] getLocalMinMaxPixelPos() { if (mMinMaxPosDirty) { bool isNGUI = mWindow.getLayout().isNGUI(); Vector2 parentWidgetSize = Vector2.zero; if (isNGUI) { #if USE_NGUI // 获得第一个带widget的父节点的rect if (mParentRect == null) { mParentRect = WidgetUtility.findNGUIParentRect(mWindow.getObject()); } parentWidgetSize = WidgetUtility.getNGUIRectSize(mParentRect); #endif } else { parentWidgetSize = mWindow.getParent().getWindowSize(); } // 计算父节点的世界缩放 Vector2 worldScale = getMatrixScale(mWindow.getTransform().parent.localToWorldMatrix); txUIObject root = mLayoutManager.getUIRoot(isNGUI); Vector2 uiRootScale = root.getTransform().localScale; Vector2 parentScale = worldScale / uiRootScale; // 计算移动的位置范围 Vector2 minPos = parentWidgetSize * 0.5f * mMinRelativePos / parentScale; Vector2 maxPos = parentWidgetSize * 0.5f * mMaxRelativePos / parentScale; if (mClampType == CLAMP_TYPE.CT_EDGE) { Vector2 thisSize = mWindow.getWindowSize(true); minPos += thisSize * 0.5f; maxPos -= thisSize * 0.5f; if (!mClampInner) { swap(ref minPos, ref maxPos); } } else if (mClampType == CLAMP_TYPE.CT_CENTER) { } mMinMaxPos[0] = minPos; mMinMaxPos[1] = maxPos; mMinMaxPosDirty = false; } return(mMinMaxPos); }