private bool RegisterTrigger(DestroyTrigger trigger, GameObject bindTarget, TimerJob timerJob)
        {
            if (bindTarget == null)
            {
                Debugs.LogError("bindTarget이 이미 null입니다.");
                return(false);
            }

            if (timerJob == null)
            {
                Debugs.LogError("timerJob이 이미 null입니다.");
                return(false);
            }

            if (triggerMap.ContainsKey(trigger.Key))
            {
                triggerMap[trigger.Key].Add(new WeakReference(timerJob));
            }
            else
            {
                triggerList.AddLast(trigger);
                triggerMap.SafetyAdd(trigger.Key, new List <WeakReference>());
                triggerMap[trigger.Key].Add(new WeakReference(timerJob));
            }

            return(true);
        }
        /// <summary>
        /// TimerJob을 Global Dispatch Timer에 등록합니다.
        /// GameObject인 bindTarget이 파괴되면 작업도 취소됩니다.
        /// 이 메서드는 동작 시간의 유효성을 따로 검사해주지 않습니다.
        /// </summary>
        /// <param name="job">실행할 TimerJob 객체</param>
        /// <param name="bindTarget">라이프 사이클을 함께할 GameObject</param>
        public void PushTimerJob(TimerJob job, GameObject bindTarget)
        {
            if (job == null)
            {
                Debugs.LogError("Job이 null입니다.");
                return;
            }

            if (bindTarget == null)
            {
                Debugs.LogError("bindTarget이 null입니다.");
                return;
            }

            var destroyTrigger = bindTarget.GetComponent <DestroyTrigger>();

            if (destroyTrigger == null)
            {
                                #if __USE_TIMER_LOG
                Debugs.Log("Create New DestroyTrigger");
                                #endif
                destroyTrigger = bindTarget.AddComponent <DestroyTrigger>();
            }

                        #if __USE_TIMER_LOG
            Debugs.Log("Attatch DestroyTrigger to gameObject");
                        #endif

            if (RegisterTrigger(destroyTrigger, bindTarget, job))
            {
                timedJobQueue.Enqueue(job);
            }
        }
Exemplo n.º 3
0
    public void ProcessLoad(SoundPlayData Data)
    {
        /// 이미 로드 중인 데이터 클립 제거 추가
        ///
        /// 이미 로드중인 클립이 있는가? => 플레이 리스트에 추가
        ///

        /*
         * for (int i = 0; i < Loaders.size; i++)
         * {
         *  if (Loaders[i].m_strName == Data.m_strSoundFileName)
         *  {
         *     Loaders[i].AddPlayData(Data);
         *      return;
         *  }
         * }
         */
        AudioClip TargetClip = Resources.Load <AudioClip>(string.Concat(m_strLocalLoad, Data.m_strSoundFileName));

        if (TargetClip == null)
        {
            Debugs.LogError("[사운드로드] ProcessLoad 실패! 대상 클립(", Data.m_strSoundFileName, ")을 찾을 수 없습니다!");
        }
        else
        {
            m_Storage.AddAudioClip(TargetClip);
            Data.m_AudioClipGroup.PushAudioClip(TargetClip);
            Data.LoadComplete(TargetClip, 0.0f);
            Debugs.Log(string.Concat("[사운드로드] 완료! ", Data.m_LoadedAudioClip.name, " 소요 시간 [", 0.0f, "]"));
            Data.TryPlay();
        }
        return;
    }
        /// <summary>
        /// TimerJob을 Global Dispatch Timer에 등록합니다.
        /// 이 메서드는 동작 시간의 유효성을 따로 검사해주지 않습니다.
        /// </summary>
        /// <param name="job">실행할 TimerJob 객체</param>
        public void PushTimerJob(TimerJob job)
        {
            if (job == null)
            {
                Debugs.LogError("Job이 null입니다.");
                return;
            }

            timedJobQueue.Enqueue(job);
        }
Exemplo n.º 5
0
    public void PublishKey()
    {
        if (m_trPlace == null)
        {
            Debugs.LogError("[사운드-키발급] 발급의 대상이 되는 객체가 없습니다! 채널을 먼저 생성하십시오.");
            return;
        }

        m_strFinalKey = string.Concat(m_trPlace.GetInstanceID(), m_strKey);
    }
        public T Peek()
        {
            if (_size == 0)
            {
                Debugs.LogError("Heap이 비었다.");
                return(default(T));
            }

            return(_items[0].Value);
        }
Exemplo n.º 7
0
    public Transform GetAudioChannelRoot(E_AUDIO_CHANNEL_TYPE eChannelType)
    {
        if (!m_AudioChannelList.ContainsKey(eChannelType))
        {
            Debugs.LogError("[사운드] 대상 오디오 채널", eChannelType.ToString(), "이 없습니다!");
            return(null);
        }

        return(m_AudioChannelList[eChannelType].m_trTransform);
    }
Exemplo n.º 8
0
    //public void Play(int nSoundId, Transform trParent, eAudioGroupType eAudioGroup, bool bLocal = false, int nIndex = 0)
    //{
    //    SoundData Data = SoundDataManager.Instance.GetSoundDataByID(nSoundId);
    //    if (Data == null) return;

    //    Play(Data.name, trParent, eAudioGroup, Data.m_eChannelType, bLocal, nIndex);
    //}

    //public void Play(string strSoundName, Transform trParent, eAudioGroupType eAudioGroup, E_AUDIO_CHANNEL_TYPE eChannelType, bool bLocal = false, int nIndex = 0)
    //{
    //    if (m_AudioChannelList.ContainsKey(eChannelType))
    //    {
    //        AudioObject NewAudioObject = m_AudioChannelList[eChannelType].GetAudioObject();
    //        NewAudioObject.SetParent(trParent);
    //        NewAudioObject.transform.localPosition = Vector3.zero;
    //        NewAudioObject.SetAudioOptionType(eAudioOptionType.BGM);
    //        NewAudioObject.SetAudioGroup(eAudioGroup);

    //        LoadAsyncAddCachClipData(NewAudioObject.name, (clip, loadDelay) =>
    //        {
    //            publicSFXAudio.Play(clip);
    //            publicSFXAudio.OnStop = () => {
    //                ClipCachData data = GetCachClipData(clip.name);
    //                if (data == null)
    //                    return;
    //                RemoveClipCachData(data);
    //            };
    //        }, E_AUDIO_CLIP_GROUP.Stop, bLocal);

    //    }
    //}

    public void Pause(Transform trPlace, E_AUDIO_CHANNEL_TYPE eAudioChannel, string strKey)
    {
        if (!AvaliableAudioChannel(eAudioChannel))
        {
            if (g_bPrintLog)
            {
                Debugs.LogError("[사운드-일시정지] 일시정지 할 채널이 없거나 비활성화 중입니다!");
            }
            return;
        }
        m_AudioChannelList[eAudioChannel].Pause(string.Concat(trPlace.GetInstanceID(), strKey));
    }
Exemplo n.º 9
0
    /// <summary>
    /// 해당 채널의 해당 객체의 모든 오디오를 중지합니다.
    /// </summary>
    /// <param name="trPlace"></param>
    /// <param name="eAudioChannel"></param>

    public void StopAll(Transform trPlace, E_AUDIO_CHANNEL_TYPE eAudioChannel)
    {
        if (!AvaliableAudioChannel(eAudioChannel))
        {
            if (g_bPrintLog)
            {
                Debugs.LogError("[사운드-중지] 중지할 채널이 없거나 비활성화 중입니다!");
            }
            return;
        }
        m_AudioChannelList[eAudioChannel].StopAll(trPlace);
    }
Exemplo n.º 10
0
    /// <summary>
    /// 해당 채널의 해당 오디오를 중지합니다. (비용이 거의 없음)
    /// </summary>
    /// <param name="eAudioChannel"></param>
    /// <param name="strKey"></param>
    public void Stop(E_AUDIO_CHANNEL_TYPE eAudioChannel, string strKey)
    {
        if (!AvaliableAudioChannel(eAudioChannel))
        {
            if (g_bPrintLog)
            {
                Debugs.LogError("[사운드-중지] 중지할 채널이 없거나 비활성화 중입니다!");
            }
            return;
        }

        m_AudioChannelList[eAudioChannel].Stop(string.Concat(m_AudioChannelList[eAudioChannel].m_trTransform.GetInstanceID(), strKey));
    }
Exemplo n.º 11
0
    public virtual bool CanPlay(SoundPlayData Data)
    {
        if (Data.m_LoadedAudioClip == null)
        {
            Debugs.LogError("[사운드-재생] 클립이 null입니다!");
            return(false);
        }

        if (Data.m_trPlace == null)
        {
            Debugs.LogError("[사운드-재생] 재생할 장소가 null입니다!");
            return(false);
        }
        return(true);
    }
Exemplo n.º 12
0
    /// <summary>
    /// 오디오 오브젝트를 생성한다.
    /// </summary>
    /// <param name="groupType"></param>
    /// <param name="optionType"></param>
    /// <returns></returns>
    //public static AudioObject CreateAudioObject(eAudioOptionType optionType = eAudioOptionType.SE, eAudioGroupType groupType = eAudioGroupType.UI)
    //{
    //    return CreateAudioObject(Instance.gameObject.transform, optionType, groupType);
    //}

    //public static AudioObject CreateAudioObject(Transform parent, eAudioOptionType optionType = eAudioOptionType.SE, eAudioGroupType groupType = eAudioGroupType.UI)
    //{
    //    AudioObject NewAudioObject = Instantiate(Instance.AudioObjectPrefab);
    //    NewAudioObject.SetParent(parent);
    //    NewAudioObject.transform.localPosition = Vector3.zero;
    //    NewAudioObject.SetAudioChannel(optionType);
    //    NewAudioObject.SetAudioGroup(groupType);
    //    return NewAudioObject;
    //}


    #region Play (SoundPlayData모델)

    /// <summary>
    /// 최종 사운드 재생
    /// </summary>
    /// <param name="Data"></param>
    public void Play(SoundPlayData Data)
    {
        if (Data == null)
        {
            Debugs.LogError("[사운드-재생] 이 사운드 재생 데이터는 NULL입니다!");
            return;
        }

        if (!AvaliableAudioChannel(Data.m_eAudioChannel))
        {
            Debugs.LogError("[사운드-재생] 재생할 채널이 없거나 비활성화 중입니다!");
            return;
        }

        m_AudioChannelList[Data.m_eAudioChannel].Play(Data);
    }
Exemplo n.º 13
0
    public AudioObject DeactiveList_Dequeue()
    {
        if (m_AudioDeactiveObjectList.Count <= 0)
        {
            return(null);
        }

        AudioObject TargetAudio = m_AudioDeactiveObjectList[0];

        m_AudioDeactiveObjectList.RemoveAt(0);
        if (TargetAudio == null)
        {
            Debugs.LogError("[사운드-재생] 꺼내온 비활성화중인 오디오 객체가 NULL입니다! 이미 파괴되었을 수 있습니다.");
            return(null);
        }
        TargetAudio.gameObject.SetActive(true);
        IncreasePriority();
        return(TargetAudio);
    }
Exemplo n.º 14
0
 public virtual void ExceptionProcess(AudioObject NewAudioObject)
 {
     ///버그에 대한 예외처리 및 디버그 코드 작성
     if (NewAudioObject == null)
     {
         Debugs.LogError("[사운드-재생] 새로 가져온 오브젝트가 null입니다! 어딘가에서 객체 파괴시 그 객체 하위에서 재생중인 사운드를 돌려주지 않았을 수 있습니다! 일단 새로운 객체를 재생성합니다.");
         NewAudioObject = m_Channel.AddAudioObject();
         m_Channel.m_AudioDeactiveObjectList.Remove(NewAudioObject);
         NewAudioObject.gameObject.SetActive(true);
         for (int i = 0; i < m_Channel.m_AudioActiveObjectList.Count; i++)
         {
             if (m_Channel.m_AudioActiveObjectList[i] == null)
             {
                 Debugs.LogError("[사운드-재생] 현재 활성화된 객체중 이미 NULL이 되버린 객체를 발견했습니다! 인덱스:", i);
                 m_Channel.m_AudioActiveObjectList.Remove(m_Channel.m_AudioActiveObjectList[i]);
             }
         }
     }
 }
        private void LateUpdate()
        {
            if (isCalledDestroyed)
            {
                return;
            }

            if (!isRunning)
            {
                return;
            }

            CheckDestroyedGameObject();

            while (timedJobQueue.Count > 0)
            {
                var timedJob = timedJobQueue.Peek();

                if (CurrentTicks < timedJob.ExecutedTicks)
                {
                    break;
                }

                try
                {
                                        #if __USE_TIMER_LOG
                    Debugs.LogFormat("Execute Timer Job !!! - currentTicks {0}, job_excutedTicks {1}", CurrentTicks,
                                     timedJob.ExecutedTicks);
                                        #endif
                    timedJob.Execute();
                }
                catch (Exception ex)
                {
                    Debugs.LogError(string.Concat(ex.Message, ex.StackTrace));
                }
                finally
                {
                    // 어쩄든 큐에서 뺴자
                    timedJobQueue.Dequeue();
                }
            }
        }
        /// <summary>
        /// Global Queue에 delay초 뒤에 실행되도록 작업을 예약합니다.
        /// GameObject인 bindTarget이 파괴되면 작업도 취소됩니다.
        /// </summary>
        /// <param name="timerTask">실행할 작업</param>
        /// <param name="delay">실행까지 남은 초(float)</param>
        /// <param name="bindTarget">라이프 사이클을 함께할 GameObject</param>
        /// <returns>생성된 TimerJob의 할당 해제 가능한 IDisposable 객체를 반환합니다.</returns>
        public IDisposable PushTimerJob(Action timerTask, float delay, GameObject bindTarget)
        {
            if (!ValidateTime(delay))
            {
                return(null);
            }

            if ((object)bindTarget == null)
            {
                Debugs.LogError("bindTarget이 null입니다.");
                return(null);
            }

            var destroyTrigger = bindTarget.GetComponent <DestroyTrigger>();

            if (destroyTrigger == null)
            {
                                #if __USE_TIMER_LOG
                Debugs.Log("Create New DestroyTrigger");
                                #endif
                destroyTrigger = bindTarget.AddComponent <DestroyTrigger>();
            }

                        #if __USE_TIMER_LOG
            Debugs.Log("Attatch DestroyTrigger to gameObject");
                        #endif

            var timerJob = new TimerJob(timerTask, CurrentTicks + delay);

            if (!RegisterTrigger(destroyTrigger, bindTarget, timerJob))
            {
                return(null);
            }

            timedJobQueue.Enqueue(timerJob);

            return(timerJob);
        }
        private static void Init()
        {
            if (!isInited)
            {
                if (!Application.isPlaying)
                {
                    return;
                }

                GlobalDispatchTimer mainDispatcher = null;

                try
                {
                    mainDispatcher = GameObject.FindObjectOfType <GlobalDispatchTimer>();
                }
                catch (Exception e)
                {
                    Debugs.LogError("Failed to create DispatchTimer Instance.");
                }

                // 메인 디스패처가 없으면 만들어 준다.
                if (mainDispatcher == null)
                {
                    new GameObject("GlobalDispatchTimer").AddComponent <GlobalDispatchTimer>();
                }
                else
                {
                    // 있어도 강제로 Awake를 실행 시켜서 초기화 되도록 해준다.
                    instance.Awake();
                }
            }
            else
            {
                Debugs.Log("DispatchTimer가 이미 초기화 되었습니다.");
            }
        }