Exemple #1
0
    public void OnServerPositionUpdate(NetworkMessage netmsg)
    {
        ObjPosMsg msg = netmsg.ReadMessage <ObjPosMsg>();
        string    targetObjectName = msg.gameObjectName;

        GameObject targetGameObject = gameObjectList[targetObjectName];

        if (targetGameObject == null)
        {
            targetGameObject = GameObject.Find(targetObjectName);
        }

        if (targetGameObject != null)
        {
            gameObjectList[targetObjectName] = targetGameObject;

            if (msg.isLocal)
            {
                targetGameObject.transform.localPosition = msg.position;
            }
            else
            {
                targetGameObject.transform.position = msg.position;
            }
        }
    }
Exemple #2
0
    public void UpdatePosition(string targetObjectName, Vector3 position, bool isLocal = false, int channel = Channels.DefaultUnreliable)
    {
        GameObject targetGameObject;

        if (!gameObjectList.ContainsKey(targetObjectName))
        {
            targetGameObject = GameObject.Find(targetObjectName);
        }
        else
        {
            targetGameObject = gameObjectList[targetObjectName];
        }

        if (targetGameObject != null)
        {
            gameObjectList[targetObjectName] = targetGameObject;

            ObjPosMsg msg = new ObjPosMsg();
            msg.gameObjectName = targetObjectName;
            msg.position       = position;
            msg.isLocal        = isLocal;

            SendToAll(PosUpdate, msg, channel);
        }
    }