Ejemplo n.º 1
0
        public void InstantiateSharing()
        {
            SharingStage stage = SharingStage.Instance;

            if (stage == null)
            {
                GameObject sharingObj = GameObject.Find(Sharing.name);

                if (sharingObj != null)
                {
                    stage = sharingObj.GetComponent <SharingStage>();
                }
            }

            // Instantiate Sharing.
            if (stage == null)
            {
                CreateSharingStage(null);
            }
            else
            {
                // A sharing service already exists, ensure it has the correct IP.
                if (stage.ServerAddress != SharingServiceIP)
                {
                    // IP was wrong, must reconnect.
                    stage.ConnectToServer(SharingServiceIP, stage.ServerPort);
                }
            }

            Sharing.SetActive(true);
        }
    void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage == null)
        {
            Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found.");
            return;
        }

        serverConnection = sharingStage.Manager.GetServerConnection();
        if (serverConnection == null)
        {
            Debug.Log("Cannot initialize CustomMessages. Cannot get a server connection.");
            return;
        }

        connectionAdapter = new NetworkConnectionAdapter();
        connectionAdapter.MessageReceivedCallback += OnMessageReceived;

        // Cache the local user ID
        this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();

        for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++)
        {
            if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
            {
                MessageHandlers.Add((TestMessageID)index, null);
            }

            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 初期化
    /// </summary>
    private void InitializeMessageHandler()
    {
        SharingStage sharingStage = SharingStage.Instance;

        // null check
        if (sharingStage == null)
        {
            Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found.");
            return;
        }

        serverConnection = sharingStage.Manager.GetServerConnection();
        // nullcheck
        if (serverConnection == null)
        {
            Debug.Log("Cannot Initialize CustomMessages. Cannot get a server connection.");
            return;
        }

        connectionAdapter = new NetworkConnectionAdapter();
        // SharingServiceからのメッセージを受信したときのハンドラを設定
        connectionAdapter.MessageReceivedCallback += OnMessageReceived;
        // 自分のユーザIDを取得
        LocalUserId = SharingStage.Instance.Manager.GetLocalUser().GetID();
        // 受信メッセージハンドラのdictionaryの箱を用意しておく
        for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++)
        {
            if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
            {
                MessageHandlers.Add((TestMessageID)index, null);
            }
            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 4
0
    private void InitMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage == null)
        {
            UnityEngine.Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found.");
            return;
        }

        _serverConnection = sharingStage.Manager.GetServerConnection();
        if (_serverConnection == null)
        {
            UnityEngine.Debug.Log("Cannot initialize CustomMessages. Cannot get a server connection.");
            return;
        }

        _connectionAdapter = new NetworkConnectionAdapter();
        _connectionAdapter.MessageReceivedCallback += OnMessageReceived;

        LocalUserId = SharingStage.Instance.Manager.GetLocalUser().GetID();

        foreach (var entry in _messageHandlers)
        {
            _serverConnection.AddListener((byte)entry.Key, _connectionAdapter);
        }

        if (Debug)
        {
            InvokeRepeating("SendDebugMessage", 1.0f, 5.0f);
        }
    }
Ejemplo n.º 5
0
    private void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage == null)
        {
            Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found.");
            return;
        }

        serverConnection = sharingStage.Manager.GetServerConnection();
        if (serverConnection == null)
        {
            Debug.Log("Cannot initialize CustomMessages. Cannot get a server connection.");
            return;
        }

        connectionAdapter = new NetworkConnectionAdapter();
        connectionAdapter.MessageReceivedCallback += OnMessageReceived;

        var localUser = SharingStage.Instance.Manager.GetLocalUser();

        LocalUserData.Id   = localUser.GetID();
        LocalUserData.Name = localUser.GetName();

        for (byte index = (byte)CommandType.Start; index < (byte)CommandType.UpdateScore; index++)
        {
            if (MessageHandlers.ContainsKey((CommandType)index) == false)
            {
                MessageHandlers.Add((CommandType)index, null);
            }

            serverConnection.AddListener(index, connectionAdapter);
        }
    }
        private void TryConnect()
        {
            try
            {
                if (listener == null)
                {
                    SharingStage sharingStage = SharingStage.Instance;
                    if (sharingStage && sharingStage.Manager != null)
                    {
                        NetworkConnection connection = SharingStage.Instance.Manager.GetServerConnection();

                        listener = new NetworkConnectionAdapter();
                        listener.ConnectedCallback        += OnConnected;
                        listener.DisconnectedCallback     += OnDisconnected;
                        listener.ConnectionFailedCallback += OnConnectedFailed;
                        listener.MessageReceivedCallback  += OnMessageReceived;

                        connection.AddListener((byte)MessageID.AudioSamples, listener);

                        Debug.Log("SpeakerController Start called");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Exception: " + ex);
            }
        }
Ejemplo n.º 7
0
    // 初始化消息处理器
    private void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage == null)
        {
            return;
        }

        // 获取当前Socket连接
        serverConnection = sharingStage.Manager.GetServerConnection();
        if (serverConnection == null)
        {
            return;
        }

        // 初始化消息监听
        connectionAdapter = new NetworkConnectionAdapter();
        connectionAdapter.MessageReceivedCallback += ConnectionAdapter_MessageReceivedCallback;

        // 获取当前用户在Socket服务器中生成的唯一编号
        LocalUserID = sharingStage.Manager.GetLocalUser().GetID();

        // 根据每个自定义消息,添加监听器
        for (byte index = (byte)MessageID.UserMessageIDStart; index < (byte)CustomMessageID.Max; index++)
        {
            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 8
0
    private byte[] anchorTestData      = new byte[5 * 1024 * 1024]; // 5 meg test buffer

    void Start()
    {
        for (int i = 0; i < anchorTestData.Length; ++i)
        {
            anchorTestData[i] = (byte)(i % 256);
        }

        SharingStage stage = SharingStage.Instance;

        if (stage != null)
        {
            SharingManager sharingMgr = stage.Manager;
            if (sharingMgr != null)
            {
                this.roomMgr = sharingMgr.GetRoomManager();

                this.listener = new RoomManagerAdapter();
                this.listener.RoomAddedEvent         += OnRoomAdded;
                this.listener.RoomClosedEvent        += OnRoomClosed;
                this.listener.UserJoinedRoomEvent    += OnUserJoinedRoom;
                this.listener.UserLeftRoomEvent      += OnUserLeftRoom;
                this.listener.AnchorsChangedEvent    += OnAnchorsChanged;
                this.listener.AnchorsDownloadedEvent += OnAnchorsDownloaded;
                this.listener.AnchorUploadedEvent    += OnAnchorUploadComplete;

                this.roomMgr.AddListener(this.listener);
            }
        }
    }
Ejemplo n.º 9
0
    void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage != null)
        {
            serverConnection  = sharingStage.Manager.GetServerConnection();
            connectionAdapter = new NetworkConnectionAdapter();
        }

        connectionAdapter.MessageReceivedCallback += OnMessageReceived;

        // Cache the local user ID
        this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();

        for (byte index = (byte)HoloPaintMessageID.HeadTransform; index < (byte)HoloPaintMessageID.Max; index++)
        {
            if (MessageHandlers.ContainsKey((HoloPaintMessageID)index) == false)
            {
                MessageHandlers.Add((HoloPaintMessageID)index, null);
            }

            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 10
0
    private void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage == null)
        {
            return;
        }

        serverConnection = sharingStage.Manager.GetServerConnection();
        if (serverConnection == null)
        {
            return;
        }

        connectionAdapter = new NetworkConnectionAdapter();
        connectionAdapter.MessageReceivedCallback += ConnectionAdapter_MessageReceivedCallback;

        LocalUserID = sharingStage.Manager.GetLocalUser().GetID();

        // 根据每一个customeMessageID 添加监听器
        for (byte index = (byte)MessageID.UserMessageIDStart; index < (byte)CustomMessageID.Max; ++index)
        {
            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 11
0
        private void Start()
        {
            int keywordCount = ButtonActionsResponse.Length;

            if (keywordCount > 0)
            {
                try
                {
                    string[] keywords = new string[keywordCount];
                    // Convert the struct array into a dictionary, with the keywords and the keys and the methods as the values.
                    // This helps easily link the keyword recognized to the UnityEvent to be invoked.
                    for (int index = 0; index < keywordCount; index++)
                    {
                        ButtonActionResponse buttonActionResponse = ButtonActionsResponse[index];
                        responses[index] = buttonActionResponse.Response;
                    }
                }
                catch (ArgumentException)
                {
                    Debug.LogError("Duplicate ButtonActionsResponse specified in the Inspector on " + gameObject.name + ".");
                }
            }
            else
            {
                Debug.LogError("Must have at least one ButtonActionsResponse specified in the Inspector on " + gameObject.name + ".");
            }

            shareStage = GameObject.Find("Sharing").GetComponent <SharingStage>();
        }
Ejemplo n.º 12
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (Application.isPlaying)
            {
                SharingStage networkManager = (SharingStage)target;

                SyncRoot root = networkManager.Root;

                if (root != null)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.BeginVertical();
                    {
                        EditorGUILayout.LabelField("Object Hierarchy");
                        DrawDataModelGUI(root, string.Empty);
                    }
                    EditorGUILayout.EndVertical();
                }

                // Force this inspector to repaint every frame so that it reflects changes to the undo stack
                // immediately rather than showing stale data until the user clicks on the inspector window
                Repaint();
            }
        }
Ejemplo n.º 13
0
        void InitializeMessageHandlers()
        {
            SharingStage sharingStage = SharingStage.Instance;

            if (sharingStage != null)
            {
                serverConnection  = sharingStage.Manager.GetServerConnection();
                connectionAdapter = new NetworkConnectionAdapter();
            }

            connectionAdapter.MessageReceivedCallback += OnMessageReceived;

            // Cache the local user ID
            this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();

            for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++)
            {
                if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
                {
                    MessageHandlers.Add((TestMessageID)index, null);
                }

                serverConnection.AddListener(index, connectionAdapter);
            }

            //// Add the message handler for toggling highlight
            MessageHandlers[CustomMessages.TestMessageID.ToggleHighLight] = this.ToggleHighLightMessageReceived;
            MessageHandlers[CustomMessages.TestMessageID.ToggleMRI]       = this.ToggleMRIMessageReceived;
        }
Ejemplo n.º 14
0
    /// <summary>
    /// Sets up our dictionary and registers various callbacks.
    /// </summary>
    void InitializeMessageHandlers()
    {
        SharingStage sharingStage = SharingStage.Instance;

        if (sharingStage != null)
        {
            serverConnection  = sharingStage.Manager.GetServerConnection();
            connectionAdapter = new NetworkConnectionAdapter();
        }
        // Register our OnMessageReceived function below with connection adapter,
        // so we can dispatch messages received on the network to classes that register
        // with our dictionary.
        connectionAdapter.MessageReceivedCallback += OnMessageReceived;

        // Cache the local user ID
        this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();

        for (byte index = (byte)TestMessageID.SpellMessage; index < (byte)TestMessageID.Max; index++)
        {
            if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
            {
                // Just set up the dictionary.
                MessageHandlers.Add((TestMessageID)index, null);
            }
            // Add listeners for each possible message with its index.
            serverConnection.AddListener(index, connectionAdapter);
        }
    }
Ejemplo n.º 15
0
 protected virtual void Start()
 {
     // SharingStage should be valid at this point, but we may not be connected.
     NetworkManager = SharingStage.Instance;
     if (NetworkManager.IsConnected)
     {
         Connected();
     }
     else
     {
         NetworkManager.SharingManagerConnected += Connected;
     }
 }
        private void CreateSharingStage(Transform parent)
        {
            GameObject sharing = (GameObject)GameObject.Instantiate(SV_Settings.Instance.Sharing, Vector3.zero, Quaternion.identity);

            sharing.transform.parent = parent;

            SharingStage stage = sharing.GetComponent <SharingStage>();

            if (stage == null)
            {
                stage = sharing.AddComponent <SharingStage>();
            }

            stage.ConnectToServer(SV_Settings.Instance.localIP, stage.ServerPort);
        }
        public void InstantiateSharing()
        {
            SharingStage stage = SharingStage.Instance;

            if (stage == null)
            {
                GameObject sharingObj = GameObject.Find(SV_Settings.Instance.Sharing.name);

                if (sharingObj != null)
                {
                    stage = sharingObj.GetComponent <SharingStage>();
                }
            }

            // Instantiate Sharing.
            if (stage == null)
            {
                CreateSharingStage(null);
            }

            SV_Settings.Instance.Sharing.SetActive(true);
        }
Ejemplo n.º 18
0
    // index all TestMessageID and create handlers for it
    private void InitializeMessageHandlers()
    {
        // save instance of sharing stage
        sharingStage = SharingStage.Instance;

        // if something goes wrong we stop here
        if (sharingStage == null ||
            sharingStage.Manager == null)
        {
            return;
        }

        // setup connection and adapter
        serverConnection  = sharingStage.Manager.GetServerConnection();
        connectionAdapter = new NetworkConnectionAdapter();

        // Cache the local user ID
        localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();

        AddCallbacks();

        Initialized = true;
    }
Ejemplo n.º 19
0
 protected virtual void Start()
 {
     NetworkManager = SharingStage.Instance;
     SetDataModelSource();
     RegisterToDataModel();
 }