예제 #1
0
    void Start()
    {
        // set the listener transform to the audio listener
        AudioListener tmp_listener = (AudioListener)FindObjectOfType(typeof(AudioListener));

        listener = tmp_listener.transform;

        // scale the overall height (distance between objects) using the scalar (the size of the objects)
        height = height * scalar / 0.05f;

        texts = new GameObject[num_texts];
        string poem_text = poem_text_file.text;

        string[] poem_array = poem_text.Split('*');
        num_poems    = poem_array.Length;
        poem_heights = new float[num_texts];
        float poem_heights_total = 0;

        for (int i = 0; i < num_texts; i++)
        {
            texts[i] = Instantiate(textfab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            texts[i].transform.localRotation = Quaternion.Euler(90, 180, 0);
            texts[i].transform.parent        = GameObject.Find("ImageTarget").transform;
            texts[i].transform.localScale    = new Vector3(scalar, scalar, scalar);
            ScriptExample1 scr = texts[i].GetComponent <ScriptExample1>();

            texts[i].GetComponent <TextMeshPro>().SetText(poem_array[i % num_poems]);

            texts[i].GetComponent <TextMeshPro>().ForceMeshUpdate();

            float text_height = texts[i].GetComponent <TextMeshPro>().textBounds.size.y;
            poem_heights_total += text_height;
            poem_heights[i]     = text_height;

            // set audio clip
            AudioSource audio_src       = texts[i].GetComponent <AudioSource>();
            string      audio_clip_name = "Climate_loop_" + i;
            AudioClip   audio_clip      = (AudioClip)Resources.Load(audio_clip_name);
            audio_src.clip = audio_clip;
            //audio_src.pitch = (i/(float)num_texts) + 1;
            audio_src.loop = true;
            audio_src.Play();
            //Debug.Log("audio clip for " + i + " is " + audio_src.clip.);
        }

        float poem_height_total_normalized = 0;
        float poem_height_total_previous   = 0;

        for (int i = 0; i < num_texts; i++)
        {
            poem_height_total_previous    = poem_heights[i] / poem_heights_total;
            poem_heights[i]               = poem_height_total_normalized;
            poem_height_total_normalized += poem_height_total_previous;
        }
    }
예제 #2
0
    void Start()
    {
        texts = new GameObject[num_texts];
        string blue_text = blue_text_file.text;

        for (int i = 0; i < num_texts; i++)
        {
            texts[i] = Instantiate(textfab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            texts[i].transform.localRotation = Quaternion.Euler(180, 180, 0);
            texts[i].transform.parent        = GameObject.Find("ImageTarget").transform;
            texts[i].transform.localScale    = new Vector3(scalar, scalar, scalar);
            ScriptExample1 scr = texts[i].GetComponent <ScriptExample1>();

            texts[i].GetComponent <TextMeshPro>().SetText(blue_text);
        }
    }