示例#1
0
    public void RequestRoomObjectManipulation(object data, PhotonMessageInfo info)
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            Debug.LogWarning("[RequestRoomObjectManipulation] Only Master Client can Manipulate RoomObject!");
            return;
        }

        var insData = new InstantiationData(data as object[]);

        //TODO: MC Verify data
        if (insData.tokenType != SyncTokenType.General)
        {
            Debug.LogWarning("[RequestRoomObjectManipulation] Only For Manipulate RoomObject!");
            return;
        }

        if (insData.TryGetValue(InstantiationData.InstantiationKey.objectname, out object objName))
        {
            // Object UUID
            if (!insData.ContainsKey(InstantiationData.InstantiationKey.objectuuid))
            {
                var tokenID = $"ro_{Random.Range(1000, 9999).ToString()}";
                insData[InstantiationData.InstantiationKey.objectuuid.ToString()] = tokenID;
            }

            if (insData.TryGetValue(InstantiationData.InstantiationKey.sceneobject, out object soModification))
            {
                switch ((string)soModification)
                {
                case "create":
                    Debug.LogWarning("[RequestRoomObjectManipulation] Create");
                    itp.RequestSyncToken(insData);
                    break;

                case "destroy":
                    photonView.RPC("RequestLocalObjectManipulation", RpcTarget.Others, insData.ToData() as object);

                    itp.RevokeSyncToken(insData);

                    iosManager.DestroyObject((string)objName, (string)insData["objectuuid"]);

                    Debug.LogWarning($"[RequestRoomObjectManipulation] MC Destroy {insData}");
                    break;
                }
            }
        }
    }
示例#2
0
    public void RequestLocalObjectManipulation(object data, PhotonMessageInfo info)
    {
        var insData = new InstantiationData(data as object[]);

        if (insData.tokenType != SyncTokenType.General)
        {
            Debug.LogWarning("[RequestLocalObjectManipulation] Only For Manipulate Local RoomObject!");
            return;
        }

        if (insData.TryGetValue("localobject", out object objName))
        {
            if (!insData.ContainsKey("objectuuid"))
            {
                return;
            }

            if (insData.TryGetValue("sceneobject", out object modifyword) && (string)modifyword == "Destroy")
            {
                iosManager.DestroyObject((string)objName, (string)insData["objectuuid"]);
            }
        }
    }