/// <summary>
    /// 外部调用的自适应接口
    /// </summary>
    /// <param name="adaption">适配参数</param>
    public void ExecAdaption(Adaption adaption = null)
    {
        ScreenWidth  = Screen.width;
        ScreenHeight = Screen.height;

        ViewWidth  = ScreenWidth;
        ViewHeight = ScreenHeight;

        #region 计算摄像机视野
        {
            float standardCameraSize = standardHeight / 2.0f;
            float standardAspect     = standardWidth / (float)standardHeight;
            float screenAspect       = ViewWidth / ViewHeight;
            float cameraScaleRatio   = standardAspect / screenAspect;
            if (screenAspect < standardAspect)
            {
                uiCamera.orthographicSize = standardCameraSize * cameraScaleRatio;
                ViewWidth  = standardWidth;
                ViewHeight = standardHeight * cameraScaleRatio;
            }
            else
            {
                uiCamera.orthographicSize = standardCameraSize;
                ViewHeight = standardHeight;
                ViewWidth  = standardWidth / cameraScaleRatio;
            }
        }
        #endregion

        Width  = Math.Min(ViewWidth, maxWidth);
        Height = Math.Min(ViewHeight, maxHeight);

        #region 特殊适配自适应
        if (adaption != null)
        {
            Width  = ViewWidth * (adaption.targetX / ScreenWidth);
            Height = ViewHeight * (adaption.targetY / ScreenHeight);

            TMP_VECTOR2.x = adaption.offsetX;
            TMP_VECTOR2.y = adaption.offsetY;
            CachedTran.anchoredPosition = TMP_VECTOR2;
        }
        #endregion

        if (adaptionType == AdaptionType.Stretch)
        {
            TMP_VECTOR3.x         = Width / standardWidth;
            TMP_VECTOR3.y         = Height / standardHeight;
            TMP_VECTOR3.z         = 1;
            CachedTran.localScale = TMP_VECTOR3;

            Width  = standardWidth;
            Height = standardHeight;
        }

        TMP_VECTOR2.x        = Width;
        TMP_VECTOR2.y        = Height;
        CachedTran.sizeDelta = TMP_VECTOR2;
    }
    public void ExecAdaption(int targetX, int targetY, int offsetX, int offsetY)
    {
        Adaption adaption = new Adaption();

        adaption.targetX = targetX;
        adaption.targetY = targetY;
        adaption.offsetX = offsetX;
        adaption.offsetY = offsetY;
        ExecAdaption(adaption);
    }
Ejemplo n.º 3
0
    void Start()
    {
        fileStartTime = DateTime.Now.ToString("yyMMdd-HHmmss");
        log           = new XFileWriter(this, "log-");
        deb           = new XFileWriter(this, "deb-", false);

        SetupServer();
        recognition = new Recognition(this);
        adaption    = new Adaption(this, recognition);
        events      = new List <string>();
        eventsMutex = new object();

        tSample    = GameObject.Find("Sample").GetComponent <Text>();
        tinputted  = GameObject.Find("Inputted").GetComponent <Text>();
        tDragItems = new Text[DRAG_ITEM_N];
        GameObject canvas = GameObject.Find("Canvas");

        for (int i = 0; i < DRAG_ROW; i++)
        {
            for (int j = 0; j < DRAG_COLUMN; j++)
            {
                GameObject gDragItem = Instantiate(prefabDragItem);
                gDragItem.transform.position = new Vector3(-150 + j * 105, -15 + i * -35, 700);
                gDragItem.transform.SetParent(canvas.transform);
                tDragItems[i * DRAG_COLUMN + j] = gDragItem.GetComponentInChildren <Text>();
            }
        }

        inputtedWords     = new List <string>();
        inputtedPoints    = new List <Vector2>();
        inputtedPointsAll = new List <Vector2[]>();
        //sampleSentences = XFileReader.Read("phrases-all-filtered.txt");
        sampleSentences = XFileReader.Read("phrases-simple.txt");
        for (int i = 0; i < sampleSentences.Length; i++)
        {
            sampleSentences[i] = sampleSentences[i].ToLower();
        }
        sampleCnt = -1;

        UpdateSample();
        UpdateInputted();
    }