Repository URL to install this package:
|
Version:
1.3.2 ▾
|
using Fluctio.FluctioSim.Core.Components.Base;
using Fluctio.FluctioSim.Utils.Extensions;
using Fluctio.FluctioSim.Utils.General;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Fluctio.FluctioSim.Core.Components.Prefabs.HeightField.Base
{
public abstract class RemappedLayer: HeightFieldLayer
{
[field: SerializeField] private Vector2 StartCoords { get; set; } = Vector2.zero;
[field: SerializeField] private Vector2 EndCoords { get; set; } = Vector2.one;
public sealed override float GetHeightAt(Vector2 normalPosition)
{
var remappedPosition = VectorExtensions.Lerp(StartCoords, EndCoords, normalPosition);
return GetHeightAtRemapped(remappedPosition);
}
protected abstract float GetHeightAtRemapped(Vector2 remappedPosition);
}
#if UNITY_EDITOR
[CustomEditor(typeof(RemappedLayer), true)]
[CanEditMultipleObjects]
public class RemappedLayerEditor : EditorComponentEditor
{
private SerializedProperty _startCoords;
private SerializedProperty _endCoords;
private void GetProperty(string propertyName, out string fieldName, out SerializedProperty property)
{
fieldName = Util.GetBackingFieldName(propertyName);
property = serializedObject.FindProperty(fieldName);
}
private void DrawSlider(string component)
{
var minProperty = _startCoords.FindPropertyRelative(component);
var maxProperty = _endCoords.FindPropertyRelative(component);
var minValue = minProperty.floatValue;
var maxValue = maxProperty.floatValue;
var label = ObjectNames.NicifyVariableName(component);
EditorGUILayout.MinMaxSlider(label, ref minValue, ref maxValue, 0f, 1f);
minProperty.floatValue = minValue;
maxProperty.floatValue = maxValue;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
GetProperty("StartCoords", out var startCoordsName, out _startCoords);
GetProperty("EndCoords", out var endCoordsName, out _endCoords);
DrawPropertiesExcluding(serializedObject, "m_Script", startCoordsName, endCoordsName);
DrawSlider("x");
DrawSlider("y");
serializedObject.ApplyModifiedProperties();
}
}
#endif
}