• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Unity实现通用的信息提示框

c# 搞代码 4年前 (2022-01-09) 20次浏览 已收录 0个评论

本文实例为大家分享了Unity实现信息提示框的具体代码,供大家参考,具体内容如下

1、创建一个信息提示框添加InfoTipsFrameScale脚本(然后将其制作为预制体)

2、编写该信息提示框的控制脚本

/***
* Title:"智慧工厂" 项目
* 主题:全局层:提示框的动画效果
* Description:
* 功能:实现提示框的缩放功能
* Date:2018
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Global;
using kernal;
using UnityEngine.UI;
 
namespace View
{
 public class InfoTipsFrameScale : Global_baseScalePopUp
  {
    private ScaleType _ScaleType = ScaleType.Scale;    //缩放类型为Scale
    public Button btnClose;      //关闭按钮
    public Text text_TipsTitle;     //提示框的标题
    public Text text_TipsContent;   //提示框的内容
 
 
 
    private void Start()
    {
      //注册相关按钮
      ResigterBtn();
    }
 
 
    //注册按钮
    /// <summary>
    /// 注册相关按钮
    /// </summary>
    public void ResigterBtn()
    {
      if (btnClose != null)
      {
        EventTriggerListener.Get(btnClose.gameObject).onClick += BtnCloseMethod;
      }
    }
 
    /// <summary>
    /// 缩放基础设置
    /// </summary>
    public void BaseSettings()
 {
      //物体基础缩放设置
      base.needScaleGameObject = this.gameObject.transform;
      base.needScaleGameObject.gameObject.SetActive(false);
      base.needScaleGameObject.localScale = new Vector3(0, 0, 0);
 
    }
 
 
 
    /// <summary>
    /// 开启缩放
    /// </summary>
    public void StartScale()
    {
      this.gameObject.SetActive(true);
      //物体基础缩放设置
      base.ScaleMenu();
    }
 
    /// <summary>
    /// 关闭按钮的方法
    /// </summary>
    /// <param name="go"></param>
    private void BtnCloseMethod(GameObject go)
    {
      if (go==btnClose.gameObject)
      {
        //开启缩放
        StartScale();
 
        //延迟销毁物体
        Destroy(this.gameObject, Global_Parameter.INTERVAL_TIME_0DOT5);
      }
    }
 
    /// <summary>
    /// 显示提示框的标题、提示信息内容
    /// </summary>
    /// <param name="Tipstitle">提示的标题</param>
    /// <param name="TipsContents">提示的内容</<em>本文来源[email protected]搞@^&代*@码)网5</em>param>
    public void DisplayTipsFrameTextContent(string TipsContents,string Tipstitle = "信息提示")
    {
      if (text_TipsTitle!=null&&text_TipsContent!=null)
      {
        text_TipsTitle.text = Tipstitle;
        text_TipsContent.text = TipsContents;
      }
    }
 
 }//class_end
}
/***
* Title:"智慧工厂" 项目
* 主题:全局层:信息提示框的启用与隐藏
* Description:
* 功能:实现提示信息框的加载、动画显示与隐藏(单例模式)
* Date:2018
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using kernal;
using View;
 
namespace Global
{
 public class InfoTipsFrame
  {
    private static InfoTipsFrame _Instance;    //本类实例
    private Transform _InfoTipsFrame;     //信息提示框
 
 
    /// <summary>
    /// 本类实例
    /// </summary>
    /// <returns></returns>
    public static InfoTipsFrame GetInstance()
    {
      if (_Instance==null)
      {
        _Instance = new InfoTipsFrame();
      }
      return _Instance;
    }
 
 
    /// <summary>
    /// 显示信息提示框与内容
    /// </summary>
    /// <param name="Tipstitle">提示的标题</param>
    /// <param name="TipsContents">提示的内容</param>
    public void DisplayTipsFrameAndContents(GameObject infoTipsFrameParent, string TipsTitle, string TipsContents)
    {
      //获取到信息提示框且显示
      GetInfoTipFrame(infoTipsFrameParent, true);
      _InfoTipsFrame.GetComponent<InfoTipsFrameScale>().DisplayTipsFrameTextContent(TipsContents, TipsTitle);
    }
 
 
    /// <summary>
    /// 获取到信息提示框
    /// </summary>
    /// <param name="infoTipsFrameParent">信息提示框的父物体</param>
    /// <param name="IsEnable">是否启用</param>
    private void GetInfoTipFrame(GameObject infoTipsFrameParent,bool IsEnable)
    {
      _InfoTipsFrame = LoadPrefabs.GetInstance().GetLoadPrefab("TipsFrame/TipsFrame").transform;
      _InfoTipsFrame.parent = infoTipsFrameParent.transform.parent;
      _InfoTipsFrame.localPosition = new Vector3(0, 0, 0);
      _InfoTipsFrame.localScale = new Vector3(1, 1, 1);
      _InfoTipsFrame.gameObject.SetActive(IsEnable);
      if (IsEnable == true)
      {
        _InfoTipsFrame.GetComponent<InfoTipsFrameScale>().BaseSettings();
      }
      _InfoTipsFrame.GetComponent<InfoTipsFrameScale>().StartScale();
    }
 
   
 
  }//class_end
}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Unity实现通用的信息提示框
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址