Beispiel #1
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);
            }
        }
Beispiel #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);
        }
        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);
            }
        }
Beispiel #4
0
 protected override void InitializeOnAwake()
 {
     if (appInfo == null)
     {
         DebugWrapper.LogError("npE: AppInfo not provided! Drag'n Drop App/AppInfo.asset in the inspector or create a new info asset.");
         DebugWrapper.Break();
     }
 }
Beispiel #5
0
    // Start is called before the first frame update
    void Start()
    {
        DebugWrapper.Assert(blinkTarget != null, $"'{this.gameObject}'는 blinkTarget이 없습니다.");

        isProcessing = true;
        interval     = 1f;
        StartCoroutine(BlinkProcess(interval));
    }
Beispiel #6
0
 public static float Extended(float start, float end, float percent, Func <float, float> easing)
 {
     if (easing == null)
     {
         DebugWrapper.Log("easing function cannot ve null");
         return(start);
     }
     return(Classic(start, end, easing(percent)));
 }
Beispiel #7
0
        public void Should_LogNull_When_ListContainsOneObject()
        {
            LogAssert.Expect(LogType.Log, "null");

            DebugWrapper.LogCollection(new List <object>()
            {
                new Object()
            });
        }
Beispiel #8
0
    void Start()
    {
        debug       = gameObject.AddComponent <DebugWrapper>();
        debug.world = this;

        terrain = new TerrainGenerator();

        //	Create initial chunks
        //	Must always be multiple of ChunkSize
        LoadChunks(VoxelOwner(player.transform.position), viewDistance);
    }
Beispiel #9
0
    void Awake()
    {
        bmsHeader = new BMSHeader();
        DebugWrapper.Assert(bmsHeader != null, "BMS Header가 설정되지 않았습니다.");

        isLoadInfo = SingletonData.Instance.selectedMusicInfo != null ? true : false;

        testPath = Path.Combine(Application.dataPath, GlobalDefine.RESOURCE_BASE_PATH, @"happiness\happiness_5b.bms");
        bmsHeader.BmsFilePath   = isLoadInfo ? SingletonData.Instance.selectedMusicInfo.bmsFilePath.bmsPath : testPath;
        bmsHeader.BmsParentPath = isLoadInfo ? SingletonData.Instance.selectedMusicInfo.bmsFilePath.bmsParentPath : Path.GetDirectoryName(testPath);
    }
Beispiel #10
0
    private void Awake()
    {
        DebugWrapper.Assert(judgeTextSpriteArr != null, this.GetType() + " : Where is Judge Text Sprite");

        this.Initialize();

        numberling.numberlingPrevAction = () =>
        {
            numberling.ParentPanel.transform.localScale = Vector2.zero;
            numberling.ParentPanel.transform.DOScale(Vector2.one, 0.1f).SetEase(Ease.OutQuint);
        };
    }
        private BaseWindow GetWindowByType(Type windowType)
        {
            if (!_typeToWindow.ContainsKey(windowType))
            {
                DebugWrapper.LogError($"This window type is not registered: {windowType}");
                return(null);
            }

            var window = _typeToWindow[windowType];

            return(window);
        }
Beispiel #12
0
 /// <summary>
 /// Performs an action if this reference isn't null or prints error in DebugWrapper if it's null
 /// </summary>
 /// <param name="reference">this object reference</param>
 /// <param name="action">Action to perform if reference isn't null</param>
 public static void DoActionWithCheckReference(this Object reference, Action action)
 {
     if (reference != null)
     {
         action.Invoke();
     }
     else
     {
         DebugWrapper.LogError($"{nameof(reference)} is null! Assign the reference!",
                               DebugColors.Red);
     }
 }
        private bool RegisterWindowType(BaseWindow window)
        {
            var windowType = window.GetType();

            if (_typeToWindow.ContainsKey(windowType))
            {
                DebugWrapper.LogError($"This window type is already registered: {windowType}");
                return(false);
            }

            _typeToWindow.Add(windowType, window);
            return(true);
        }
    public void BeatSetting(int bpm)
    {
        // 60BPM에서 초당 마디 = 0.25마디(4개의 노트)
        DebugWrapper.Assert(bpm != 0, "BPM 값이 설정되지 않았습니다.");

        BarPerSec  = bpm / (60.0f * GlobalDefine.STD_BEAT);
        SecPerBar  = 1 / BarPerSec;
        BeatPerSec = GlobalDefine.BEAT_PER_BAR * BarPerSec;
        SecPerBeat = 1 / BeatPerSec;

        PerfectJudgeTime = SecPerBeat * 0.5f;
        GreatJudgeTime   = SecPerBeat * 1.5f;
        GoodJudgeTime    = SecPerBeat * 2.5f;
    }
Beispiel #15
0
    public static T Load()
    {
        if (File.Exists(Path.Combine(Application.dataPath, $"{typeof(T)}.save")))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Path.Combine(Application.dataPath, $"{typeof(T)}.save"), FileMode.Open);

            T data = bf.Deserialize(stream) as T;
            stream.Close();
            return(data);
        }

        DebugWrapper.LogError($"'{typeof(T)}.save' File Not Exist.");
        return(null);
    }
Beispiel #16
0
    public void ParseBMS(string filePath)
    {
        this.Awake();

        // 이전 씬(보통 음악선택 씬)에서 미리 받아둔 음악정보 데이터가 있다면, 음악 정보에 관련된 파싱은 생략하고 해당 데이터를 사용.
        if (isLoadInfo)
        {
            bmsHeader.info = SingletonData.Instance.selectedMusicInfo;
            DebugWrapper.Log("이전 Scene에서 받아온 음악 정보를 사용합니다.");
        }

        string[] textLine = File.ReadAllLines(bmsHeader.BmsFilePath, System.Text.Encoding.Default);
        if (textLine.Length > 0)
        {
            char[]   separator = { ' ', ':' };
            string[] splitText;

            if (!isLoadInfo)
            {
                DebugWrapper.Log("이전 Scene에서 받아온 음악 정보가 없기 때문에 별도의 Parsing을 진행합니다.");
            }

            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;
                }

                if (!isLoadInfo)
                {
                    Parsing_ShowHeader(ref splitText);
                }
                Parsing_GameHeader(ref splitText);
                Parsing_GameData(ref splitText);
            }
        }
    }
Beispiel #17
0
        public AudioClip GetClip(string id, out float inherentVolume)
        {
            inherentVolume = 1.0f;

            AudioClipData outClipData;

            if (liveClipData.TryGetValue(id, out outClipData))
            {
                inherentVolume = outClipData.inherentVolume;

                return(outClipData.clip);
            }
            else
            {
                DebugWrapper.LogError("[AudioSystem] Sound id:" + id + " is invalid or you are trying to play it in a wrong load level");
            }

            return(null);
        }
        public void PlaySfx(string id, float volume = 1.0f, float delay = 0.0f)
        {
            if (dataManager == null || channelManager == null)
            {
                return;
            }

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

            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;
            }
            channelManager.PlaySfxDelayed(delay, clip, volume);
        }
    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);
        }
    }
        public BaseWindow ShowWindow(Type windowType)
        {
            var window = GetWindowByType(windowType);

            if (window.IsShown)
            {
                DebugWrapper.LogError(
                    $"This window is already shown: {windowType}\n{StackTraceUtility.ExtractStackTrace()}");
            }

            _shownWindows.Add(window);


            OnSomeWindowVisible?.Invoke(window);

            window.OnShow();

            UpdateZOrder(window);

            return(window);
        }
Beispiel #21
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));
        }
        public void StartSfxLoop(string obj)
        {
            if (dataManager == null || channelManager == null)
            {
                return;
            }

            float     volume;
            AudioClip clip = dataManager.GetClip(obj, 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?) ", obj);

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

            channelManager.PlaySfxLoop(clip, volume);
        }
Beispiel #23
0
        private AudioSource GetFreeChannel(bool isBgm, out int chanNr)
        {
            AudioSource[] channelList = isBgm ? bgmChannels : sfxChannels;

            for (int chanIndex = channelList.Length - 1; chanIndex > -1; chanIndex--)
            {
                if (!channelList[chanIndex].gameObject.activeSelf)
                {
                    channelList[chanIndex].volume = 1.0f;
                    channelList[chanIndex].gameObject.SetActive(true);
                    chanNr = chanIndex;
                    return(channelList[chanIndex]);
                }
            }

            string channelType = isBgm ? "BGM" : "SFX";

            DebugWrapper.LogError("[AudioSystem] No free channels. Sound is being dropped for " + channelType + " increase channel count!");
            chanNr = -1;
            return(null);
        }
    IEnumerator CoLoadSpriteBundle(string filePath, string assetName)
    {
        using (loader = UnityWebRequestAssetBundle.GetAssetBundle(filePath, 0))
        {
            yield return(loader.SendWebRequest());

            if (loader.error != null)
            {
                DebugWrapper.LogError("어셋 번들 로딩 중에 문제가 발생했습니다.");
            }
            else
            {
                AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(loader);

                SpriteAtlas atlas = assetBundle.LoadAsset <SpriteAtlas>(assetName);
                for (int i = 0; i < numberSprites.Length; ++i)
                {
                    numberSprites[i] = atlas.GetSprite($"JudgeAtlas_{i + 1}");
                }
            }
        }
    }
Beispiel #25
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);
        }
Beispiel #26
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();
        }
Beispiel #27
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);
        }
Beispiel #28
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();
        }
Beispiel #29
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);
        }
Beispiel #30
0
        public void Should_LogTrue_When_ArrayContainsOneBooleanSetToTrue()
        {
            LogAssert.Expect(LogType.Log, "True");

            DebugWrapper.LogCollection(new [] { true });
        }