当前位置:网站首页>Change the material of unity model as a whole
Change the material of unity model as a whole
2022-04-23 20:10:00 【m_ dlwlrma】
using System;
using System.Collections.Generic;
using UnityEngine;
public class ModelTransparent : MonoBehaviour
{
/// <summary>
/// Used to save the original of the model Material
/// </summary>
[HideInInspector] public List<MaterialList> Material_List = new List<MaterialList>();
/// <summary>
/// Transparent material
/// </summary>
public Material MaterialTransparent;
private void Awake()
{
RecordOriginalMaterials();
}
/// <summary>
/// Record the original material of the model
/// </summary>
void RecordOriginalMaterials()
{
MeshRenderer[] rendererArray = GetComponentsInChildren<MeshRenderer>();
if (rendererArray.Length != 0)
{
Material_List.Clear();
for (int i = 0; i < rendererArray.Length; i++)
{
int temp = i;
Material[] materialArray = rendererArray[temp].materials;
MaterialList materialList = new MaterialList();
if (materialArray.Length != 0)
{
for (int j = 0; j < materialArray.Length; j++)
{
int tempNumber = j;
materialList.materialData.Add(materialArray[tempNumber]);
}
Material_List.Add(materialList);
}
}
}
}
/// <summary>
/// Model transparency
/// </summary>
public void ChangeModelForTransparent()
{
MeshRenderer[] rendererArray = GetComponentsInChildren<MeshRenderer>();
if (rendererArray.Length != 0)
{
for (int i = 0; i < rendererArray.Length; i++)
{
int temp = i;
Material[] ma = rendererArray[temp].materials;
if (ma.Length != 0)
{
for (int j = 0; j < ma.Length; j++)
{
ma[j] = MaterialTransparent;
}
}
rendererArray[temp].materials = ma;
}
}
}
/// <summary>
/// Restore the original material of the model
/// </summary>
public void ChangeModelMaterialForOriginal()
{
MeshRenderer[] rendererArray = GetComponentsInChildren<MeshRenderer>();
if (rendererArray.Length != 0)
{
for (int i = 0; i < rendererArray.Length; i++)
{
int temp = i;
if (i < Material_List.Count)
{
rendererArray[temp].materials = Material_List[temp].materialData.ToArray();
}
}
}
}
}
[Serializable]
public class MaterialList
{
public List<Material> materialData = new List<Material>();
public MaterialList()
{
}
public MaterialList(List<Material> materials)
{
materialData = materials;
}
}
Test:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
private ModelTransparent _modelTransparent;
public GameObject TestGameObject;
public List<Button> btns;
void Start()
{
_modelTransparent = TestGameObject.GetComponent<ModelTransparent>();
btns[0].onClick.AddListener(delegate {
_modelTransparent.ChangeModelForTransparent(); });
btns[1].onClick.AddListener(delegate {
_modelTransparent.ChangeModelMaterialForOriginal(); });
}
}
版权声明
本文为[m_ dlwlrma]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232008560976.html
边栏推荐
- Esp8266 - beginner level Chapter 1
- 山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(五)
- 指针数组与数组指针的区分
- 如何在BNB鏈上創建BEP-20通證
- 数据库查询 - 选课系统
- MySQL数据库 - 单表查询(一)
- LeetCode异或运算
- MFC obtains local IP (used more in network communication)
- 【webrtc】Add x264 encoder for CEF/Chromium
- C6748 software simulation and hardware test - with detailed FFT hardware measurement time
猜你喜欢

Class loading process of JVM

深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件

AQS learning

【目标跟踪】基于帧差法结合卡尔曼滤波实现行人姿态识别附matlab代码

SIGIR'22「微软」CTR估计:利用上下文信息促进特征表征学习

波场DAO新物种下场,USDD如何破局稳定币市场?

PHP reference manual string (7.2000 words)

DTMF双音多频信号仿真演示系统
![[text classification cases] (4) RNN and LSTM film evaluation Tendency Classification, with tensorflow complete code attached](/img/19/27631caff199fbf13f802decbd6ead.gif)
[text classification cases] (4) RNN and LSTM film evaluation Tendency Classification, with tensorflow complete code attached

FFT物理意义: 1024点FFT就是1024个实数,实际进入fft的输入是1024个复数(虚部为0),输出也是1024个复数,有效的数据是前512个复数
随机推荐
NC basic usage 4
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(五)
Is the wechat CICC wealth high-end zone safe? How to open an account for securities
Kubernetes introduction to mastery - ktconnect (full name: kubernetes toolkit connect) is a small tool based on kubernetes environment to improve the efficiency of local test joint debugging.
NC basic usage
Openharmony open source developer growth plan, looking for new open source forces that change the world!
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
Software College of Shandong University Project Training - Innovation Training - network security shooting range experimental platform (8)
Local call feign interface message 404
【webrtc】Add x264 encoder for CEF/Chromium
Kubernetes entry to mastery - bare metal loadbalance 80 443 port exposure precautions
Compact CUDA tutorial - CUDA driver API
filebeat、logstash配置安装
对普通bean进行Autowired字段注入
渤海期货这家公司怎么样。期货开户办理安全?
MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte
Inject Autowired fields into ordinary beans
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
R语言ggplot2可视化:ggplot2可视化散点图并使用geom_mark_ellipse函数在数据簇或数据分组的数据点周围添加椭圆进行注释
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行BoxCox变换处理(将非正态分布数据列转换为正态分布数据、不可以处理负数)、设置method参数为BoxCox