private void SetDefaultValue(SerializedProperty serializedInput) { Type nodeInputType = SerializedPropertyUtils.GetSerializedPropertyType(serializedInput); NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; //Default Transform nodes to this GameObject's Transform if (nodeInputType == typeof(NodeGraphComponent.TransformInput)) { DynamicTransformRef transformRef = nodeGraphComponent.transform; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, transformRef); } //Default Material nodes to this GameObject's Renderer's material else if (nodeInputType == typeof(NodeGraphComponent.MaterialInput)) { Renderer renderer = nodeGraphComponent.GetComponent <Renderer>(); if (renderer != null) { DynamicMaterialRef materialRef = DynamicMaterialRef.InstancedMaterialRef(renderer); SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, materialRef); } } //Default GameObject nodes to this GameObject else if (nodeInputType == typeof(NodeGraphComponent.GameObjectInput)) { DynamicGameObjectRef gameObjectRef = nodeGraphComponent.gameObject; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, gameObjectRef); } }
public static DynamicMaterialRef StaticMaterialRef(Material material) { DynamicMaterialRef dynamicMaterial = new DynamicMaterialRef { _value = new MaterialRefProperty(material) }; return(dynamicMaterial); }
public static DynamicMaterialRef InstancedMaterialRef(Renderer renderer, int materialIndex = 0) { DynamicMaterialRef dynamicMaterial = new DynamicMaterialRef(); if (renderer != null) { dynamicMaterial._value = new MaterialRefProperty(renderer.materials[materialIndex], materialIndex, renderer); } return(dynamicMaterial); }