private object OnSingleMonoAtPlay(Type implType, string path, GameObject parent) { if (!Singles.ContainsKey(implType)) { return(null); } var mono = Singles[implType]; return(mono); }
private object OnSingleMonoAtEditor(Type implType, string path, GameObject parent) { if (!Singles.ContainsKey(implType)) { return(null); } if (Singles[implType] == null) { Singles.Remove(implType); return(ResloveMono(implType, path, parent)); } var mono = Singles[implType]; return(mono); }
/// <summary> /// 解析一个mono实例。 /// 优先从单例字典中获取。 /// </summary> /// <param name="implType"></param> /// <param name="path"></param> /// <param name="parent"></param> /// <returns></returns> private object ResloveMono(Type implType, string path, GameObject parent) { object targetMono = null; var isSingle = implType.IsSingle(); if (isSingle && Singles.ContainsKey(implType)) { #if UNITY_EDITOR targetMono = OnSingleMonoAtEditor(implType, path, parent); #else targetMono = OnSingleMonoAtPlay(implType, path, parent); #endif } if (targetMono != null) { return(targetMono); } if (!string.IsNullOrEmpty(path) && PathMapObjs.ContainsKey(path)) { var mono = PathMapObjs[path]; return(mono); } targetMono = CreateNewMono(path, implType, isSingle, parent); if (isSingle) { CacheToSingles(implType, targetMono); } else { CacheToPathMapObjs(path, targetMono); } var fieldInfos = GetInjectFieldInfos(implType); var propertyInfos = GetInjectPropertyInfos(implType); InjectMonoFields(targetMono, fieldInfos); InjectMonoPropertys(targetMono, propertyInfos); InvokeInit(targetMono); return(targetMono); }
/// <summary> /// Returns storage content. /// </summary> /// <param name="type">The type of the storage content.</param> /// <param name="name">The name of the storage content.</param> public static object GetObject(string type, string name) { switch (type.ToLower()) { case "pokemon": if (Pokemons.ContainsKey(name)) { return(Pokemons[name]); } break; case "string": case "str": if (Strings.ContainsKey(name)) { return(Strings[name]); } break; case "integer": case "int": if (Integers.ContainsKey(name)) { return(Integers[name]); } break; case "boolean": case "bool": if (Booleans.ContainsKey(name)) { return(Booleans[name]); } break; case "item": if (Items.ContainsKey(name)) { return(Items[name]); } break; case "single": case "sng": if (Singles.ContainsKey(name)) { return(Singles[name]); } break; case "double": case "dbl": if (Doubles.ContainsKey(name)) { return(Doubles[name]); } break; } return(ScriptVersion2.ScriptComparer.DefaultNull); }
/// <summary> /// Adds or updates storage content. /// </summary> /// <param name="type">The type of the storage content.</param> /// <param name="name">The name of the storage content.</param> /// <param name="newContent">The new storage content.</param> public static void SetObject(string type, string name, object newContent) { switch (type.ToLower()) { case "pokemon": if (Pokemons.ContainsKey(name)) { Pokemons[name] = (BasePokemon)newContent; } else { Pokemons.Add(name, (BasePokemon)newContent); } break; case "string": case "str": if (Strings.ContainsKey(name)) { Strings[name] = Convert.ToString(newContent); } else { Strings.Add(name, Convert.ToString(newContent)); } break; case "integer": case "int": if (Integers.ContainsKey(name)) { Integers[name] = @int(newContent); } else { Integers.Add(name, @int(newContent)); } break; case "boolean": case "bool": if (Booleans.ContainsKey(name)) { Booleans[name] = Convert.ToBoolean(newContent); } else { Booleans.Add(name, Convert.ToBoolean(newContent)); } break; case "item": if (Items.ContainsKey(name)) { Items[name] = (BaseItem)newContent; } else { Items.Add(name, (BaseItem)newContent); } break; case "single": case "sng": if (Singles.ContainsKey(name)) { Singles[name] = sng(newContent); } else { Singles.Add(name, sng(newContent)); } break; case "double": case "dbl": if (Doubles.ContainsKey(name)) { Doubles[name] = dbl(newContent); } else { Doubles.Add(name, dbl(newContent)); } break; } }