Quick Test
Put this script a game object to instance procedural materials at start up
Please note you will have to change the resource path to your substance locations
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AssignmentTest : MonoBehaviour {
public GameObject cube1;
public GameObject cube2;
public GameObject cube3;
// Use this for initialization
void Start()
{
// Load some procedural materials
ProceduralMaterial mat1 = Resources.Load("Allegorithmic Database 2.1/Brick/boulder_stone_wall", typeof(ProceduralMaterial)) as ProceduralMaterial;
ProceduralMaterial mat2 = Resources.Load("Allegorithmic Database 2.1/Brick/brick_castle_bumpy", typeof(ProceduralMaterial)) as ProceduralMaterial;
// Instance some procedural materials
InstanceSubstance(cube1, mat1);
InstanceSubstance(cube2, mat1);
InstanceSubstance(cube3, mat2);
// Change some standard shader values
cube1.GetComponent<MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1f, 1f));
cube2.GetComponent<MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(2f, 2f));
cube3.GetComponent<MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(3f, 3f));
// Change some standard procedural values
((ProceduralMaterial)cube1.GetComponent<MeshRenderer>().material).SetProceduralFloat("saturation", 0.5f);
((ProceduralMaterial)cube2.GetComponent<MeshRenderer>().material).SetProceduralFloat("saturation", 0.7f);
((ProceduralMaterial)cube3.GetComponent<MeshRenderer>().material).SetProceduralFloat("saturation", 0.9f);
}
private void InstanceSubstance(GameObject go, ProceduralMaterial mat)
{
GameObject tmpGo = new GameObject("_tmpObj");
MeshRenderer tmpRenderer = tmpGo.AddComponent<MeshRenderer>();
tmpRenderer.material = mat;
go.GetComponent<MeshRenderer>().material = tmpRenderer.material;
DestroyImmediate(tmpGo);
}
}