PropertiesController
PropertiesController
Generic component used to change properties of materials. Works with Renderer
, UnityEngine.UI.Graphic
and custom renderers containing a material
property.
PropertyController
This component is used to set a generic value [int
, float
, Vector4
, Color
, Texture
].
Using in custom script
Simple
var pc = gameObject.GetOrAddComponent<PropertiesController>();
using (var setter = pc.GetPropertiesSetter()) {
setter.SetColor("_BaseColor", Color.red);
}
Event
[ExecuteInEditMode]
[RequireComponent(typeof(PropertiesController))]
public class CustomScript : MonoBehaviour {
public float Metallic = 0f;
float _oldValue = 0f;
PropertiesController _ctrl;
void Awake() {
_oldValue = Metallic;
_ctrl = GetComponent<PropertiesController>();
_ctrl.OnUpdate += UpdateProperty;
}
void OnDestroy() {
if (_ctrl == null) return;
_ctrl.OnUpdate -= UpdateProperty;
}
public void Reset() {
if (!Application.isPlaying) {
OnDestroy();
Awake();
}
}
void Update() {
if (_ctrl == null || (!_ctrl.RuntimeAutoUpdate && Application.isPlaying)) return;
if (_oldValue != Metallic) {
_ctrl.UpdateRequired = true;
oldValue = Metallic;
}
}
void UpdateProperty(PropertiesController.PropertiesSetter ps) {
ps.SetFloat("_Metallic", Metallic);
}
}