C# 如何在Unity中加载位于资产文件夹之外的材料文件?

C# 如何在Unity中加载位于资产文件夹之外的材料文件?,c#,unity3d,C#,Unity3d,我有一个平面,我想在运行时动态加载它的材质。上述材料不在Unity项目文件夹内。如何在游戏中加载它 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Experiment : MonoBehaviour { public Material materialToChange; Material m_Material; void Start

我有一个平面,我想在运行时动态加载它的材质。上述材料不在Unity项目文件夹内。如何在游戏中加载它

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Experiment : MonoBehaviour
{
    public Material materialToChange;
    Material m_Material;

    void Start()
    {
        m_Material = GetComponent<Renderer>().material;
    }

    void Update()
    {
        if(Input.GetKeyDown("a"))
        {
            GetComponent<Renderer>().material=materialToChange;
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共课堂实验:单一行为
{
公共材料变更;
材料m_材料;
void Start()
{
m_Material=GetComponent().Material;
}
无效更新()
{
if(Input.GetKeyDown(“a”))
{
GetComponent().material=materialToChange;
}
}
}

因此,这里我希望materialToChange是一个材料文件,其路径在Unity项目文件夹之外。

Unity提供资产绑定,允许在运行时加载资产(游戏对象、材料等)。 目标是创建一个包含新材料的资产组合,例如。然后,您可以下载此资产绑定(从本地路径或web)并提取您的资产。 您将能够使用新的材料更改您的材料


看看这个页面:

为什么你不能把它放在项目内部?我会加入@gameDev_Unity的问题并补充:如果你想在以后调整颜色或纹理(图像)之类的东西,你可以从外部加载这些东西(图像文件或带有颜色和设置的JSON/XML文件)。。
材质
(这是Accord着色器的一个实例)我不会尝试从外部加载。。。