unity学习(5)——panel

1.unity和vs中都需要主动按ctrl+s,同时在unity中一定要注意退出游戏的执行状态,要不就都白干了。

2.制作注册panel,也是ui的一种而已,再在panel中做一下上一篇的内容。

3.因为这次最后加的image,遮挡住了复制过来的text input 和button,需要调整面板内部ui的上下关系。直接在hierarchy中上下拖动即可,立竿见影。panel和其他的控件之间也存在这种层级关系。

4.为panel挂载如下脚本,这样就可以初始化时隐藏注册panel了。当然用2中的办法也是可以的,后者符合学习过程。

using UnityEngine;
using System.Collections;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
}

5.点击“注册”按钮打开panel,用的也是SetActive方法。把open方法给登录界面的注册按钮。

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
}

6.点击按钮关闭panel。用的也是SetActive方法。把close方法给panel界面的取消按钮。

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
    public void Close()
    {
        gameObject.SetActive(false);
    }
}

7.同理在登陆界面右上角增加一个红色退出按钮

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
    public void Close()
    {
        gameObject.SetActive(false);
    }
    public void Exit()
    {
        #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;//在Unity编译器中结束运行
        #else
            Application.Quit();//在可执行程序中结束运行
        #endif
    }
}

你可能感兴趣的:(学习)