Esempio n. 1
0
        void CreateTarget(string targetName, out EasyImageTargetBehaviour targetBehaviour)
        {
            GameObject Target = new GameObject(targetName);

            Target.transform.localPosition = Vector3.zero;
            targetBehaviour = Target.AddComponent <EasyImageTargetBehaviour>();
        }
    private IEnumerator Start()
    {
        /*WWW www = new WWW("http://www.myenocta.com/download/content/AR_demo/modelsAR.txt");
         * //WWW www = new WWW("file:///C:/Users/eda.mutlu/Desktop/modelsAR.json");
         * yield return www;
         * settings = JsonUtility.FromJson<Settings>(www.text);*/

        // when the QR code scanned is not a json file
        while (settings == null)
        {
            Debug.Log("not a json file");
            yield return(new WaitForSeconds(1.0f)); // wait for a second
        }
        // when the QR code scanned is a json file but not in the form we wish to have
        while (settings.total_models == 0)
        {
            Debug.Log("wrong json file");
            yield return(new WaitForSeconds(1.0f)); // wait for a second
        }
        // just after this point we know that we've scanned a json file in the form we wish to have

        Destroy(barcode_scanner); // disable QR scanning

        // some settings
        API_KEY               = settings.api_key;
        LANG                  = settings.lang;
        model_display_time    = settings.model_display_time;
        question_display_time = settings.question_countdown_time;

        // inform user about QR scanned was the correct one
        qr_code_canvas.SetActive(true);
        yield return(new WaitForSeconds(2.0f));

        qr_code_canvas.SetActive(false);

        Debug.Log("start");
        Debug.Log(settings.total_models);

        // create an deactive game object (ImageTarget-Image prefab) for each model given
        int i = 0;

        foreach (Model model in settings.models)
        {
            GameObject target_image = Resources.Load("ImageTarget-Image") as GameObject;
            target_image = Instantiate(target_image, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            Debug.Log(target_image);

            // set the references of the gameobject created
            EasyImageTargetBehaviour EITScript = target_image.GetComponent <EasyImageTargetBehaviour>();
            EITScript.Path = model.image_target + ".jpg";
            EITScript.Name = model.image_target;
            EITScript.Bind(image_tracker);
            EITScript.controller = controller;

            // keep a reference of the created object to access later
            target_images.Add(target_image);
            Debug.Log(target_images.Count);

            // make the model a child object of the ImageTarget-Image created
            GameObject newModel = Resources.Load(model.name) as GameObject;
            newModel = Instantiate(newModel, target_images[i].transform);
            newModel.transform.SetParent(target_images[i].transform);

            // save the questions of the given model
            foreach (Question question in model.questions)
            {
                ImageTarget image_target_script = target_images[i].GetComponent <ImageTarget>();
                image_target_script.questions.Add(question);
            }
            i++;
        }
        // find if there any activated model in the scene
        GameObject current_target = null;

        for (i = 0; i < target_images.Count; i++)
        {
            // ...if not wait
            while (!model_alive)
            {
                yield return(new WaitForSeconds(1.0f));
            }
            // after finding it, display it for a while (given as model_display_time)
            Debug.Log("Model found");
            int count;
            timer.gameObject.SetActive(true);
            for (count = model_display_time; count > 0; count--)
            {
                timer_text.text = "Kalan Süre: " + count;
                yield return(new WaitForSeconds(1.0f)); // Wait 1 sec
            }
            timer.gameObject.SetActive(false);
            foreach (var target_image in target_images)
            {
                if (target_image)
                {
                    if (target_image.activeInHierarchy)
                    {
                        current_target = target_image;
                        Destroy(target_image);
                        break;
                    }
                }
            }
            // display the questions of the current model
            yield return(StartCoroutine(UpdateQuestion(current_target)));

            model_alive = false;
        }
    }