public virtual void cloneFrom(txUIObject obj) { if (obj.GetType() != GetType()) { logError("ui type is different, can not clone!"); return; } setPosition(obj.getPosition()); setRotation(obj.getRotation()); setScale(obj.getScale()); }
public override void update(float elapsedTime) { if (mSceneMap != null) { bool changed = false; Vector3 moveDelta = Vector3.zero; // 方向键用来移动地图 if (getKeyCurrentUp(KeyCode.UpArrow)) { mCurViewPos.y += 1 * mMoveSpeed; changed = true; moveDelta.y = 32 * mMoveSpeed; } if (getKeyCurrentUp(KeyCode.DownArrow)) { mCurViewPos.y -= 1 * mMoveSpeed; changed = true; moveDelta.y = -32 * mMoveSpeed; } if (getKeyCurrentUp(KeyCode.LeftArrow)) { mCurViewPos.x += 1 * mMoveSpeed; changed = true; moveDelta.x = -48 * mMoveSpeed; } if (getKeyCurrentUp(KeyCode.RightArrow)) { mCurViewPos.x -= 1 * mMoveSpeed; changed = true; moveDelta.x = 48 * mMoveSpeed; } if (changed) { refreshMap(); LT.MOVE_WINDOW(mSceneRoot, mSceneRoot.getPosition() + moveDelta); } } }
public void init() { mStartPosition = mRole.getPosition(); mEndPosition = mEnd.getPosition(); mRole.setAutoHide(false); }
public override void init() { mPosRootStart = mUIVolumeRootStart.getPosition(); mPosRootEnd = mUIVolumeRoot.getPosition(); mLayout.setScriptControlHide(true); }
public override void update(float elapsedTime) { base.update(elapsedTime); if (mDraging) { Vector3 curPosition = mWindow.getPosition(); Vector3 prePos = curPosition; // 拖拽状态时,鼠标移动量就是窗口的移动量,此处未考虑父窗口的缩放不为1的情况 Vector3 moveDelta = getMousePosition() - mStartDragMousePosition; if (mDragDirection == DRAG_DIRECTION.DD_HORIZONTAL) { moveDelta.y = 0.0f; } else if (mDragDirection == DRAG_DIRECTION.DD_VERTICAL) { moveDelta.x = 0.0f; } curPosition = mStartDragWindowPosition + moveDelta; if (mClampInRange) { clampPosition(ref curPosition); } if (!isVectorEqual(ref prePos, ref curPosition)) { setPosition(curPosition); mDragingCallback?.Invoke(); } } else { // 自动停靠最近的边 if (mAutoMoveToEdge) { Vector3[] minMaxPos = getLocalMinMaxPixelPos(); Vector2 minPos = minMaxPos[0]; Vector2 maxPos = minMaxPos[1]; Vector3 curPosition = mWindow.getPosition(); Vector3 targetPosition = curPosition; // 获得当前最近的边 if (mDragDirection == DRAG_DIRECTION.DD_HORIZONTAL) { targetPosition.x = getNearest(curPosition.x, minPos.x, maxPos.x); } else if (mDragDirection == DRAG_DIRECTION.DD_VERTICAL) { targetPosition.y = getNearest(curPosition.y, minPos.y, maxPos.y); } else { mDisArray[0] = abs(curPosition.x - minPos.x); mDisArray[1] = abs(curPosition.x - maxPos.x); mDisArray[2] = abs(curPosition.y - minPos.y); mDisArray[3] = abs(curPosition.y - maxPos.y); int minIndex = -1; float minDistance = 0.0f; for (int i = 0; i < 4; ++i) { if (minIndex < 0 || minDistance > mDisArray[i]) { minIndex = i; minDistance = mDisArray[i]; } } if (minIndex == 0) { targetPosition.x = minPos.x; } else if (minIndex == 1) { targetPosition.x = maxPos.x; } else if (minIndex == 2) { targetPosition.y = minPos.y; } else if (minIndex == 3) { targetPosition.y = maxPos.y; } } if (!isVectorEqual(ref curPosition, ref targetPosition)) { Vector3 pos = lerp(curPosition, targetPosition, elapsedTime * mMoveToEdgeSpeed); setPosition(pos); } } else { Vector3 curPosition = mWindow.getPosition(); // 如果滑动已经超过了正常区域,则手指放开时回弹到正常范围内 Vector3 validPos = curPosition; if (!isValidPosition(ref curPosition, ref validPos, mAlignTopOrLeft)) { Vector3 newPos = lerp(curPosition, validPos, elapsedTime * mAutoClampSpeed); if (!isVectorEqual(ref newPos, ref curPosition)) { setPosition(newPos); } else { mMoveSpeed = 0.0f; } } else { // 按照当前滑动速度移动 if (mMoveSpeed > 0.0f) { // 只有鼠标未按下并且不自动停靠到最近的边时才衰减速度 Vector3 prePos = curPosition; mMoveSpeed = lerp(mMoveSpeed, 0.0f, elapsedTime * mAttenuateFactor, 10.0f); curPosition += mMoveNormal * mMoveSpeed * mMoveSpeedScale * elapsedTime; clampPosition(ref curPosition); if (!isVectorEqual(ref prePos, ref curPosition)) { setPosition(curPosition); } else { mMoveSpeed = 0.0f; } } } } } }