private void Update()
    {
        switch (state)
        {
        case State.btserver:
            string message = bluetooth.Call <string>("GetMessage");
            if (!string.IsNullOrEmpty(message))
            {
                if (message == "connected")
                {
                    state = State.broadcaster;
                    if (bluetoothConnectedCallback != null)
                    {
                        bluetoothConnectedCallback(true);
                    }
                }
                else
                {
                    DebugText.LogImportant(message);
                    if (bluetoothConnectedCallback != null)
                    {
                        bluetoothConnectedCallback(false);
                    }
                    Disconnect();
                }
            }
            break;

        case State.broadcaster:
            time -= Time.deltaTime;
            if (time < 0)
            {
                time += sendInterval;
                if (scenarioManager.gameObject.activeSelf)
                {
                    data = new MessageData(this);
                    Send(data.ToString());
                }
                else
                {
                    Send("idle");
                }
            }
            break;

        case State.observer:
            string msg = bluetooth.Call <string>("GetMessage");
            if (!string.IsNullOrEmpty(msg))
            {
                HandleMessage(msg);
            }
            mainCamera.transform.rotation = Quaternion.Lerp(mainCamera.transform.rotation, Quaternion.Euler(data.rotation), Time.deltaTime * 2 / sendInterval);
            break;

        case State.fake:
            mainCamera.transform.rotation = Quaternion.Lerp(mainCamera.transform.rotation, Quaternion.Euler(data.rotation), Time.deltaTime * 2 / sendInterval);
            break;
        }
    }
示例#2
0
    public void Setup()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        manager.EnableBluetooth(() => { background.SetActive(true); roleSelection.SetActive(true); });
#else
        DebugText.LogImportant("Bluetooth only available on Android (faking observer)");
        manager.FakeConnect();
#endif
    }
 public void EnableBluetoothCallback(string result)
 {
     if (result == "true")
     {
         if (bluetoothEnabledCallback != null)
         {
             bluetoothEnabledCallback();
         }
     }
     else
     {
         DebugText.LogImportant("Bluetooth needed for observing");
     }
 }
示例#4
0
    public void ShowQuestion(aggrathon.vq360.data.Event question, string folderpath, Action <aggrathon.vq360.data.Option> selectionCallback)
    {
        if (question.title != "")
        {
            transform.GetChild(0).gameObject.SetActive(true);
            transform.GetChild(0).GetComponentInChildren <Text>().text = question.title;
        }
        else
        {
            transform.GetChild(0).gameObject.SetActive(false);
        }

        if (question.options.Length >= transform.childCount)
        {
            DebugText.LogImportant("Too many options in question '" + question.title + "' (max " + (transform.childCount - 1) + ")");
            aggrathon.vq360.data.Option[] opts = new aggrathon.vq360.data.Option[transform.childCount - 1];
            System.Array.Copy(question.options, opts, transform.childCount - 1);
            question.options = opts;
        }

        options = question.options.Length;
        for (int i = 0; i < options; i++)
        {
            aggrathon.vq360.data.Option option = question.options[permutation.IterateNext(options)];
            transform.GetChild(i + 1).GetComponent <VrButton>().Setup(
                option.text,
                option.image == "" ? "" : Path.Combine(folderpath, option.image),
                () => selectionCallback(option));
            transform.GetChild(i + 1).gameObject.SetActive(true);
        }
        for (int i = question.options.Length + 1; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }

        RecalculatePositions();
        gameObject.SetActive(true);
        permutation.Randomize();
    }
    public void SwitchScene(Scene scene)
    {
        uiLayer.gameObject.SetActive(false);
        StopAllCoroutines();
        bool video = false;

        if (scene == null)
        {
            currentScene                  = new Scene();
            currentScene.background       = "#333";
            currentScene.events           = new aggrathon.vq360.data.Event[1];
            currentScene.events[0]        = new aggrathon.vq360.data.Event();
            currentScene.events[0].time   = 5f;
            currentScene.events[0].action = "exit";
        }
        else
        {
            currentScene = scene;
        }

        if (currentScene.background != "")
        {
            if (!File.Exists(Path.Combine(scenarioFolder, currentScene.background)))
            {
                Color c = Color.black;
                ColorUtility.TryParseHtmlString(currentScene.background, out c);
                colorLayer.SetColor(c, colorLayer.gameObject.activeSelf? sceneChangeSpeed * 2f : sceneChangeSpeed);

                if (videoLayer.gameObject.activeSelf)
                {
                    videoLayer.Hide(sceneChangeSpeed);
                }

                StartCoroutine(Utils.RunLater(() => {
                    if (photoLayer.gameObject.activeSelf)
                    {
                        photoLayer.gameObject.SetActive(false);
                    }
                    logger.SwitchScene(GetSceneName());
                }, sceneChangeSpeed * 0.5f));
            }
            else
            {
                string ext = Path.GetExtension(currentScene.background).ToLower();
                if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
                {
                    photoLayer.material.mainTexture = Utils.LoadImage(Path.Combine(scenarioFolder, currentScene.background));

                    colorLayer.Flash(sceneChangeSpeed);
                    StartCoroutine(Utils.RunLater(() => {
                        if (!photoLayer.gameObject.activeSelf)
                        {
                            photoLayer.gameObject.SetActive(true);
                        }
                        logger.SwitchScene(currentScene.name);
                    }, sceneChangeSpeed * 0.5f));
                    if (videoLayer.gameObject.activeSelf)
                    {
                        videoLayer.Hide(sceneChangeSpeed * 0.5f);
                    }
                }
                else if (ext == ".mp4")
                {
                    colorLayer.TurnOn(sceneChangeSpeed * 0.5f);
                    videoLayer.SetVideo(Path.Combine(scenarioFolder, currentScene.background), currentScene.ending, HandleAction, sceneChangeSpeed * 0.5f, () => {
                        colorLayer.TurnOff(sceneChangeSpeed * 0.5f);
                        logger.SwitchScene(currentScene.name);

                        for (int i = 0; i < currentScene.events.Length; i++)
                        {
                            StartCoroutine(HandleEvent(currentScene.events[i], 0));
                        }
                    });

                    video = true;
                    if (photoLayer.gameObject.activeSelf)
                    {
                        StartCoroutine(Utils.RunLater(() => photoLayer.gameObject.SetActive(false), sceneChangeSpeed * 0.5f));
                    }
                }
                else
                {
                    DebugText.LogImportant("Unsupported background file format in scene '" + currentScene.name + "'");
                    StartCoroutine(Utils.RunLater(() => logger.SwitchScene(currentScene.name), sceneChangeSpeed * 0.5f));
                    videoLayer.ClearAction();
                }
            }
        }
        else
        {
            StartCoroutine(Utils.RunLater(() => logger.SwitchScene(currentScene.name), sceneChangeSpeed * 0.5f));
            videoLayer.ClearAction();
        }

        if (!video)
        {
            for (int i = 0; i < currentScene.events.Length; i++)
            {
                StartCoroutine(HandleEvent(currentScene.events[i], 0.5f * sceneChangeSpeed));
            }
        }
    }