2

UNet とクライアント権限の割り当て方法を理解しようとしていますが、少し迷っています。これが私が達成しようとしていることです:

1) With On_LongTapEnd= コンテナ、つまり複数のオブジェクト (Orange" および "Apple") を作成します。

2) 「ポインター」を親として持ち、Orange と Apple を子として割り当てます

3)AssignClientAuthority()コンテナの動きを同期できるようにオレンジとアップルに (ポインター、オレンジ、アップル)

このコンテキストでオレンジとアップルにクライアント権限を割り当てる方法がわからないので、コンテナーを移動できます。

次のエラーが発生します。コード内の ERROR とマークされた行を参照してください。

Apple(Clone) (UnityEngine.GameObject) 所有者の AssignClientAuthority を null にすることはできません。代わりに RemoveClientAuthority() を使用してください。

誰かが私を解決策に導き、私が欠けているものを説明していただければ幸いです。

コードは次のとおりです。

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using System.Collections.Generic;

public class Pointer : NetworkBehaviour {

    public Transform myTransform;
    public HashSet<GameObject> linecast_GameObject_HashSet = new HashSet<GameObject> ();
    private List<GameObject> linecast_GameObject_List = new List<GameObject> ();
    private GameObject parentGameObject;
    private GameObject childGameObject;
    private bool firstRun = true;

    // Subscribe to events
    void OnEnable(){
        EasyTouch.On_TouchStart += On_TouchStart;
        EasyTouch.On_Drag += On_Drag;
        EasyTouch.On_DragEnd += On_DragEnd;
        EasyTouch.On_LongTapStart += On_LongTapStart;
        EasyTouch.On_LongTap += On_LongTap;
        EasyTouch.On_LongTapEnd += On_LongTapEnd;
    }
    // Unsubscribe
    void OnDisable(){
        EasyTouch.On_TouchStart -= On_TouchStart;
        EasyTouch.On_Drag -= On_Drag;
        EasyTouch.On_DragEnd -= On_DragEnd;
        EasyTouch.On_LongTapStart -= On_LongTapStart;
        EasyTouch.On_LongTap -= On_LongTap;
        EasyTouch.On_LongTapEnd -= On_LongTapEnd;
    }
    // Unsubscribe
    void OnDestroy(){
        OnDisable ();
        //EasyTouch.On_TouchStart -= On_TouchStart;
    }
    // Touch start event
    public void On_TouchStart(Gesture gesture){
    //        Debug.Log( "Touch in " + gesture.position);

        if (!isLocalPlayer)
            return;

        myTransform.position = Camera.main.ScreenToWorldPoint (new Vector3 (gesture.position.x, gesture.position.y, 1f));



    }

    public void On_LongTapStart (Gesture gesture) {
        linecast_GameObject_HashSet.Clear ();
    }

    public void On_LongTap(Gesture gesture) {

        if (!isLocalPlayer)
            return;

        HashSet<GameObject> myList = new HashSet<GameObject> ();
        myList = DoLinecast ();

    }

    public void On_LongTapEnd(Gesture gesture) {
        if (!isLocalPlayer)
            return;

        if (linecast_GameObject_HashSet.Count > 0) {

            foreach (GameObject aGO in linecast_GameObject_HashSet) {

                childGameObject = GameObject.FindWithTag (aGO.tag);
                childGameObject.GetComponent<Renderer> ().material.color = Color.green;
                childGameObject.transform.parent = myTransform.transform;

                // Assign Network Authority
                NetworkIdentity myNetID = childGameObject.GetComponent<NetworkIdentity>();
                print ("GO: " + childGameObject.tag + " // myNetID: " + myNetID.netId);
                CmdAssignNetworkAuthority (myNetID.netId);

            }

        }


        //CmdDoStuff ();
    }


    [Command]
    public void CmdAssignNetworkAuthority (NetworkInstanceId toId) {
        print ("Incoming ID: " + toId);
        GameObject client = NetworkServer.FindLocalObject (toId);
        var conn = client.GetComponent<NetworkIdentity> ().connectionToClient;
        NetworkIdentity ni = client.GetComponent<NetworkIdentity> ();

        if (ni.clientAuthorityOwner != null) {
            // Remove previous owner
            ni.RemoveClientAuthority (ni.clientAuthorityOwner);
            print ("!= : " + ni.netId + " // name: " + ni.name);
        } else if (ni.clientAuthorityOwner == null) {

            print ("== : " + ni.netId + " // name: " + ni.name);

            //============= ERROR ===============//
            //============= ERROR ===============//
            //============= ERROR ===============//
            ni.AssignClientAuthority (conn);
            // ==================================//
        }


    }

    public void On_Drag(Gesture gesture) {

        if (!isLocalPlayer)
            return;

        if (isLocalPlayer) {
            gesture.pickedObject.transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (gesture.position.x, gesture.position.y, 1f));
        }
    }

    HashSet<GameObject> DoLinecast () {
        GameObject linecast_GameObject;


        LayerMask theLayer;
        theLayer = (1 << LayerMask.NameToLayer("Fruit")); //set the layer to be clickable
        Vector2 clickedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        //Get current worldspace position of mouse cursor
        RaycastHit2D[] hits = Physics2D.LinecastAll(clickedPos,clickedPos,theLayer);

        foreach (RaycastHit2D ray in hits) {
            linecast_GameObject = GameObject.Find(ray.collider.name);
            linecast_GameObject_HashSet.Add (linecast_GameObject);
        }

        return linecast_GameObject_HashSet;
    }


    public void On_DragEnd (Gesture gesture) {

        if (linecast_GameObject_HashSet.Count > 0) {

            foreach (GameObject aGO in linecast_GameObject_HashSet) {

                childGameObject = GameObject.FindWithTag (aGO.tag);
                childGameObject.GetComponent<Renderer> ().material.color = Color.white;
                childGameObject.transform.parent = null;

            }

        }
    }





    [Command]
    public void CmdDoPrint(int xx, GameObject aGO) {
        print (xx + ") Ray: " + aGO.name);

    }

    [Command]
    public void CmdBIG() {
        print (">>>BIGGER<<<");
    }

    [Command]
    void CmdDoStuff() {
        print ("Tap End");
    }
    }
4

0 に答える 0