03-02-2020, 08:05 AM
Hey there,
I use this script on Build Volume Mesh of generator:
The problem is although I put that Refresh at the end of UpdateUVScale but still after changing _referenceUVScaleY value, there is no effect on the texture in the scene but in its generator the values are changed. (As you noticed I want this functionality in edit mode)
Where the problem is ? Any idea ?
I use this script on Build Volume Mesh of generator:
Code:
public class VolumeMeshController : MonoBehaviour
{
[SerializeField] private float _referenceUVScaleY = 0.07f;
[SerializeField] private bool _flip = false;
}
Code:
[CustomEditor(typeof(VolumeMeshController))]
public class VolumeMeshControllerEditor : UnityEditor.Editor
{
private SerializedProperty _referenceUVScaleYProperty;
private SerializedProperty _flipProperty;
private Transform _transform;
private BuildVolumeMesh _buildVolumeMesh;
void OnEnable()
{
_transform = (target as VolumeMeshController).transform;
_buildVolumeMesh = _transform.GetComponent<BuildVolumeMesh>();
GetSerialiezedProperties();
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
serializedObject.Update();
UpdateUV();
// Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
serializedObject.ApplyModifiedProperties();
}
private void GetSerialiezedProperties()
{
_referenceUVScaleYProperty = serializedObject.FindProperty("_referenceUVScaleY");
_flipProperty = serializedObject.FindProperty("_flip");
}
private void UpdateUVScale()
{
int flip = !_flipProperty.boolValue ? 1 : -1;
CGVolume data = _buildVolumeMesh.InVolume.GetData<CGVolume>();
_buildVolumeMesh.MaterialSetttings[0].UVScale.x = flip;
_buildVolumeMesh.MaterialSetttings[0].UVScale.y = data.Length * flip * _referenceUVScaleYProperty.floatValue;
_buildVolumeMesh.Refresh();
}
}
The problem is although I put that Refresh at the end of UpdateUVScale but still after changing _referenceUVScaleY value, there is no effect on the texture in the scene but in its generator the values are changed. (As you noticed I want this functionality in edit mode)
Where the problem is ? Any idea ?