在Unity Networking中执行Command时的权限警告

时间:2017-03-01 22:47:41

标签: c# unity3d unity3d-unet

我在执行[命令]时收到有关权限的警告消息,但我无法找到此警告的来源。当我拖动一个物体时,我得到了这个。

a)我不明白为什么以及在哪里收到警告信息?

b)我不明白为什么它不是本地玩家并且第二次拥有权限?

c)我不明白为什么yt是' 0' 0当localplayer和hasauthority是假的时候?

如果有人能向我解释一下,我真的很感激?向我解释一下?

我使用EasyTouch进行触摸。

//======================================================================//
//                                                                        //
//                               On_DragStart                                //
//                                                                        //
//======================================================================//

public void On_DragStart (Gesture gesture) {

    print ("On_DragStart");
    if (!isLocalPlayer) 
        return;

    if (!hasAuthority)
        return;

    if (selected_GO == null)
        return;

//        Cmd_SetAuthority(selected_GO.GetComponent<NetworkIdentity>().netId, gameObject.GetComponent<NetworkIdentity>());

}
private bool firstLoop = true;
private int yt = 0;
//======================================================================//
//                                                                        //
//                                  On_Drag                                //
//                                                                        //
//======================================================================//

public void On_Drag (Gesture gesture) {
//        print ("On_Drag");

    print ("a) " + yt + " isLocalPlayer: " + isLocalPlayer);

    if (!isLocalPlayer)
        return;

    print ("b) " + yt + " hasAuthority: " + hasAuthority);

    if (!hasAuthority)
        return;
    print ("c) " + yt + " selected_GO: " + selected_GO.name);

    if (selected_GO == null)
        return;
    print ("d) " + yt);

    if (firstLoop) {
        print ("e) " + yt);
        if (selected_GO.GetComponent<NetworkIdentity> ().hasAuthority == false) {
            print ("f) " + yt);
            var networkIdentity = selected_GO.GetComponent<NetworkIdentity>();
            var otherOwner = networkIdentity.clientAuthorityOwner;      

            networkIdentity.RemoveClientAuthority(otherOwner);  
        }


        print ("g) " + yt);

    }

    // Only allow drag if player own object
    if (selected_GO.GetComponent<NetworkIdentity> ().hasAuthority == true) {
        // Check if there have been a linecast, if so use that Game Object for drag
        print ("h) " + yt);

        if (selected_GO != null) {

            print ("i) " + yt);
            selected_GO.transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (gesture.position.x, gesture.position.y, 1f));
        } else if (gesture.pickedObject != null) {
            print ("j) " + yt);

            gesture.pickedObject.transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (gesture.position.x, gesture.position.y, 1f));
        }
    }
    print ("k) " + yt);
    yt++;
}

//======================================================================//
//                                                                        //
//                               On_DragEnd                                //
//                                                                        //
//======================================================================//

public void On_DragEnd (Gesture gesture) {
    print ("On_DragEnd");
    if (!isLocalPlayer && !hasAuthority) 
        return;

    if (selected_GO == null)
        return;

    if (containerMode) {
        DisableParentChildRelationship (_syncEngine.cardNames_SList);

        // Color all cards in container white to show that this is not a container anylonger
        foreach (string aSTR in _syncEngine.cardNames_SList) {
            temp_GO = GameObject.FindWithTag (aSTR);
            Cmd_Paint (temp_GO, Color.white);
        }
    } else {
        if (selected_GO.GetComponent<NetworkIdentity> ().hasAuthority == true) {
            Cmd_SetAuthority(selected_GO.GetComponent<NetworkIdentity>().netId, gameObject.GetComponent<NetworkIdentity>());
        }
    }


} 

以下是我在拖动时从此代码中获得的打印件:

On_DragStart
On_DragStart
a) 0 isLocalPlayer: True
b) 0 hasAuthority: True
c) 0 selected_GO: _H4_Gun
d) 0
e) 0
f) 0
g) 0
h) 0
i) 0
k) 0
a) 0 isLocalPlayer: False
Command for object without authority [netId=9]
Command for object without authority [netId=9]
Command for object without authority [netId=9]
Command for object without authority [netId=9]
a) 1 isLocalPlayer: True
b) 1 hasAuthority: True
c) 1 selected_GO: _H4_Gun
d) 1
h) 1
i) 1
k) 1
a) 0 isLocalPlayer: False
Command for object without authority [netId=9]
Command for object without authority [netId=9]
a) 2 isLocalPlayer: True
b) 2 hasAuthority: True
c) 2 selected_GO: _H4_Gun
d) 2
h) 2
i) 2
k) 2
a) 0 isLocalPlayer: False
a) 3 isLocalPlayer: True
b) 3 hasAuthority: True
c) 3 selected_GO: _H4_Gun
d) 3
h) 3
i) 3
k) 3
…etc.

0 个答案:

没有答案