Ejemplo n.º 1
0
    /// <summary>
    /// Création des entités créées, destruction des entités détruites,
    /// et synchronisation des autres.
    /// </summary>
    /// <param name="stateUpdate"></param>
    public void OnStateUpdate(BloodAndBileEngine.Networking.Messaging.NetworkMessages.StateUpdateMessage stateUpdate)
    {
        // Synchronisation
        // Chaque EntitySynchronizationDataObject a un identifiant d'entité à synchroniser, il suffit donc
        // d'appliquer la synchronisation à l'entité en question.
        BloodAndBileEngine.EntitySynchronizationDataObject[] synchObject = (BloodAndBileEngine.EntitySynchronizationDataObject[])(stateUpdate.GetStateUpdateInfo("EntitySynchronization")[0].Information);
        if (synchObject == null || synchObject.Length == 0)
        {
            BloodAndBileEngine.Debugger.Log("ERREUR : pas de EntitySynchronizationDataObject !", UnityEngine.Color.red);
        }
        foreach (BloodAndBileEngine.EntitySynchronizationDataObject SynchData in synchObject)
        {
            BloodAndBileEngine.Entity entity = BloodAndBileEngine.EntitiesManager.GetEntityFromID(SynchData.GetEntityID());
            BloodAndBileEngine.EntitySynchroniserComponent synchComponent = (BloodAndBileEngine.EntitySynchroniserComponent)entity.GetComponent(typeof(BloodAndBileEngine.EntitySynchroniserComponent));
            if (synchComponent != null)
            {
                synchComponent.GetSynchronizationData().SetSynchInfoFromSynchObject(SynchData);

                synchComponent.OnSynch();
            }
        }
    }
Ejemplo n.º 2
0
        static void SetEntityPosition(object[] args)
        {
            if (args.Length < 4)
            {
                Debugger.Log("ERREUR : Pas assez de paramètres dans l'appel de la commande SetEntityPosition !", UnityEngine.Color.red);
                return;
            }

            uint  ID;
            float posX;
            float posY;
            float posZ;

            // On vérifie que chaque argument soit du bon type. S'ils ne le sont pas, on les converti.
            if (args[0] is uint)
            {
                ID = (uint)args[0];
            }
            else
            {
                if (!(args[0] is string) || !uint.TryParse((string)args[0], out ID))
                {
                    Debugger.Log("ERREUR : Commande SetEntityPosition - L'ID de l'entité doit être un entier ou une chaine de caractères !");
                    return;
                }
            }

            if (args[1] is float)
            {
                posX = (float)args[1];
            }
            else
            {
                if (!(args[1] is string) || !float.TryParse((string)args[1], out posX))
                {
                    Debugger.Log("ERREUR : Commande SetEntityPosition - La position X de l'entité doit être un entier ou une chaine de caractères !");
                    return;
                }
            }


            if (args[2] is float)
            {
                posY = (float)args[2];
            }
            else
            {
                if (!(args[2] is string) || !float.TryParse((string)args[2], out posY))
                {
                    Debugger.Log("ERREUR : Commande SetEntityPosition - La position Y de l'entité doit être un entier ou une chaine de caractères !");
                    return;
                }
            }

            if (args[3] is float)
            {
                posZ = (float)args[3];
            }
            else
            {
                if (!(args[3] is string) || !float.TryParse((string)args[3], out posZ))
                {
                    Debugger.Log("ERREUR : Commande SetEntityPosition - La position Z de l'entité doit être un entier ou une chaine de caractères !");
                    return;
                }
            }

            // Tout est bon ! La position de l'entité peut être changée. Si l'entité est détruite, affichage d'un warning.

            Entity e = GetEntityFromID(ID);

            if (e == null || e.Destroyed)
            {
                Debugger.Log("WARNING : Tentative de modifier la position de l'entité " + ID + " qui n'existe pas ou est détruite !", UnityEngine.Color.yellow);
            }

            if (e != null)
            {
                SerializableVector3 newPos = new SerializableVector3(posX, posY, posZ);
                if (e.GetComponent(typeof(EntityMover)) != null)
                {
                    e.GetComponent <EntityMover>().Teleport(newPos.z, newPos.x);
                }
                else
                {
                    e.Position = newPos;
                }
            }
        }