コード例 #1
0
        // Construit une entité dans le WorldState passé en paramètre, la place
        // dans la cellule appropriée si possible et renvoi une référence si tout s'est bien passé.
        public Entity BuildEntity(uint ID, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot, float size, float height)
        {
            Debugger.Log("Building entity ID " + ID);
            Entity newEntity = EntitiesManager.GetEntityFromID(ID);

            if (!newEntity.Destroyed) // Cet ID est déjà prit par une entité en vie !
            {
                return(null);
            }
            newEntity.Destroyed = false;
            // Destruction des components existants
            newEntity.Reset();

            // Assignation du WorldState à l'entité
            newEntity.SetWorldState(World);
            if (World == null)
            {
                Debugger.Log("ERREUR : Pas de worldstate !", UnityEngine.Color.red);
            }
            // Placement de l'entité sur une cellule.
            CellSystem cellSystem = World.GetData <CellSystem>();

            if (cellSystem != null)
            {
                Cell cell = cellSystem.GetCellFromPosition(pos.z, pos.x);
                if (cell != null)
                {
                    cell.AddEntity(newEntity);
                }
                else
                {
                    Debugger.Log("ERREUR : Pas de Cell trouvée lors de la création de l'entité " + ID);
                }
            }
            else
            {
                Debugger.Log("ERREUR : Pas de CellSystem lors de la création de l'entité " + ID);
            }
            newEntity.AddComponent(typeof(EntitySynchroniserComponent));
            newEntity.AddComponent(typeof(EntityMover));

            newEntity.Position = pos;
            newEntity.Rotation = rot;
            newEntity.Height   = height;
            newEntity.Size     = size;

            // Appel du callback
            if (OnEntityCreated != null)
            {
                OnEntityCreated(newEntity);
            }


            return(newEntity);
        }
コード例 #2
0
    static public void OnEntityCreation(uint EntityID)
    {
        Entity e = EntitiesManager.GetEntityFromID(EntityID);

        if (e == null)
        {
            Debugger.Log("ERREUR : Cet ID d'entité n'existe pas, ou alors la mémoire des entités n'a pas été initialisée !", UnityEngine.Color.red);
            return;
        }

        // Création du GameObject

        UnityEngine.GameObject entityGO = UnityEngine.GameObject.Instantiate <UnityEngine.GameObject>((UnityEngine.GameObject)UnityEngine.Resources.Load("Prefabs/EntityPrefab"));
        // Ajout du component Actor & assignation de l'entité

        entityGO.AddComponent <Actor>().SetEntityID(EntityID);

        // Terminé.
    }
コード例 #3
0
        // Construit un joueur dans le WorldState passé en paramètre, le place
        // dans la cellule appropriée si possible et renvoie une référence si tout s'est bien passé.
        static public Entity BuildPlayer(WorldState.WorldState world, uint ID, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot, float size, float height)
        {
            Debugger.Log("Building entity ID " + ID);
            Entity newEntity = EntitiesManager.GetEntityFromID(ID);

            if (!newEntity.Destroyed) // Cet ID est déjà prit par une entité en vie !
            {
                return(null);
            }
            newEntity.Destroyed = false;
            // Destruction des components existants
            newEntity.Reset();

            // Assignation du WorldState à l'entité
            newEntity.SetWorldState(world);

            // Placement de l'entité sur une cellule.
            CellSystem cellSystem = world.GetData <CellSystem>();

            if (cellSystem != null)
            {
                Cell cell = cellSystem.GetCellFromPosition(pos.z, pos.x);
                if (cell != null)
                {
                    cell.AddEntity(newEntity);
                }
                newEntity.AddComponent(typeof(EntitySynchroniserComponent));
                newEntity.AddComponent(typeof(EntityMover));
                newEntity.AddComponent(typeof(SpellComponent));
                newEntity.AddComponent(typeof(HumorsComponent));

                SerializableVector3 newPos = new SerializableVector3(pos.x, pos.y + size, pos.z);
                newEntity.Position = newPos;
                newEntity.Rotation = rot;
                newEntity.Height   = height;
                newEntity.Size     = size;

                return(newEntity);
            }

            // Si ce code est atteint, c'est qu'il y a eu un problème lors de la création de l'entité.
            return(null);
        }