Exemplo n.º 1
0
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent, bool screenCenterAsZero = false, bool isNGUI = true)
    {
        Camera  camera   = mCameraManager.getUICamera().getCamera();
        Vector2 rootSize = WidgetUtility.getRootSize();

        screenPos.x = screenPos.x / camera.pixelWidth * rootSize.x;
        screenPos.y = screenPos.y / camera.pixelHeight * rootSize.y;
        Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero;

        txUIObject root  = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    scale = root.getScale();

        parentWorldPosition.x = parentWorldPosition.x / scale.x;
        parentWorldPosition.y = parentWorldPosition.y / scale.y;
        Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one;

        Vector2 pos       = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y);
        Vector2 windowPos = new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y);

        if (screenCenterAsZero)
        {
            windowPos -= rootSize / 2;
        }
        return(windowPos);
    }
Exemplo n.º 2
0
    public void showIndex(int index, float time = 0.3f)
    {
        // 设置当前选中的下标,并显示图标
        mShowIndex = index;
        int count = mPropsList.Count;

        for (int i = 0; i < count; ++i)
        {
            mPropsList[i].setSelected(i == mShowIndex);
        }
        // 设置当前起始和目标值
        mStartOffsetValue  = mCurOffsetValue;
        mTargetOffsetValue = -mPropsList[mShowIndex].mControlValueOffset;
        // 默认将范围限定到0-1之间
        MathUtility.clampValue(ref mStartOffsetValue, 0.0f, 1.0f, 1.0f);
        MathUtility.clampValue(ref mTargetOffsetValue, 0.0f, 1.0f, 1.0f);
        // 需要保证起始和目标之间不超过0.5,如果超过0.5则转换范围
        if (Mathf.Abs(mStartOffsetValue - mTargetOffsetValue) > 0.5f)
        {
            MathUtility.clampValue(ref mStartOffsetValue, 0.5f, 1.5f, 1.0f);
            MathUtility.clampValue(ref mTargetOffsetValue, 0.5f, 1.5f, 1.0f);
        }
        // 利用辅助物体开始渐变
        LayoutTools.SCALE_WINDOW_EX(mControlHelper, mControlHelper.getScale(), Vector2.one, time, onHelperScaling, null);
    }
Exemplo n.º 3
0
    public void showIndex(int index)
    {
        int trackCount = mTrackList.Count;

        for (int i = 0; i < trackCount; ++i)
        {
            mTrackList[i].setSelected(index == i);
        }
        // 选择上一个或者是从第0个切换到了最后一个
        arrowAnim(index - mShowIndex == -1 || index - mShowIndex == mTrackList.Count - 1);
        // 设置当前选中的下标,并显示图标
        mShowIndex = index;
        // 设置当前起始和目标值
        mStartOffsetValue  = mCurOffsetValue;
        mTargetOffsetValue = -mTrackList[mShowIndex].mControlValueOffset;
        // 默认将范围限定到0-1之间
        MathUtility.clampValue(ref mStartOffsetValue, 0.0f, 1.0f, 1.0f);
        MathUtility.clampValue(ref mTargetOffsetValue, 0.0f, 1.0f, 1.0f);
        // 需要保证起始和目标之间不超过0.5,如果超过0.5则转换范围
        if (Mathf.Abs(mStartOffsetValue - mTargetOffsetValue) > 0.5f)
        {
            MathUtility.clampValue(ref mStartOffsetValue, 0.5f, 1.5f, 1.0f);
            MathUtility.clampValue(ref mTargetOffsetValue, 0.5f, 1.5f, 1.0f);
        }
        // 利用辅助物体开始渐变
        LayoutTools.SCALE_WINDOW_EX(mControlHelper, mControlHelper.getScale(), Vector2.one, 0.3f, onHelperScaling, null);
    }
Exemplo n.º 4
0
    protected override void applyTrembling(float value)
    {
        txUIObject mObject  = mComponentOwner as txUIObject;
        Vector3    curScale = mObject.getScale();
        Vector2    newSacle = mStartScale + (mTargetScale - mStartScale) * value;

        mObject.setLocalScale(new Vector3(newSacle.x, newSacle.y, curScale.z));
    }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
    public static Vector2 screenPosToEffectPos(Vector2 screenPos, Vector2 parentWorldPos, Vector2 parentWorldScale, float effectDepth, bool isBack, bool isRelative = true, bool isNGUI = true)
    {
        GameCamera camera = isBack ? mBackEffectCamera : mForeEffectCamera;

        if (isRelative)
        {
            // 转到世界坐标系下,首先计算UI根节点的缩放值
            txUIObject root  = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
            Vector3    scale = root.getScale();
            screenPos.x      = screenPos.x / scale.x;
            screenPos.y      = screenPos.y / scale.y;
            parentWorldPos.x = parentWorldPos.x / scale.x;
            parentWorldPos.y = parentWorldPos.y / scale.y;
        }
        Vector2 pos = (effectDepth / -camera.getPosition().z + 1) * screenPos - parentWorldPos;

        return(new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y));
    }
Exemplo n.º 7
0
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent, bool screenCenterOsZero = false, bool isNGUI = true)
    {
        Camera camera = mCameraManager.getUICamera().getCamera();

        screenPos.x = screenPos.x / camera.pixelWidth * UnityEngine.Screen.currentResolution.width;
        screenPos.y = screenPos.y / camera.pixelHeight * UnityEngine.Screen.currentResolution.height;
        Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero;

        txUIObject root  = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    scale = root.getScale();

        parentWorldPosition.x = parentWorldPosition.x / scale.x;
        parentWorldPosition.y = parentWorldPosition.y / scale.y;
        Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one;

        Vector2 pos       = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y);
        Vector2 windowPos = new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y);

        if (screenCenterOsZero)
        {
            windowPos -= new Vector2(UnityEngine.Screen.currentResolution.width / 2.0f, UnityEngine.Screen.currentResolution.height / 2.0f);
        }
        return(windowPos);
    }
Exemplo n.º 8
0
    protected void onButtonPress(GameObject obj, bool press)
    {
        txUIObject window = mLayout.getUIObject(obj);

        LayoutTools.SCALE_WINDOW(window, window.getScale(), press ? new Vector2(1.2f, 1.2f) : Vector2.one, 0.2f);
    }
Exemplo n.º 9
0
    protected void onButtonPress(GameObject go, bool press)
    {
        txUIObject obj = mLayout.getUIObject(go);

        LT.SCALE_WINDOW(obj, obj.getScale(), press ? new Vector2(1.2f, 1.2f) : Vector2.one, 0.2f);
    }
Exemplo n.º 10
0
    // 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);
    }
Exemplo n.º 11
0
    protected void onButtonPress(GameObject go, bool press)
    {
        txUIObject button = mLayout.getUIObject(go);

        LayoutTools.SCALE_WINDOW(button, button.getScale(), press ? new Vector2(1.2f, 1.2f) : Vector2.one, 0.2f);
    }