zoukankan      html  css  js  c++  java
  • Unity工具二:确定取消窗口的显示与使用

    工作项目中我们经常会遇到这个情况,例如在某个要进行提示的地方需要玩家进行选择的提示窗口,当玩家选择确定的时候才会进行到下一个页面,否则将不会进行跳转,如下图所示:

    其中当我们点击确定的时候就会跳转到下一场景,点击取消,将会关闭当前窗口:

    其中具体使用的脚本如下:

    这个脚本主要用于进行脚本功能键的控制(也就是确定和取消按键的点击方法的添加):

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    
    public class WindowPanel : MonoBehaviour {
        private Button ConfirmBtn;
        private Button CancelBtn;
    
        public static string OpenSceneName = "";
        public static bool isOpenWindows = false;
    
        private void Start()
        {
            transform.GetChild(0).gameObject.SetActive(false);
            ConfirmBtn = transform.GetChild(0).Find("ConfirmBtn").GetComponent<Button>();
            CancelBtn = transform.GetChild(0).Find("CancelBtn").GetComponent<Button>();
            ConfirmBtn.onClick.AddListener(ConfirmMethod);
            CancelBtn.onClick.AddListener(CancelMethod);
        }
    
        private void CancelMethod()
        {
            isOpenWindows = false;
        }
    
        private void ConfirmMethod()
        {
            //TODO 跳转到相应的场景
            SceneManager.LoadScene(OpenSceneName);
        }
    
        private void Update()
        {
            transform.GetChild(0).gameObject.SetActive(isOpenWindows);
        }
    }
    

      这个脚本主要进行提示消息的发送以及颜色的设置:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class ShowSetting : MonoBehaviour {
    
        private Text txt;
        public static bool isStartShowText = false;
    
        void Start()
        {
            txt = transform.Find("Text").GetComponent<Text>();
        }
        private void Update()
        {
            if (isStartShowText)
            {
                promptMessage(PromptMsg.Instance.Text, PromptMsg.Instance.Color);
                isStartShowText = false;
            }
        }
        /// <summary>
        /// 提示消息
        /// </summary>
        private void promptMessage(string text, Color color)
        {
            txt.text = text;
            txt.color = color;
        }
    }
    

     下面这个脚本主要进行的是其中跳转场景和提示信息的设置:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class ShowWindowsContent : MonoBehaviour {
    
    
    	void Update () {
            if (Input.GetKeyDown(KeyCode.A))
            {
                WindowPanel.OpenSceneName = "one";
                WindowPanel.isOpenWindows = true;
                ShowSetting.isStartShowText = true;
                PromptMsg.Instance.Change("您将要进入第一关!!!!!!",Color.red);
            }
            if (Input.GetKeyDown(KeyCode.B))
            {
                WindowPanel.OpenSceneName = "two";
    
                WindowPanel.isOpenWindows = true;
                ShowSetting.isStartShowText = true;
                PromptMsg.Instance.Change("您将要进入第二关!!!!!!", Color.green);
            }
    	}
    }
    

     以上三个脚本就能实现,窗口功能键的打开,以及跳转场景的控制,我们可以设置更好的页面图片,来重载相应的方法,写好一些方法更加有助于我们项目的开发,欢迎大家在下方的留言大家一起学习!!!!!!!!!!!!!

  • 相关阅读:
    PostGIS安装教程
    报错:尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
    flexpaper跨服务器访问swf不显示问题
    JSAPI 基于arcgis_js_api3.3的部署
    C# datatable排序(转)
    C# 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”
    C# 正则表达式
    AE10.0在Visual Studio 2012下安装没有模板(转)
    AE安装部署以及监测ArcEngine runtime 9.3是否安装
    Flex带CheckBox的Tree(修改ItemRenderer)
  • 原文地址:https://www.cnblogs.com/baosong/p/10970727.html
Copyright © 2011-2022 走看看