常用组件的动态修改

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIController : MonoBehaviour {

    public UITexture myTexture;
    public UIPanel myPanel;
    public UIButton myButton;
    public UILabel myLabel;
    public UISprite mySprite;

    // Use this for initialization
    void Start () {
        myPanel = GetComponent<UIPanel> ();
        //myPanel.alpha = 0.5f;
        myPanel.depth = 10;//修改深度
        myPanel.renderQueue = UIPanel.RenderQueue.StartAt;
        myPanel.startingRenderQueue = 3000;//这个功能与depth有些冲突,因为它是决定渲染次序的终极手段
        //特别是做粒子系统的时候希望粒子显示在UI上面的时候,就要考虑渲染的次序,粒子的渲染队列是3000,所以要把渲染队列调的更低

        myLabel = myPanel.GetComponentInChildren<UILabel> ();
        myLabel.enabled = true;
        //myLabel.text = "Flashloft一定要东山再起!";
        myLabel.fontSize = 100;
        //myLabel.color = new Color (1, 0, 0);
        //myLabel.color = Color.red;
        //myLabel.text = "Flashloft[c]之后的文字颜色不会变化!";
        myLabel.text = "[0000ff]Flashloft[-]之后的文字颜色不会变化!";

        mySprite = myPanel.GetComponentInChildren<UISprite> ();
        mySprite.enabled = true;
        mySprite.gameObject.SetActive (true);
        mySprite.spriteName = "playBtn_high";
        mySprite.width = 144;
        mySprite.height = 164;

        myButton = myPanel.GetComponentInChildren<UIButton> ();
        UILabel buttonLabel = myButton.GetComponentInChildren<UILabel> ();
        buttonLabel.text = "new";
        myButton.gameObject.SetActive (true);
        myButton.enabled = false;

        myTexture = myPanel.GetComponentInChildren<UITexture> ();
        myTexture.SetDimensions (50, 50);
    }

    // Update is called once per frame
    void Update () {

    }
}

results matching ""

    No results matching ""