示例#1
0
    public static void CreateSoundEffect(string url, Vector3 playPos)
    {
        string uid = Torch.CreateObject(null);

        Torch.SetPrefab(uid, "Prefabs/SoundEffect");
        GameObject audioPlayer = Torch.GetTransform(uid).gameObject;

        Torch.SetTransformPosition(uid, playPos);
        AudioClip clip = (AudioClip)Resources.Load(url, typeof(AudioClip));

        if (clip == null)
        {
            return;
        }

        AudioSource source = (AudioSource)audioPlayer.GetComponent("AudioSource");

        if (source == null)
        {
            source = (AudioSource)audioPlayer.AddComponent <AudioSource>();
        }
        source.clip   = clip;
        source.loop   = false;
        source.volume = 1.0f;
        source.Play();
        source.DOFade(0f, 1f).OnComplete(() => Torch.DestroyObject(uid));
    }
示例#2
0
    private static void RemoveListener()
    {
        string    audioSourceUid = soundSourceUID;
        Transform audTrans       = Torch.GetTransform(audioSourceUid);

        audTrans.GetComponent <AudioListener>().enabled = false;
    }
示例#3
0
    private static AudioSource GetAudioSource()
    {
        string      audioSourceUid = soundSourceUID;
        Transform   audioTrans     = Torch.GetTransform(audioSourceUid);
        AudioSource audioSource    = audioTrans.GetComponent <AudioSource>() as AudioSource;

        return(audioSource);
    }
示例#4
0
    // Update is called once per frame
    public static void Update(string uid)
    {
        if (Input.GetKey("d"))
        {
            Torch.DestroyObject(uid);
        }

        Transform thisTransform = Torch.GetTransform(uid);

        thisTransform.Rotate(new Vector3(Random.value * 10, Random.value * 10, Random.value * 10));
    }
示例#5
0
    public static AudioSource LoadSound(string uid, string url, bool loop)
    {
        AudioClip  clip        = (AudioClip)Resources.Load(url, typeof(AudioClip));
        GameObject audioPlayer = Torch.GetTransform(uid).gameObject;

        if (clip == null)
        {
            return(null);
        }

        AudioSource source = (AudioSource)audioPlayer.GetComponent("AudioSource");

        if (source == null)
        {
            source = (AudioSource)audioPlayer.AddComponent <AudioSource>();
        }
        source.clip = clip;
        source.loop = loop;
        return(source);
    }