Graphics Generation - Maxodie/BattriKeepel2 GitHub Wiki

Generate Graphics data

The GraphicsManager is a singleton wich can be used by doing :

GraphicsManager.Get()

Practical tips

  • every TGraphicsScript is a template class using the GameEntityGraphics parent class

Create a visual in Unity

you can either generate a visual based on a GameObject prefab or a parent script in a prefab

public TGraphicsScript GenerateVisualInfos<TGraphicsScript>(GameEntityGraphics graphicsPrefab, Transform transform, IGameEntity owner, bool isChild = true, bool dontDestroyOnLoad = false) where TGraphicsScript : GameEntityGraphics

or

public GameObject GenerateVisualInfos(GameObject graphicsPrefab, Transform transform, IGameEntity owner, bool isChild = true, bool dontDestroyOnLoad = false)

EXEMPLE :

in BossGraphics.cs

public class BossGraphics : GameEntityGraphics
{
    [SerializeField] Image lifefill;
    [SerializeField] Transform projectilSpawnPoint;

    public void SetLifeAmount(float amount)
    {
        lifefill.fillAmount = amount;
    }
}

in BossManager.cs

public class Projectil : IGameEntity
{
    Projectil(GameObject projectilVisualAsGameObject, Transform spawnLocation)
    {
        GraphicsManager.Get().GenerateVisualInfos(projectilVisualAsGameObject, spawnLocation, this, false);
    }
}


class BossEntity : IGameEntity
{
    SO_BossData data;

    BossGraphics entityGraphics;
    Projectil projectil;
    public int health = 100;

    public BossEntity(SO_BossData newData, Transform spawnLocation)
    {
        data = newData;
        //BossGraphics bossGrpahics; a script taken from a prefab in order to generate the prefab and storing the scirpt

        entityGraphics = GraphicsManager.Get().GenerateVisualInfos<BossGraphics>(data.bossGraphics, spawnLocation, this);
    }

    public void TakeDamage(int amount)
    {
        health -= amount;
        entityGraphics.SetLifeAmount(health / 100.0f);
    }

    public void CreateProjectil()
    {
        projectil = new Projectil(data.projectilVisualAsGameObject, entityGraphics.projectilSpawnPoint);
    }
}

public class BossManager : GameEntityMonoBehaviour
{
    BossEntity boss;
    [SerializeField] SO_BossData bossData;
    [SerializeField] Transform spawnLocation;

    void Awake()
    {
        boss = new BossEntity(bossData, spawnLocation);
        boss.CreateProjectil();
    }
}