コード例 #1
0
        public void EndSfxLoop(string id)
        {
            if (dataManager == null || channelManager == null)
            {
                return;
            }

            float     volume;
            AudioClip clip = dataManager.GetClip(id, out volume);

            if (clip == null)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendFormat("[AudioProducer] Audio Clip \"{0}\" is not found in the database. (maybe you forgot to include?) ", id);

                DebugWrapper.LogError(sb.ToString());
                return;
            }

            int returnCode = channelManager.StopSfxLoop(clip);

            if (returnCode > -1)
            {
                return;
            }

            if (isDebug)
            {
                DebugWrapper.LogWarning("[AudioSystem] Cannot Stop Loop as it is inactive. Audio Clip Name:" + clip.name);
            }
        }
コード例 #2
0
        // these methods have same logical issues and are old. Pending refactoring
        public void PlaySfxDelayed(float delay, AudioClip clip, float volume, Action onComplete = null)
        {
            if (delay <= 0)
            {
                PlaySfx(clip, volume, onComplete);
                return;
            }

            if (clip == null)
            {
                DebugWrapper.LogWarning("[AudioSystem] Play Sfx - Request parameters clip is null");
                return;
            }

            int         chanNr;
            AudioSource channel = GetFreeChannel(false, out chanNr);

            if (channel == null)
            {
                return;
            }

            onCompleteRegistry[chanNr] = onComplete;

            onDelayedCompleteTimes[chanNr] = ( float )AudioSettings.dspTime + delay + clip.length;

            channel.volume = sfxVolume * volume;
            inherentSfxClipVolumes[chanNr] = volume;
            channel.clip = clip;
            channel.loop = false;
            channel.PlayDelayed(delay);
        }
コード例 #3
0
        /// <summary>
        /// Get object from pool by prefab name. If pool doesn't have enough needed objects, it will be added </summary>
        /// <param name="prefabName"> Type of element to get. Type is matching with prefab's path in resources </param>
        /// <param name="position">Desired position </param>
        /// <param name="rotation">Desired orientation </param>
        /// <param name="timeBeforeDestroy"> Desired life time </param>
        /// <returns> GameObject of requested object from pool </returns>
        public static GameObject GetObjectFromPool(string prefabName, Vector3 position, Quaternion rotation,
                                                   double timeBeforeDestroy = -1.0f)
        {
            if (!_pool.ContainsKey(prefabName))
            {
                DebugWrapper.LogWarning($"PrefabName was not present in dictionary: {prefabName} ");
                AddItemToSleepingPool(prefabName);
            }

            if (_pool[prefabName].sleepingGameObjects.Count > 0)
            {
                return(GetItemFromPoolAndSetTransform());
            }

            AddItemToSleepingPool(prefabName);
            return(GetItemFromPoolAndSetTransform());

            GameObject GetItemFromPoolAndSetTransform()
            {
                var go = GetItemFromSleepingPool(prefabName, timeBeforeDestroy).gameObject;

                go.transform.position = position;
                go.transform.rotation = rotation;
                go.transform.parent   = null;
                return(go);
            }
        }
コード例 #4
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            isAutoMode = !isAutoMode;
            if (isAutoMode)
            {
                DebugWrapper.Log("Auto Mode On");
            }
            else
            {
                DebugWrapper.Log("Auto Mode Off");
            }
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            isPause = !isPause;
            if (isPause)
            {
                Time.timeScale = 0f;
                DebugWrapper.Log("Game Pause");
            }
            else
            {
                Time.timeScale = 1f;
                DebugWrapper.Log("Game Resume");
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            DebugWrapper.LogWarning("ESC 키를 통해 실행을 정지했습니다.");
            EditorApplication.isPlaying = false;
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            SceneManager.LoadSceneAsync((int)eSceneName.SCENE_RESULT);
        }
    }
コード例 #5
0
        /// <summary>
        /// Creates new element in queue and moves it into sleeping objects queue of given type.
        /// </summary>
        /// <param name="prefabName"> Type of element that needs to be created and put to sleep. Type is matching with prefab's path in resources
        /// </param>
        private static void AddItemToSleepingPool(string prefabName)
        {
            var goForAdd = Resources.Load <GameObject>(prefabName);

            if (goForAdd == null)
            {
                DebugWrapper.LogWarning($"[GameObjectPool::AddItemToSleepingPool] Object with name {prefabName} is null ");
            }

            var go = Instantiate(goForAdd, _container);

            go.name = prefabName;
            go.SetActive(false);

            if (!_pool.ContainsKey(prefabName))
            {
                _pool.Add(prefabName, new PoolablePrefab());
            }

            _pool[prefabName].sleepingGameObjects.Enqueue(new QueueItem(go));
        }
コード例 #6
0
        public void LoadClipsLoadLevel(int audioLevel)
        {
            if (liveClipData == null)
            {
                liveClipData = new Dictionary <string, AudioClipData>();
            }

            List <AudioClipData> loadQueue = new List <AudioClipData>();

            if (liveClipData != null)
            {
                foreach (KeyValuePair <string, AudioClipData> kvp in liveClipData)
                {
                    if (kvp.Value.loadLevel == 0 || kvp.Value.loadLevel == audioLevel)
                    {
                        kvp.Value.id = kvp.Key;
                        loadQueue.Add(kvp.Value);
                    }
                }
            }

            if (loadQueue.Count > 0 && audioLevel == 0)
            {
                DebugWrapper.LogWarning("[AudioDataManager] You are loading LoadingLevel(0) AudioClips more then once. Check your design!\nInterrupted load process...");
                return;
            }

            Dictionary <string, AudioEntry> loadLevel = registry.GetLoadLevel(audioLevel);

            foreach (KeyValuePair <string, AudioEntry> kvp in loadLevel)
            {
                AudioClipData audioClipData = new AudioClipData(kvp.Value);
                audioClipData.id = kvp.Key;

                loadQueue.Add(audioClipData);
            }

            LoadResources(loadQueue);
        }
コード例 #7
0
        public int StopSfxLoop(AudioClip clip)
        {
            if (clip == null)
            {
                DebugWrapper.LogWarning("[AudioSystem] StopLoop - Request parameters clip is null");
                return(-2);
            }

            AudioSource sfxChannel = GetFirstPlaying(clip);

            if (sfxChannel == null)
            {
                DebugWrapper.LogWarning("[AudioSystem] Cannot Stop Loop as it is inactive. Audio Clip Name:" + clip.name);
                return(-1);
            }

            sfxChannel.Stop();
            sfxChannel.clip = null;
            sfxChannel.loop = false;

            return(0);
        }
コード例 #8
0
        public void PlaySfxLoop(AudioClip clip, float inherentVolume)
        {
            if (clip == null)
            {
                DebugWrapper.LogWarning("[AudioSystem] PlayLoop - Request parameters clip is null");
                return;
            }

            int         chanNr;
            AudioSource channel = GetFreeChannel(false, out chanNr);

            if (channel == null)
            {
                return;
            }

            channel.volume = sfxVolume * inherentVolume;
            inherentSfxClipVolumes[chanNr] = inherentVolume;
            channel.clip = clip;
            channel.loop = true;
            channel.Play();
        }
コード例 #9
0
        /// <summary>
        /// Returns inactive element from sleeping objects queue, moves it to active objects queue and sets time to return to sleep
        /// </summary>
        /// <param name="prefabName"> Type of element that needs to be waken up and returned. Type is matching with prefab's path in resources
        /// </param>
        /// <param name="timeBeforeDestroy">
        /// </param>
        /// <returns> Returns inactive element from sleeping objects queue</returns>
        private static QueueItem GetItemFromSleepingPool(string prefabName, double timeBeforeDestroy)
        {
            var tQueueItem = _pool[prefabName].sleepingGameObjects.Dequeue();

            if (tQueueItem == null)
            {
                DebugWrapper.LogWarning($"[GameObjectPool::GetItemFromSleepingPool] tQueueItem invalid {prefabName}");
            }

            if (tQueueItem != null && tQueueItem.gameObject == null)
            {
                DebugWrapper.LogWarning(
                    $"[GameObjectPool::GetItemFromSleepingPool] tQueueItem GameObject invalid {prefabName}");
            }


            long timeToLive = -1;

            if (timeBeforeDestroy > 0.0f)
            {
                timeToLive = DateTime.Now.AddSeconds(timeBeforeDestroy).ToUnixTime();
            }
            else if (_pool[prefabName].timeToLive != 0.0d)
            {
                timeToLive = DateTime.Now.AddSeconds(_pool[prefabName].timeToLive).ToUnixTime();
            }

            if (timeToLive > 0.0f)
            {
                tQueueItem.destroyTime = timeToLive;
                _pool[prefabName].activeGameObjects.Enqueue(tQueueItem);
            }

            tQueueItem?.gameObject.SetActive(true);
            return(tQueueItem);
        }
コード例 #10
0
        public void PlaySfx(AudioClip clip, float volume, Action onComplete = null)
        {
            if (clip == null)
            {
                DebugWrapper.LogWarning("[AudioSystem] Play Sfx - Request parameters clip is null");
                return;
            }

            int         chanNr;
            AudioSource channel = GetFreeChannel(false, out chanNr);

            if (channel == null)
            {
                return;
            }

            onCompleteRegistry[chanNr] = onComplete;

            channel.volume = sfxVolume * volume;
            inherentSfxClipVolumes[chanNr] = volume;
            channel.clip = clip;
            channel.loop = false;
            channel.Play();
        }
コード例 #11
0
 protected BMSObject()
 {
     DebugWrapper.LogWarning($"{this.GetType()} Default Constructor is not available.");
 }
コード例 #12
0
    // Select Scene에서 필요한 정보들만 미리 파싱
    public void RecursiveFileFind(DirectoryInfo bmsDirectory, ref List <MusicInfo> musicInfoList)
    {
        string[] files = Directory.EnumerateFiles(bmsDirectory.FullName, "*.*", SearchOption.AllDirectories)
                         .Where(file => GlobalDefine.AVAILABLE_BMS_EXTENSIONS.Any(available => file.EndsWith(available, StringComparison.OrdinalIgnoreCase)))
                         .ToArray();

        if (files.Length == 0)
        {
            DebugWrapper.LogWarning("BMS File not exist.");
            return;
        }

        MusicInfo sendMusicInfo = new MusicInfo(bmsDirectory.Name);

        for (int fileIndex = 0; fileIndex < files.Length; ++fileIndex)
        {
            string[] textLine = File.ReadAllLines(files[fileIndex], System.Text.Encoding.Default);
            if (textLine.Length > 0)
            {
                BMSMusicInfo musicInfo = new BMSMusicInfo();

                musicInfo.bmsFilePath.bmsPath       = files[fileIndex];
                musicInfo.bmsFilePath.bmsParentPath = Path.GetDirectoryName(files[fileIndex]).ToString();

                char[]   separator = { ' ', ':' };
                string[] splitText;

                for (int lineIndex = 0; lineIndex < textLine.Length; ++lineIndex)
                {
                    textLine[lineIndex] = textLine[lineIndex].Trim();

                    if (string.IsNullOrEmpty(textLine[lineIndex]) || // 빈 라인에 대한 처리
                        !textLine[lineIndex].StartsWith("#"))        // '#'으로 시작하는 라인만 유효(나머지는 보통 주석)
                    {
                        continue;
                    }

                    splitText = textLine[lineIndex].Split(separator);
                    if (splitText.Length <= 1)
                    {
                        continue;
                    }

                    // GENRE
                    if (splitText[0].Equals("#GENRE"))
                    {
                        for (int i = 1; i < splitText.Length; ++i)
                        {
                            musicInfo.genre += splitText[i] + " ";
                        }
                    }
                    // TITLE
                    if (splitText[0].Equals("#TITLE"))
                    {
                        musicInfo.titleName = musicInfo.subTitleName = string.Empty;
                        int index = 1;
                        //do
                        //{
                        //    musicInfo.titleName += splitText[index];
                        //    index++;
                        //} while (!splitText[index].StartsWith("["));

                        for (int i = index; i < splitText.Length; ++i)
                        {
                            musicInfo.subTitleName += splitText[i];
                        }
                        musicInfo.subTitleName = musicInfo.subTitleName.Trim('[', ']');
                    }
                    // ARTIST
                    else if (splitText[0].Equals("#ARTIST"))
                    {
                        musicInfo.artistName = splitText[1];
                    }
                    else if (splitText[0].Equals("#BPM"))
                    {
                        if (int.TryParse(splitText[1], out musicInfo.bpm))
                        {
                        }
                    }
                    // PLAY LEVEL
                    else if (splitText[0].Equals("#PLAYLEVEL"))
                    {
                        if (int.TryParse(splitText[1], out musicInfo.playLevel))
                        {
                        }
                    }
                    // STAGE FILE
                    else if (splitText[0].Equals("#STAGEFILE"))
                    {
                        musicInfo.bmsFilePath.stageFileName = splitText[1];
                    }

                    if (char.IsNumber(splitText[0][1]))
                    {
                        break;                                 // FileSystem에선 Data Field까지 전부 파싱할 필요 없음. Data Field 도달 시 파싱 종료.
                    }
                }
                sendMusicInfo.BmsFileList.Add(musicInfo);
            }
        }
        musicInfoList.Add(sendMusicInfo);
    }