Unity数字可视化学校_昼夜(三)

news/2024/10/18 9:22:16/

1、删除不需要的

 UI

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class EnvControl : MonoBehaviour
{//UIprivate Button btnTime;private Text txtTime; //材质public List<Material> matList=new List<Material>();private List<float>  matValueList=new List<float>();// Start is called before the first frame updatevoid Awake(){btnTime = transform.Find("Canvas/Panel/btnTime").GetComponent<Button>();txtTime = transform.Find("Canvas/Panel/btnTime/Text").GetComponent<Text>();txtTime.text = "白天";btnTime.onClick.AddListener(onBtnTimeClick);}// Update is called once per framevoid Update(){}void onBtnTimeClick(){txtTime.text = txtTime.text == "白天" ? "晚上" : "白天";}
}

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;public class EnvControl : MonoBehaviour
{//UIprivate Button btnTime;private Text txtTime; //材质public List<Material> matList=new List<Material>();private List<float>  matValueList=new List<float>();//Postprivate PostProcessVolume postDay;private PostProcessVolume PostNight;//特效、光照private GameObject nightFx;private GameObject nightLight;// Start is called before the first frame updatevoid Awake(){btnTime = transform.Find("Canvas/Panel/btnTime").GetComponent<Button>();txtTime = transform.Find("Canvas/Panel/btnTime/Text").GetComponent<Text>();for (int i = 0; i < matList.Count; i++){matValueList.Add(matList[i].GetFloat("_E"));}postDay = transform.Find("Light/PostDay").GetComponent<PostProcessVolume>();PostNight = transform.Find("Light/PostNight").GetComponent<PostProcessVolume>();nightFx = transform.Find("Light/FX").gameObject;nightLight = transform.Find("Light/Night").gameObject;//初始化txtTime.text = "夜晚";btnTime.onClick.AddListener(onBtnTimeClick);}// Update is called once per framevoid Update(){}void onBtnTimeClick(){txtTime.text = txtTime.text == "白天" ? "夜晚" : "白天";//白天if (txtTime.text== "白天"){nightFx.SetActive(false);nightLight.SetActive(false);for (int i = 0; i < matList.Count; i++){matList[i].SetFloat("_E", 0f);}postDay.weight = 1.0f;PostNight.weight = 0f;UniStorm.UniStormManager.Instance.SetTime(10, 0);}//夜晚if (txtTime.text == "夜晚"){nightFx.SetActive(true);nightLight.SetActive(true);for (int i = 0; i < matList.Count; i++){//matList[i].SetFloat("_E", 1.0f);matList[i].SetFloat("_E", matValueList[i]);}postDay.weight = 0.0f;PostNight.weight = 11.0f;UniStorm.UniStormManager.Instance.SetTime(22, 0);}}private void onDestroy(){for (int i = 0; i < matList.Count; i++){matList[i].SetFloat("_E", matValueList[i]);}}
}

注意:

 

 2、DOTween

DOTween (HOTween v2) | Animation Tools | Unity Asset Store

导入

下载完成后直接导入Unity,如果是新项目第一次导入Unity,会弹出提示框提示DoTween需要初始化,如下图所示:
 

dotween utilitypanel


点击Setup DOTween按钮即可完成配置,当然如果需要自定义一些参数,可以点击Preferences选项卡来进行设置,该选项卡如下图所示:

dotween utilitypanel preferences

初始化完成后,在需要使用DoTween的地方需要引入命名空间DG.Tweening; 这里是一些官方的链接:
快速开始: http://dotween.demigiant.com/getstarted.php
官方文档: http://dotween.demigiant.com/documentation.php

3、属性变化

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;
using DG.Tweening;public class EnvControl : MonoBehaviour
{//UIprivate Button btnTime;private Text txtTime; //材质public List<Material> matList=new List<Material>();private List<float>  matValueList=new List<float>();//Postprivate PostProcessVolume postDay;private PostProcessVolume PostNight;//特效、光照private GameObject nightFx;private GameObject nightLight;// Start is called before the first frame updatevoid Awake(){btnTime = transform.Find("Canvas/Panel/btnTime").GetComponent<Button>();txtTime = transform.Find("Canvas/Panel/btnTime/Text").GetComponent<Text>();for (int i = 0; i < matList.Count; i++){matValueList.Add(matList[i].GetFloat("_E"));}postDay = transform.Find("Light/PostDay").GetComponent<PostProcessVolume>();PostNight = transform.Find("Light/PostNight").GetComponent<PostProcessVolume>();nightFx = transform.Find("Light/FX").gameObject;nightLight = transform.Find("Light/Night").gameObject;//初始化txtTime.text = "夜晚";btnTime.onClick.AddListener(onBtnTimeClick);}// Update is called once per framevoid Update(){}void onBtnTimeClick(){txtTime.text = txtTime.text == "白天" ? "夜晚" : "白天";//白天if (txtTime.text== "白天"){nightFx.SetActive(false);nightLight.SetActive(false);for (int i = 0; i < matList.Count; i++){//matList[i].SetFloat("_E", 0f);DoPropertyAnim(matList[i],"_E",0f,1f);}float weightDay = 0f;float weightNeight = 1f;DOTween.To(() => weightDay, (x) => { weightDay = x; postDay.weight = x; }, 1f, 1f);DOTween.To(() => weightNeight, (x) => { weightNeight = x; PostNight.weight = x; }, 0f, 1f);//postDay.weight = 1.0f;//PostNight.weight = 0f;UniStorm.UniStormManager.Instance.SetTime(10, 0);}//夜晚if (txtTime.text == "夜晚"){nightFx.SetActive(true);nightLight.SetActive(true);for (int i = 0; i < matList.Count; i++){//matList[i].SetFloat("_E", 1.0f);//matList[i].SetFloat("_E", matValueList[i]);DoPropertyAnim(matList[i], "_E", matValueList[i], 1f);}float weightDay = 1.0f;float weightNeight = 0f;DOTween.To(() => weightDay, (x) => { weightDay = x; postDay.weight = x; }, 0f, 1f);DOTween.To(() => weightNeight, (x) => { weightNeight = x; PostNight.weight = x; }, 1f, 1f);//postDay.weight = 0.0f;//PostNight.weight = 1.0f;UniStorm.UniStormManager.Instance.SetTime(22, 0);}}private void onDestroy(){for (int i = 0; i < matList.Count; i++){matList[i].SetFloat("_E", matValueList[i]);}}//属性动画void DoPropertyAnim(Material mat, string property, float value, float duration){float data = mat.GetFloat(property);DOTween.To(()=>data, (x) => { data=x;mat.SetFloat(property,x);},value,duration);}
}


http://www.ppmy.cn/news/1023598.html

相关文章

Jetson nano镜像备份

首先我们要做的准备工作有&#xff1a;含有镜像的 SD 卡、读卡器、安装了 ubuntu 环境的电脑。 备份步骤&#xff1a; 1、把含有镜像的卡用读卡器插到硬盘剩余空间大于 64G&#xff08;具体根据镜像大小使用&#xff09; 的 Ubuntu 电脑上&#xff0c;注意这里不能使用虚拟机…

Mysql - 配置Mysql主从复制-keepalived高可用-读写分离集群

目录 高可用&#xff1a; 为什么需要高可用呢&#xff1f; 高可用的主要作用&#xff1a; keepalived是什么&#xff1f;它用在哪里&#xff1f; 什么是VRRP协议&#xff0c;它的作用是什么&#xff1f; 搭建一个基于keepalived的高可用Mysql主从复制读写分离集群 一、项…

Nim游戏:取石头

&#xff08;一&#xff09;一堆取石头 背景&#xff1a; 在博弈论中&#xff0c;有一种称为Nim游戏的经典问题&#xff0c;它涉及到取石子的问题&#xff0c;其中有许多变种。Nim游戏是一种零和博弈&#xff0c;即两名玩家交替行动&#xff0c;每次只能从一堆物品中取走一定数…

【PythonRS】植被显示增强(多光谱、正射、照片等)

很多时候我们需要某个区域的正射图&#xff0c;虽然正射图一般都运用了匀色的算法&#xff0c;整体色彩比较均衡。但如果研究区内有大量的植被&#xff0c;这个时候植被突出显示就很有必要了。所以今天给大家分享一下使用Python对多光谱、正射影像进行植被显示增强的算法。 一、…

Mybatis查询

返回实体类&#xff0c;必须指定返回类型&#xff0c; resultType不能省略&#xff0c;并且数据库字段名与实体类不一致会填充NULL&#xff0c;实体类我们一般都是驼峰&#xff0c;数据库字段一般都是下划线&#xff0c;所以在查询的时候可以起别名解决,属性填充本质上调用的是…

centos7安装 juter notebook

下载安装脚本并执行 wget https://repo.anaconda.com/archive/Anaconda3-2023.03-0-Linux-x86_64.sh chmod x Anaconda3-2023.03-0-Linux-x86_64.sh bash Anaconda3-2023.03-0-Linux-x86_64.sh配置环境变量 cat > /etc/profile.d/anaconda.sh << EOF export PATH$PA…

AD域机器KMS自动激活

1、打开AD域控&#xff0c;点击DNS管理 2、创建其它记录 3、选择服务位置 SRV 4、输入相关信息 服务&#xff1a;_VLMCS协议&#xff1a;_TCP权重&#xff1a;100端口号&#xff1a;1688KMS服务器地址&#xff1a;10.3.0.211 5、成功&#xff0c;这时域内主机重启后&#xff0…

SpringBoot项目启动失败:共三处错误,都是依赖的问题┭┮﹏┭┮

文章目录 项目启动报错1&#xff1a;Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway项目启动报错2&#xff1a;Failed to determine a suitable driver class项目启动报错3&#xff1a;Failed to start bean documentationPluginsBootstrapp…