示例#1
0
    public void DeleteObject(MainJsonObject obj)
    {
        if (!objects.ContainsKey(obj.contentObj.id))
        {
            throw new Exception("Id not used !");
        }
        MainObject o  = objects[obj.contentObj.id];
        int        id = o.GetId();

        SendMessage(obj);
        objects.Remove(o.GetId());
        Destroy(o.gameObject);
        Debug.Log("Destroy " + o.type);
    }
示例#2
0
    public void CreateObject(MainJsonObject obj)
    {
        if (objects.ContainsKey(obj.contentObj.id))
        {
            throw new Exception("Id already used");
        }
        ObjectType type     = (ObjectType)obj.contentObj.type;
        MainObject prefab   = prefabs[type];
        Vector3    position = new Vector3(obj.contentObj.coordX, obj.contentObj.coordY, obj.contentObj.coordZ);
        GameObject go       = Instantiate(prefab.gameObject, position, Quaternion.identity);
        MainObject o        = go.GetComponent <Object3D>();

        o.SetId(obj.contentObj.id);
        o.SetEulerRotation(obj.contentObj.rotX, obj.contentObj.rotY, obj.contentObj.rotZ);
        o.SetSize(obj.contentObj.dimX, obj.contentObj.dimY, obj.contentObj.dimZ);
        objects.Add(o.GetId(), o);
        Debug.Log("Created " + o.type);
    }
示例#3
0
    private void SendMessage(MainJsonObject obj, ContentJsonObject contentObj = null)
    {
        MainObject      o       = objects[obj.contentObj.id];
        int             id      = o.GetId();
        SendMessageJson jsonObj = new SendMessageJson();
        ObjectType      type    = (ObjectType)obj.contentObj.type;

        jsonObj.action = obj.action;
        jsonObj.type   = prefabs[type].ToString();
        jsonObj.msgId  = obj.msgId;
        jsonObj.objId  = id;
        if (contentObj != null)
        {
            jsonObj.contentObj = contentObj;
        }
        string message = JsonConvert.SerializeObject(jsonObj);

        NetworkManager.Instance.Send(message);
    }