protected override void applyScreenPosition(Vector3 screenPos) { txUIObject window = mComponentOwner as txUIObject; window.setLocalPosition(UnityUtility.screenPosToWindowPos(screenPos, window.getParent()) - new Vector2(Screen.currentResolution.width / 2.0f, Screen.currentResolution.height / 2.0f)); }
protected override void applyScreenPosition(Vector3 screenPos) { txUIObject window = mComponentOwner as txUIObject; Vector2 rootSize = WidgetUtility.getRootSize(); window.setLocalPosition(UnityUtility.screenPosToWindowPos(screenPos, window.getParent()) - rootSize / 2); }
//-------------------------------------------------------------------------------------------------------------- protected override void applyScreenPosition(ref Vector3 screenPos) { if (mMovable) { Vector3 pos = screenPosToWindowPos(screenPos - mDragMouseOffset, mWindow.getParent(), true, mWindow.getLayout().isNGUI()); mWindow.setPosition(pos); } }
//------------------------------------------------------------------------------------------------------------------------------------------ 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); }
public static void destroyWindow(txUIObject window, bool destroyReally) { if (window == null) { return; } // 先销毁所有子节点,因为遍历中会修改子节点列表,所需需要复制一个列表 if (window.mChildList.Count > 0) { List <txUIObject> childList = mListPool.newList(out childList); childList.AddRange(window.mChildList); int childCount = childList.Count; for (int i = 0; i < childCount; ++i) { destroyWindow(childList[i], destroyReally); } mListPool.destroyList(childList); } window.getParent()?.removeChild(window); // 再销毁自己 destroyWindowSingle(window, destroyReally); }