Unity3d C#实现编辑器不运行状态下执行的脚本

第一章方式:

函数前面 + [ContextMenu("Play")] ,Inspector面板右键调用

第二种方式:

OnValidate() ,值改变自动执行

cs 复制代码
using UnityEngine;
using System.Linq;

public class NightController : MonoBehaviour
{
    public float m_fEmissionInstensity = 0;
    public Material[] m_NightMats;

    // Start is called before the first frame update
    void OnValidate()
    {
        m_NightMats.ToList().ForEach(_ =>
        {
            _.SetFloat("_Emission_Intensity", m_fEmissionInstensity);
        });
    }


    [ContextMenu("Play")]
    void Play()
    {
        m_NightMats.ToList().ForEach(_ =>
        {
            _.SetFloat("_Emission_Intensity", m_fEmissionInstensity);
        });
    }
}
相关推荐
朝新_2 小时前
【多线程初阶】阻塞队列 & 生产者消费者模型
java·开发语言·javaee
立莹Sir2 小时前
Calendar类日期设置进位问题
java·开发语言
CoderIsArt2 小时前
C#中的CLR属性、依赖属性与附加属性
c#
风逸hhh3 小时前
python打卡day46@浙大疏锦行
开发语言·python
火兮明兮3 小时前
Python训练第四十三天
开发语言·python
ascarl20104 小时前
准确--k8s cgroup问题排查
java·开发语言
fpcc5 小时前
跟我学c++中级篇——理解类型推导和C++不同版本的支持
开发语言·c++
莱茵菜苗5 小时前
Python打卡训练营day46——2025.06.06
开发语言·python
爱学习的小道长5 小时前
Python 构建法律DeepSeek RAG
开发语言·python
程序猿小D5 小时前
第16节 Node.js 文件系统
linux·服务器·前端·node.js·编辑器·vim