public bool Equals(FuzzyValue <T> other) { int thisInt = EnumInt32ToInt.Convert(this.linguisticVariable); int otherInt = EnumInt32ToInt.Convert(other.linguisticVariable); return(thisInt == otherInt && this.membershipDegree == other.membershipDegree); }
public TResult GetFromPool <TEnum, TResult>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable where TResult : class { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); for (int i = 0; i < Pool.Count; i++) { var item = Pool[i]; if (item.Component != null && item.EnumType == type && item.EnumValue == value && item.GameObject.activeSelf == false) { item.GameObject.SetActive(true); return((TResult)item.Component); } } var poolItem = new PoolItem(); var name = resource.ToString(); poolItem.EnumType = type; poolItem.EnumValue = value; poolItem.GameObject = Instantiate(type, value, name); poolItem.Component = poolItem.GameObject.GetComponent(typeof(TResult)); Pool.Add(poolItem); return((TResult)poolItem.Component); }
private SoundItem GetFreeItem <TEnum>(TEnum sound) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); for (int i = 0; i < AudioItems.Count; i++) { var item = AudioItems[i]; if (item.EnumType == type && item.EnumValue == value && item.Free) { item.Free = false; return(item); } } //create new Item var source = ResourceManager.CreatePrefabInstance <TEnum, AudioSource>(sound); var newItem = new SoundItem(type, value, source, false); AudioItems.Add(newItem); newItem.Free = false; return(newItem); }
//Use this method to avoid heap memory allocation. //You have to disable GameObject to make it available from pool. public GameObject GetFromPool <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); for (int i = 0; i < Pool.Count; i++) { var item = Pool[i]; if (item.EnumType == type && item.EnumValue == value && item.GameObject.activeSelf == false) { item.GameObject.transform.parent = null; item.GameObject.SetActive(true); return(item.GameObject); } } //create new Item var poolItem = new PoolItem(); var name = resource.ToString(); poolItem.EnumType = type; poolItem.EnumValue = value; poolItem.GameObject = Instantiate(type, value, name); Pool.Add(poolItem); return(poolItem.GameObject); }
// private methods private TransitionKey GetKey(TEnum from, TEnum to) { int ifrom = EnumInt32ToInt.Convert(from); int ito = EnumInt32ToInt.Convert(to); var key = new TransitionKey(ifrom, ito); return(key); }
public static EnumKey From <T>(T value) where T : struct, System.IConvertible { FuzzyUtils.IsGenericParameterValid <T>(); EnumKey key = new EnumKey(); key.typeHash = typeof(T).GetHashCode(); key.valueHash = EnumInt32ToInt.Convert(value); return(key); }
public AudioClip LoadAudioClip <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var clip = (AudioClip)GetAsset(type, value, name); return(clip); }
public void Warm <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var gameObject = GetFromPool(type, value, name); gameObject.SetActive(false); }
public GameObject CreatePrefabInstance <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var go = Instantiate(type, value, name); return(go); }
public GameObject GetPrefab <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var go = (GameObject)GetAsset(type, value, name); return(go); }
public UnityEngine.Object GetAsset <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var asset = GetAsset(type, value, name); return(asset); }
private SoundSetting GetSettings <TEnum>(TEnum sound) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); var key = new EnumComparerKey(type, value); if (SoundSettings.ContainsKey(key) == false) { SoundSettings[key] = SoundSetting.Default; } return(SoundSettings[key]); }
public TResult CreatePrefabInstance <TEnum, TResult>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable where TResult : class { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var go = Instantiate(type, value, name); var component = go.GetComponent(typeof(TResult)) as TResult; return((TResult)component); }
public IPromise PlayAndNotify <TEnum>(TEnum sound) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); var setting = GetResultingSetting(type, value); var item = GetFreeItem(sound); item.SetSetting(setting); return(item.PlayAndNotify()); }
public void WarmAll <TEnum>() where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); foreach (TEnum prefab in Enum.GetValues(type)) { int value = EnumInt32ToInt.Convert(prefab); var name = prefab.ToString(); var gameObject = GetFromPool(type, value, name); gameObject.SetActive(false); } }
public string GetName <T>(T param) where T : struct, IComparable, IConvertible, IFormattable// where T: Enum { var type = typeof(T); int value = EnumInt32ToInt.Convert <T>(param); var key = new EnumCacheKey(type, value); if (Cache.ContainsKey(key) == false) { Cache.Add(key, param.ToString()); } var result = Cache[key]; return(result); }
private void SetSettings <TEnum>(TEnum sound, SoundSetting setting) where TEnum : struct, IComparable, IConvertible, IFormattable { using (var list = GetPlayingAudioItemsCopy(sound)) { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); var key = new EnumComparerKey(type, value); SoundSettings[key] = setting; foreach (var item in list) { ApplySetting(item); } } }
public void Register <TEnum>(TEnum sound, AudioSource source) where TEnum : struct, IComparable, IConvertible, IFormattable { using (var list = GetInternalAudioItemsCopy(sound)) { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); if (list.Count > 0) { throw new Exception("External & internal sounds conflict! Such item already exists as internal!"); } var newItem = new SoundItem(type, value, source, true); AudioItems.Add(newItem); newItem.Free = false; } }
private PoolableList <SoundItem> GetInternalAudioItemsCopy <TEnum>(TEnum sound) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); var value = EnumInt32ToInt.Convert(sound); var list = ListPool.Rent(); for (int i = 0; i < AudioItems.Count; i++) { if (AudioItems[i].External == false && AudioItems[i].EnumType == type && AudioItems[i].EnumValue == value) { list.Add(AudioItems[i]); } } return(list); }
public void Release <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); var key = new EnumComparerKey(type, value); ResourceCache.Remove(key); for (int i = Pool.Count - 1; i >= 0; i--) { var item = Pool[i]; if (item.EnumType == type && item.EnumValue == value) { Pool.RemoveAt(i); break; } } }
//load form fbx public AnimationClip LoadAnimationClip <TEnum>(TEnum resource) where TEnum : struct, IComparable, IConvertible, IFormattable { var type = typeof(TEnum); int value = EnumInt32ToInt.Convert(resource); var name = resource.ToString(); var key = new EnumComparerKey(type, value); if (ResourceCache.ContainsKey(key) == false) { var path = GetPathFromNamespace(type, name); var asset = Resources.Load <GameObject>(path); if (asset == null) { throw new UnityException("Can't load resource '" + name + "'"); } ResourceCache[key] = asset.GetComponent <Animation>().clip; } return(ResourceCache[key] as AnimationClip); }
public override int GetHashCode() { int thisInt = EnumInt32ToInt.Convert(this.linguisticVariable); return(thisInt * 17 + this.membershipDegree.GetHashCode()); }
public static int ToInt(TEnum en) { return(EnumInt32ToInt.Convert <TEnum>(en)); }