I have this script that get the properties by names from a shader : At the bottom I'm changing one of the properties values by giving the property name: "Vector1_570450D5"
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.PlayerLoop;
public class ChangeShaders : MonoBehaviour
{
public Material material;
public float duration = 1;
private List<string> propertiesNames = new List<string>();
private void Awake()
{
material = GetComponent<Renderer>().material;
var propertiesCount = ShaderUtil.GetPropertyCount(material.shader);
for(int i = 0; i < propertiesCount; i++)
{
propertiesNames.Add(ShaderUtil.GetPropertyName(material.shader, i));
}
}
void Update()
{
var currentValue = Mathf.Lerp(-1, 1, Mathf.PingPong(Time.time / duration, 1));
material.SetFloat("Vector1_570450D5", currentValue);
}
}
but instead typing manual the property name I want to create a class for each property name so I will be able to type inside the SetFloat something like :
material.SetFloat(myProperties.Vector1_570450D5, currentValue);
In this case there are 5 properties so I want to be able to do :
material.SetFloat(myProperties.Vector1_570450D5, currentValue);
Or
material.SetFloat(myProperties.Color_50147CDB, currentValue);
So I thought to make this script with the attribute executeallways to create a editor script only for getting the properties and then to use the properties in this mono script like in the examples I gave.
