We're working on animations... At last GhoulMage is animating my models!
-GhoulMage:
Huh huh. I've returned and I animate xD, I like this.
-Mio animation (Unity)
1 2 | var myInfiniteMusic = new InfiniteBackgroundMusic(); myInfiniteMusic.ChangeTrack(myAudioSource, myAudioClip, myLoopPoint); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | using UnityEngine; using System.Collections; public class InfiniteBackgroundMusic : MonoBehaviour { [Header("To get/set audio position, use Time and SampleTime")] public float MusicLoopPoint; public AudioClip audioClip; public AudioSource audioSource; public float Time { get { long p = position; p /= entire.Length; return p * audioClip.length; } set { double m = value / audioClip.length; position = (long)(m * entire.Length); } } public float Duration { get { return audioClip.length; } } public long SampleTime { get { return position; } set { if(value >= entire.Length) { Debug.LogError("Value is larger than audioClip.samples"); } if(value < 0) { Debug.LogError("Value is lesser than 0"); } position = value; } } public int SampleDuration { get { return entire.Length; } } float[] entire; long position; int sampleLoopPoint; string audioName; int channels; int start; void Start () { double mul = MusicLoopPoint / audioClip.length; sampleLoopPoint = (int)(mul * audioClip.samples); channels = audioClip.channels; audioName = audioClip.name; entire = new float[audioClip.samples * channels]; audioClip.GetData(entire, 0); audioClip = AudioClip.Create(audioName + "_Loop", audioClip.samples, channels, audioClip.frequency, true, OnAudioRead, OnAudioSetPos); audioSource.loop = true; audioSource.clip = audioClip; position = 0; audioSource.Play(); position = 0; } void OnAudioRead(float[] data) { if(start < 64) { start++; position = 0; return; } int count = 0; while(count < data.Length) { data[count] = entire[position]; position++; count++; if(position >= entire.Length) { position = sampleLoopPoint*channels; } } } void OnAudioSetPos(int newPos) { } } |