コード例 #1
0
    public void UpdateInfo(ItemInfo info)
    {
        textItem.text = info.title;
        Texture2D tex = LoadTexture.LoadFromResource(info.pic);

        imageItem.sprite = LoadTexture.CreateSprieFromTex(tex);

        RectTransform rctran = imageItem.GetComponent <RectTransform>();
        float         w      = imageItem.sprite.texture.width;  //rectTransform.rect.width;
        float         h      = imageItem.sprite.texture.height; //rectTransform.rect.height;

        // print("imageItem size:w=" + w + " h=" + h);
        rctran.sizeDelta = new Vector2(w, h);

        RectTransform rctranText    = textItem.GetComponent <RectTransform>();
        RectTransform rctranContent = objContent.GetComponent <RectTransform>();
        float         oft_y         = rctranText.rect.height;
        float         scalex        = rctranContent.rect.width / w;
        float         scaley        = (rctranContent.rect.height - oft_y) / h;
        float         scale         = Mathf.Min(scalex, scaley);

        imageItem.transform.localScale = new Vector3(scale, scale, 1.0f);
        float x = 0;
        float y = oft_y / 2;

        rctran.anchoredPosition = new Vector2(x, y);
    }
コード例 #2
0
    void OnHttpRequestFinishedImage(HttpRequest req, bool isSuccess, byte[] data)
    {
        Button btn = null;

        switch (req.index)
        {
        case 0:
        {
            btn = btnAppIcon0;
        }
        break;

        case 1:
        {
            btn = btnAppIcon1;
        }
        break;

        case 2:
        {
            btn = btnAppIcon2;
        }
        break;
        }
        if (btn == null)
        {
            return;
        }
        btn.GetComponent <Image>().color = Color.white;
        Texture2D tex = new Texture2D(0, 0, TextureFormat.ARGB32, false);

        tex.LoadImage(data);
        btn.GetComponent <Image>().sprite = LoadTexture.CreateSprieFromTex(RoundRectTexture(tex));
    }
コード例 #3
0
    public void UpdateWorldBg(string pic)
    {
        Texture2D      tex    = TextureCache.main.Load(pic);
        SpriteRenderer render = objSpriteBg.GetComponent <SpriteRenderer>();

        render.sprite = LoadTexture.CreateSprieFromTex(tex);
        LayoutChild();
    }
コード例 #4
0
    void UpdateBtnSwitch(bool isSel)
    {
        Image img = btnSwitch.GetComponent <Image>();

        if (isSel)
        {
            img.sprite = LoadTexture.CreateSprieFromTex(TextureCache.main.Load(IMAGE_BTN_SWITCH_SEL));
        }
        else
        {
            img.sprite = LoadTexture.CreateSprieFromTex(TextureCache.main.Load(IMAGE_BTN_SWITCH_UNSEL));
        }
    }
コード例 #5
0
    public void UpdateItem()
    {
        textCount.text = index.ToString();

        string filename = "";

        switch (cmdType)
        {
        case CmdType.START:
            filename = "CmdStart";
            break;

        case CmdType.LEFT:
            filename = "CmdLeft";
            break;

        case CmdType.RIGHT:
            filename = "CmdRight";
            break;

        case CmdType.UP:
            filename = "CmdUp";
            break;

        case CmdType.DOWN:
            filename = "CmdDown";
            break;

        default:
            filename = "CmdStart";
            break;
        }

        Texture2D tex = TextureCache.main.Load("App/UI/Game/CmdItem/" + filename);

        if (tex != null)
        {
            imageCmd.sprite = LoadTexture.CreateSprieFromTex(tex);
        }

        if (cmdType == CmdType.NONE)
        {
            ShowBoard(true);
            //  ShowTextCount(false);
        }
        else
        {
            ShowBoard(false);
            //   ShowTextCount(true);
        }
    }
コード例 #6
0
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        uiTouchEvent = this.gameObject.AddComponent <UITouchEvent>();
        uiTouchEvent.callBackTouch = OnUITouchEvent;
        enableTouch = true;
        textCount.gameObject.SetActive(false);
        Texture2D tex = TextureCache.main.Load(AppRes.IMAGE_CMDITEM_BG);

        if (tex != null)
        {
            imageBg.sprite = LoadTexture.CreateSprieFromTex(tex);
        }
        SetLock(false);
    }
コード例 #7
0
    static public void UpdateImageTexture(Image image, string filepath, bool isUpdateSize, Vector4 border)
    {
        Texture2D tex = TextureCache.main.Load(filepath);

        if (tex)
        {
            Sprite sp = LoadTexture.CreateSprieFromTex(tex, border);
            image.sprite = sp;
            if (isUpdateSize)
            {
                RectTransform rctan = image.GetComponent <RectTransform>();
                rctan.sizeDelta = new Vector2(tex.width, tex.height);
            }
        }
    }
コード例 #8
0
    public void UpdateItem(float w, float h)
    {
        SpriteRenderer rd  = gameObject.AddComponent <SpriteRenderer>();
        string         pic = "";

        switch (type)
        {
        case ItemType.ROAD_TILE:
            pic = ResMap.IMAGE_TILE;
            break;

        case ItemType.FLAG:
            pic = ResMap.IMAGE_FLAG;
            break;

        case ItemType.TREE:
            pic = ResMap.IMAGE_TREE;
            break;

        case ItemType.CAR:
            pic = ResMap.IMAGE_CAR;
            break;

        default:
            pic = ResMap.IMAGE_TILE;
            break;
        }
        Texture2D tex = TextureCache.main.Load(pic);

        rd.sprite = LoadTexture.CreateSprieFromTex(tex);
        BoxCollider box = gameObject.AddComponent <BoxCollider>();

        box.size = new Vector2(tex.width / 100f, tex.height / 100f);

        if (type != ItemType.ROAD_TILE)
        {
            float scale = Common.GetBestFitScale(tex.width / 100f, tex.height / 100f, w, h);
            this.gameObject.transform.localScale = new Vector3(scale, scale, 1f);
        }
    }