Unity学习笔记/*编辑器文件操作AssetDateBase接口**/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class N : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
#if UNITY_EDITOR
        //编辑器文件操作
        //load
        Material mat = AssetDatabase.LoadAssetAtPath("Assets/Materials/m1.mat",
            typeof(Material)) as Material;//将路径对应文件取出来转化成对应文件储存
        //modify
        mat.color = Color.blue;//修改该文件的一些参数
        EditorUtility.SetDirty(mat);//告诉编译器该文件被修改
        AssetDatabase.SaveAssets();//将该文件重新保存
#endif
    }


    // Update is called once per frame
    void Update()
    {
        
    }
}

发布了5 篇原创文章 · 获赞 0 · 访问量 25

猜你喜欢

转载自blog.csdn.net/qq_42447732/article/details/105613346
今日推荐