Beispiel #1
0
    public FlowDevice()
    {
        deviceModel = SystemInfo.deviceModel;
        switch (SystemInfo.deviceType)
        {
        case DeviceType.Unknown:
            deviceType = UNKNOWN;
            break;

        case DeviceType.Handheld:
            deviceType = HANDHELD;
            break;

        case DeviceType.Desktop:
            deviceType = DESKTOP;
            break;
        }
        _id            = SystemInfo.deviceUniqueIdentifier;
        resolutionX    = Screen.currentResolution.width;
        resolutionY    = Screen.currentResolution.height;
        uid            = "3";
        dpi            = Screen.dpi;
        description    = SystemInfo.deviceName;
        cameraRotation = new FlowTransform(FlowCameras.mainCamera.gameObject);
    }
Beispiel #2
0
 public void Copy(FlowTransform source)
 {
     x   = source.x;
     y   = source.y;
     z   = source.z;
     q_x = source.q_x;
     q_y = source.q_y;
     q_z = source.q_z;
     q_w = source.q_w;
 }
 public FlowTransformPayload(string _tid)
 {
     data = new FlowTransform(_tid);
 }
Beispiel #4
0
    public static int processCommand(FlowEvent incoming)
    {
        int retValue = 0;

        if (cmdCbDictionary.ContainsKey(incoming.cmd))
        {
            delegate_flow_cmd cb;
            cmdCbDictionary.TryGetValue(incoming.cmd, out cb);
            cb(incoming);
            cmdCbDictionary.Remove(incoming.cmd);
        }
        if (listenerCmdDictionary.ContainsKey(incoming.cmd))
        {
            List <delegate_flow_cmd> callbacks;
            listenerCmdDictionary.TryGetValue(incoming.cmd, out callbacks);
            foreach (delegate_flow_cmd cb in callbacks)
            {
                cb(incoming);
            }
        }
        switch (incoming.cmd)
        {
        case Commands.LOGIN:
            // Successful login

#if !UNITY_WEBGL || UNITY_EDITOR
            // Debug.Log("[unity] Success in logging in!" + incoming.value + PlayerPrefs.HasKey("client_id") + PlayerPrefs.GetString("client_id"));
            if ((!(DebugPanel.instance.forceHolo || DebugPanel.instance.forceWeb) && !(PlayerPrefs.HasKey("client_id") && PlayerPrefs.GetString("client_id") != "")) ||
                (DebugPanel.instance.forceHolo && !(PlayerPrefs.HasKey("holo_client_id") && PlayerPrefs.GetString("holo_client_id") != "")) ||
                (DebugPanel.instance.forceWeb && !(PlayerPrefs.HasKey("web_client_id") && PlayerPrefs.GetString("web_client_id") != "")) &&
                !FlowNetworkManager.connection_established)
            {
                FlowDeviceCommand register = new FlowDeviceCommand(new FlowDevice());
                sendCommand(register);
            }
            else
            {
                if (DebugPanel.instance.forceWeb)
                {
                    FlowNetworkManager.identity_value = PlayerPrefs.GetString("web_client_id");
                }
                else if (DebugPanel.instance.forceHolo)
                {
                    Debug.Log("Forcing as hololens");
                    FlowNetworkManager.identity_value = PlayerPrefs.GetString("holo_client_id");
                }
                else
                {
                    FlowNetworkManager.identity_value = PlayerPrefs.GetString("client_id");
                }
                sendCommand(Commands.CONNECTION_REESTABLISHED, FlowNetworkManager.identity_value);
            }
#endif
            break;

        case Commands.LOGGING_IN:
            //Debug.Log("[unity] Getting status of logging in from client");
            break;

        case Commands.REGISTER_CLIENT:
            // Notify the enclosing web page about the status
            FlowClientCommand incomingCmd = JsonUtility.FromJson <FlowClientCommand>(FlowNetworkManager.reply);
            FlowNetworkManager.identity_value = incomingCmd.value.data._id;
#if !UNITY_WEBGL || UNITY_EDITOR
            if (DebugPanel.instance.forceHolo)
            {
                PlayerPrefs.SetString("holo_client_id", FlowNetworkManager.identity_value);
            }
            else if (DebugPanel.instance.forceWeb)
            {
                PlayerPrefs.SetString("web_client_id", FlowNetworkManager.identity_value);
            }
            else
            {
                PlayerPrefs.SetString("client_id", FlowNetworkManager.identity_value);
            }
#endif
            switch (FlowNetworkManager.clientType)
            {
            case FlowClient.CLIENT_EDITOR:
                DebugPanel.instance.identity.text           = "Edit(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                DebugPanel.instance.HUD_ClientIdentity.text = "Edit(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;

            case FlowClient.CLIENT_WEB:
                DebugPanel.instance.identity.text = "Web(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;

            case FlowClient.CLIENT_HOLOLENS:
                DebugPanel.instance.identity.text = "Holo(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;
            }
            DebugPanel.instance.client.text           = FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5);
            DebugPanel.instance.connectionStatus.text = "Disconnect";
            onRegisteredClient();
            break;

        case Commands.CONNECTION_REESTABLISHED:
            //Debug.Log("[unity] Connection re-established " + incoming.value);
            if (!FlowNetworkManager.connection_established)
            {
                FlowNetworkManager.connection_established = true;
            }
            DebugPanel.instance.connectionStatus.text = "Disconnect";
#if !UNITY_WEBGL || UNITY_EDITOR
            if (DebugPanel.instance.forceHolo)
            {
                if (!PlayerPrefs.HasKey("holo_client_id"))
                {
                    PlayerPrefs.SetString("holo_client_id", FlowNetworkManager.identity_value);
                }
            }
            else if (DebugPanel.instance.forceWeb)
            {
                if (!PlayerPrefs.HasKey("web_client_id"))
                {
                    PlayerPrefs.SetString("web_client_id", FlowNetworkManager.identity_value);
                }
            }
            else
            if (!PlayerPrefs.HasKey("client_id"))
            {
                PlayerPrefs.SetString("client_id", FlowNetworkManager.identity_value);
            }
            FlowNetworkManager.identity_value = incoming.value.data;
#elif UNITY_WEBGL
            FlowNetworkManager.identity_value = incoming.value.data;
#endif
            switch (FlowNetworkManager.clientType)
            {
            case FlowClient.CLIENT_EDITOR:
                DebugPanel.instance.identity.text = "Edit(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;

            case FlowClient.CLIENT_WEB:
                DebugPanel.instance.identity.text = "Web(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;

            case FlowClient.CLIENT_HOLOLENS:
                DebugPanel.instance.identity.text = "Holo(" + FlowNetworkManager.identity_value.Substring(FlowNetworkManager.identity_value.Length - 5, 5) + ")";
                break;
            }
            onRegisteredClient();
            break;

        case Commands.ERROR:
#if !UNITY_WEBGL || UNITY_EDITOR
            Debug.Log("[unity] Error" + incoming.value);
            PlayerPrefs.DeleteAll();
            FlowNetworkManager.identity_value = "-1";
            FlowDeviceCommand registercmd = new FlowDeviceCommand(new FlowDevice());
            sendCommand(registercmd);
#endif
            break;

        case Commands.PING:
            sendCommand(Commands.PONG, "0");
            break;

        case Commands.SET_BACKDROP:
            Debug.Log("Setting backdrop");
            Canvas mainCanvas = GameObject.Find("Canvas").GetComponent <Canvas>();
            mainCanvas.gameObject.SetActive(incoming.value.data != "0");
            break;

        case Commands.Transform.UPDATE:
            FlowTransformCommand trans_update_cmd = (FlowTransformCommand)JsonUtility.FromJson <FlowTransformCommand>(FlowNetworkManager.reply);
            FlowTransform        transform2       = FlowProject.activeProject.transformsById[trans_update_cmd.transform._id];
            if (trans_update_cmd.transform._id != "0")
            {
                transform2.Copy(trans_update_cmd.transform);
                transform2.Update();
            }
            // This Code is only for calibration and assumes pre-decided IDs
            break;

        default:
            break;
        }
        return(retValue);
    }