public override GameObject Get(bool createWhenNoneLeft = true) { GameObject obj = null; if (inactiveObjectsPool.Count == 0) { if (createWhenNoneLeft) { DevdogLogger.Log("New object created, considering increasing the pool size if this is logged often"); obj = Instantiate(); } } else { obj = inactiveObjectsPool[inactiveObjectsPool.Count - 1]; } Assert.IsNotNull(obj, "Couldn't get poolable object from pool!"); obj.gameObject.SetActive(true); obj.gameObject.transform.localScale = Vector3.one; obj.gameObject.transform.localRotation = Quaternion.identity; activeObjectsList.Add(obj); inactiveObjectsPool.RemoveAt(inactiveObjectsPool.Count - 1); return(obj); }
/// <summary> /// Plays an audio clip, only use this for the UI, it is not pooled so performance isn't superb. /// </summary> public static void AudioPlayOneShot(AudioClipInfo clip) { if (clip == null || clip.audioClip == null) { return; } if (Instance == null) { DevdogLogger.LogWarning("AudioManager not found, yet trying to play an audio clip...."); } }
private static AudioSource GetNextAudioSource() { foreach (var audioSource in _audioSources) { if (audioSource.isPlaying == false) { return(audioSource); } } DevdogLogger.LogWarning("All sources taken, can't play audio clip..."); return(null); }
private string ToString(string msg, object[] vars) { try { return(string.Format(msg, vars)); } catch (Exception) { DevdogLogger.LogWarning("Invalid string.Format :: " + msg); } return(msg); }
public static Type[] GetAllTypesThatImplement(Type type, bool creatableTypesOnly) { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); // var assemblyList = new List<Assembly>(); // foreach (var assembly in assemblies) // { // if (assembly.FullName.StartsWith("Mono.Cecil") || // assembly.FullName.StartsWith("UnityScript") || // assembly.FullName.StartsWith("Boo.Lan") || // assembly.FullName.StartsWith("System") || // assembly.FullName.StartsWith("JetBrains") || // assembly.FullName.StartsWith("nunit") || // assembly.FullName.StartsWith("NUnit") || // assembly.FullName.StartsWith("I18N") || //// assembly.FullName.StartsWith("UnityEngine") || // //assembly.FullName.StartsWith("UnityEditor") || // assembly.FullName.StartsWith("mscorlib")) // { // continue; // } // assemblyList.Add(assembly); // } var types = new List <Type>(assemblies.Length); foreach (var assembly in assemblies) { try { types.AddRange(assembly.GetTypes()); } catch (Exception e) { DevdogLogger.LogError(e.Message); } } types = types.Where(o => type.IsAssignableFrom(o)).ToList(); if (creatableTypesOnly) { types = types.Where(o => o.IsAbstract == false && o.IsInterface == false).ToList(); } return(types.ToArray()); }
private static AudioSource GetNextAudioSource() { foreach (var audioSource in _audioSources) { if (audioSource.isPlaying == false) { return(audioSource); } } DevdogLogger.LogWarning("All sources taken, creating new on the fly... Consider increasing reserved audio sources"); var src = CreateNewAudioSource(); _audioSources.Add(src); return(src); }
/// <summary> /// Plays an audio clip, only use this for the UI, it is not pooled so performance isn't superb. /// </summary> public static void AudioPlayOneShot(AudioClipInfo clip) { if (clip == null || clip.audioClip == null) { return; } if (instance == null) { DevdogLogger.LogWarning("AudioManager not found, yet trying to play an audio clip...."); } if (_audioQueue.Any(o => o.audioClip == clip.audioClip) == false) { _audioQueue.Enqueue(clip); } }
public static void DeserializeTo(ref object obj, Type type, string json, List <UnityEngine.Object> objectReferences) { lock (_lockObject) { try { fsData data = fsJsonParser.Parse(json); SetObjectReferences(objectReferences); currentRootType = type; _serializer.TryDeserialize(data, type, ref obj).AssertSuccessWithoutWarnings(); } catch (Exception e) { DevdogLogger.LogError(e.Message + "\n" + e.StackTrace); // throw; } } }
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) { try { var db = Serializer.Context.Get <List <UnityEngine.Object> >(); if (data.IsNull == false) { int index = (int)data.AsInt64; if (index == -1 || index >= db.Count) { DevdogLogger.LogError("Couldn't deserialize UnityEngine.Object : " + instance + " - not found in database. (index: " + index + ")"); return(fsResult.Fail("Index out of range " + index)); } if (IsAssetWrapper(storageType)) { var def = typeof(Asset <>); var t = def.MakeGenericType(storageType.GetGenericArguments()[0]); var inst = (IAsset)Activator.CreateInstance(t); inst.objectVal = db[index]; instance = inst; } else if (typeof(UnityEngine.Object).IsAssignableFrom(storageType)) { instance = db[index]; } } else { instance = null; } } catch (Exception e) { DevdogLogger.LogError(e.Message + "\n" + e.StackTrace); return(fsResult.Fail(e.Message)); } return(fsResult.Success); }