Mao
Mao
CC#
Created by Tijmen on 12/12/2023 in #help
Inheritance
public class Weapon
{
public WeaponData data;

public Init(WeaponData data)
{
//if you're doing some dependency injection approach
}

public ShootGrenade()
{
if(data.GrenadeComponent.HasGrenade)
{
//shoot grenade
}
}
}

public class WeaponData
{
public string WeaponName;

public WeaponStats WeaponStats;
public GrenadeComponent GrenadeComponent;
public LaserSightComponent LaserSightComponent;

public struct WeaponStats
{
public float WeaponDamage;
public float Capacity;
}

public struct GrenadeComponent
{
public bool HasGrenade;
public float GrenadeDamage;
}

public struct LaserSightComponent
{
public bool HasLaserSight;
public float LaserRange;
}
}
public class Weapon
{
public WeaponData data;

public Init(WeaponData data)
{
//if you're doing some dependency injection approach
}

public ShootGrenade()
{
if(data.GrenadeComponent.HasGrenade)
{
//shoot grenade
}
}
}

public class WeaponData
{
public string WeaponName;

public WeaponStats WeaponStats;
public GrenadeComponent GrenadeComponent;
public LaserSightComponent LaserSightComponent;

public struct WeaponStats
{
public float WeaponDamage;
public float Capacity;
}

public struct GrenadeComponent
{
public bool HasGrenade;
public float GrenadeDamage;
}

public struct LaserSightComponent
{
public bool HasLaserSight;
public float LaserRange;
}
}
Enjoy my crappy composition approach. I've actually tried something similar to what you have up there with generics, which turned into covariance, which turned into me digging a gigantic hole.
10 replies