[HOWTO] How To: Extend Surface Data
Posted: Sat Mar 30, 2024 5:03 pm
Grid Controller detects Surfaces on floors, walls, and ceilings.
Version 1.0.10 adds a GridController.CurrentFloorSurface property that returns the Surface under the player's feet.
In version 1.0.9 and earlier, you can make a subclass of GridController and override GetSurfaceUnderPosition to get the Surface, something like:
(I just typed that in here; there could be typos, etc.)
Version 1.0.10 is coming out on Monday (as of this post), so it might be simpler to just wait for it.
Whether you use 1.0.9 or 1.0.10, you can make a subclass of Surface, or a subclass of the SurfaceType ScriptableObject asset class, to add your own data. For example, if you want to damage the player when they step on certain squares, you could make a subclass of SurfaceType:
Create ScriptableObject assets of this type and assign them to Surfaces. Then you can hook into GridController's EnteredPosition event:
Version 1.0.10 adds a GridController.CurrentFloorSurface property that returns the Surface under the player's feet.
In version 1.0.9 and earlier, you can make a subclass of GridController and override GetSurfaceUnderPosition to get the Surface, something like:
Code: Select all
public class MyGridController : GridController
{
public Surface CurrentFloorSurface {get; set;}
protected override Surface GetSurfaceUnderPosition(Vector3 position, out Vector3 hitPoint)
{
CurrentFloorSurface = base.GetSurfaceUnderPosition(position, out hitPoint);
return CurrentFloorSurface;
}
}
Version 1.0.10 is coming out on Monday (as of this post), so it might be simpler to just wait for it.
Whether you use 1.0.9 or 1.0.10, you can make a subclass of Surface, or a subclass of the SurfaceType ScriptableObject asset class, to add your own data. For example, if you want to damage the player when they step on certain squares, you could make a subclass of SurfaceType:
Code: Select all
[CreateAssetMenu]
public class DamagingSurfaceType : AudioSurfaceType
{
public int damage = 0;
}
Code: Select all
GridController.Instance..EnteredPosition += CheckSurfaceOnEnteredPosition;
...
void CheckSurfaceOnEnteredPosition(Vector3 position)
{
if (GridController.Instance.CurrentFloorSurface.SurfaceType is DamagingSurfaceType damagingSurfaceType)
{
TakeDamage(damagingSurfaceType.damage);
}
}