Example #1
0
    /// <summary>
    /// This is so dirty i cant even look through it, possibly i'll optimize it in the future. TODO
    /// </summary>
    /// <param name="e"></param>
    private void InstantiateEntity(Entity e)
    {
        GameObject entityPrefab = Instantiate(PrefabLoader.GetEntityPrefab(), e.CurrentPosition.GetWorldPos(),
                                              Quaternion.identity) as GameObject;

        entityPrefab.transform.SetParent(transform);
        if (e is Animal)
        {
            Animal a = (Animal)e;
            entityPrefab.AddComponent <AnimalManager>().Init(a);
            entityPrefab.name = "Animal " + a.Type.ToString();
        }
        if (e is Worker)
        {
            Worker w = (Worker)e;
            entityPrefab.AddComponent <WorkerManager>().Init(w);
            entityPrefab.name = "Worker " + w.Name;
        }
        else if (e is Player)
        {
            Player p = (Player)e;
            entityPrefab.AddComponent <PlayerManager>().Init(p);
            entityPrefab.AddComponent <DialogueManager>();
            entityPrefab.name = "Player " + p.Name;
        }
        else if (e is Human)
        {
            Human h = (Human)e;
            entityPrefab.AddComponent <HumanManager>().Init(h);
            entityPrefab.name = "Human " + h.Name;
        }
        else if (e is Resource)
        {
            Resource r = (Resource)e;
            entityPrefab.AddComponent <ResourceManager>().Init(r);
            entityPrefab.name = "Resource " + r.Type;
        }
        else
        {
            entityPrefab.AddComponent <EntityManager>().Init(e);
            entityPrefab.name = "Entity " + e.ToString();
        }
        prefabs.Add(e, entityPrefab);
    }