Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ai.fluctio.fluctio-sim / Core / Components / Prefabs / HeightField / Base / HeightFieldLayer.cs
Size: Mime:
using System;
using Fluctio.FluctioSim.Common.Configuration;
using Fluctio.FluctioSim.Core.Components.Base;
using UnityEngine;

namespace Fluctio.FluctioSim.Core.Components.Prefabs.HeightField.Base
{
	[RequireComponent(typeof(TerrainType))]
	public abstract class HeightFieldLayer : EditorComponent
	{
		[field: SerializeField]
		[field: Min(Config.MinFloat)]
		public float Weight { get; private set; } = 1;

		private TerrainType TerrainType { get; set; }

		protected override void Initialize()
		{
			base.Initialize();
			TerrainType = GetComponent<TerrainType>();
			if (TerrainType == null)
			{
				Debug.LogWarning("This component should be on the same GameObject with TerrainType component");
			}
		}

		public override void OnSelfChanged()
		{
			base.OnSelfChanged();
			
			if (TerrainType == null)
			{
				throw new ArgumentNullException(nameof(TerrainType));
			}
			TerrainType.UpdateLayersList();
			TerrainType.RecreateTerrainData();
		}

		/// <summary>
		/// Returns whether the layer should be included (true) or ignored (false).
		/// For example, layer might be ignored when some of required properties are not set.
		/// </summary>
		/// <returns>true, if the layer should be included, or false if it should be ignored</returns>
		public virtual bool IncludeLayer() => enabled && Weight > 0;
		
		/// <summary>
		/// This function will be used to get layer's heights.
		/// Input is a Vector2, where x and y are both in range [0; 1]
		/// The return value should be in range [0; 1] and will be scaled later. 
		/// </summary>
		/// <param name="position">Position for requested height, both x and y are in range [0; 1]</param>
		/// <returns>Value of height in range [0; 1] at specified position</returns>
		public abstract float GetHeightAt(Vector2 position);
	}
}