public static void ShowInfo(Type infoType) { InfoAttribute infoAttribute = infoType.GetCustomAttribute <InfoAttribute>(); if (infoAttribute == null) { throw new Exception("Info attribute not found"); } if (infoAttribute.Editor) { FortScriptableObject fortScriptableObject = AssetDatabase.LoadAssetAtPath <FortScriptableObject>(GetInfoLocation(infoType)); if (fortScriptableObject == null) { Resolve(infoType).Save(); fortScriptableObject = AssetDatabase.LoadAssetAtPath <FortScriptableObject>(GetInfoLocation(infoType)); } Selection.activeObject = fortScriptableObject; } else { FortScriptableObject fortScriptableObject = Resources.Load <FortScriptableObject>(InfoResolver.GetInfoResourceRelativeLocation(infoType)); if (fortScriptableObject == null) { InfoResolver.Resolve(infoType).Save(); fortScriptableObject = Resources.Load <FortScriptableObject>(InfoResolver.GetInfoResourceRelativeLocation(infoType)); } Selection.activeObject = fortScriptableObject; } }
public Balance() { if (InfoResolver.GetLoadingSequence <FortInfo>()) { return; } Values = InfoResolver.Resolve <FortInfo>().ValueDefenitions.ToDictionary(s => s, s => 0); }
public InstanceResolverResult ResolvePossibleData(object baseObject, object data, PropertyInfo property) { InstanceResolverResult result = new InstanceResolverResult { PossibleInstanceTokens = InfoResolver.Resolve <FortInfo>().MarketInfos.Where(info => info != null).Select(info => new InstanceToken(info.MarketName, info.MarketName)).ToArray() }; InstanceToken instanceToken = result.PossibleInstanceTokens.FirstOrDefault(token => string.Equals((string)token.Value, (string)data)); result.PresentableInstanceTokens = instanceToken == null ? new InstanceToken[0] : new[] { instanceToken }; return(result); }
public static void Save(Type infoType, IInfo info) { InfoAttribute infoAttribute = infoType.GetCustomAttribute <InfoAttribute>(); if (infoAttribute == null) { throw new Exception("Info attribute not found"); } if (infoAttribute.Editor) { string infoLocation = GetInfoLocation(infoType); string resourceDirectoryName = Path.GetDirectoryName(infoLocation); AssetDatabaseHelper.CreateFolderRecursive(resourceDirectoryName); FortScriptableObject fortScriptableObject = AssetDatabase.LoadAssetAtPath <FortScriptableObject>(infoLocation); bool newCreation = false; if (fortScriptableObject == null) { fortScriptableObject = (FortScriptableObject)ScriptableObject.CreateInstance(infoAttribute.ScriptableType); AssetDatabase.CreateAsset(fortScriptableObject, infoLocation); newCreation = true; } if (!newCreation) { fortScriptableObject.Save(info); EditorUtility.SetDirty(fortScriptableObject); } } else { FortScriptableObject fortInfoScriptable = Resources.Load <FortScriptableObject>(InfoResolver.GetInfoResourceRelativeLocation(infoType)); bool newCreation = false; if (fortInfoScriptable == null) { string infoResourceFullLocation = InfoResolver.GetInfoResourceFullLocation(infoType); string resourceDirectoryName = Path.GetDirectoryName(infoResourceFullLocation); AssetDatabaseHelper.CreateFolderRecursive(resourceDirectoryName); fortInfoScriptable = (FortScriptableObject)ScriptableObject.CreateInstance(infoAttribute.ScriptableType); AssetDatabase.CreateAsset(fortInfoScriptable, infoResourceFullLocation); newCreation = true; } if (!newCreation) { fortInfoScriptable.Save(info); EditorUtility.SetDirty(fortInfoScriptable); } } }
protected override void OnTargetChanged(IInfo targetObject) { LanguageEditorInfo languageEditorInfo = (LanguageEditorInfo)targetObject; if (languageEditorInfo != null) { if ( InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Any( info => languageEditorInfo.Languages.All(languageInfo => languageInfo.Id != info.Id))) { InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages = InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Where( info => languageEditorInfo.Languages.Any(languageInfo => languageInfo.Id == info.Id)) .ToArray(); InfoResolver.Resolve <FortInfo>().Save(); } } }
public void SyncValues() { if (Values == null) { Values = new Dictionary <string, int>(); } string[] valueDefenitions = InfoResolver.Resolve <FortInfo>().ValueDefenitions ?? new string[0]; foreach (string valueDefenition in valueDefenitions) { if (!Values.ContainsKey(valueDefenition)) { Values[valueDefenition] = 0; } } foreach (KeyValuePair <string, int> pair in Values.ToArray()) { if (!valueDefenitions.Contains(pair.Key)) { Values.Remove(pair.Key); } } }
public static IInfo Resolve(Type infoType) { if (!typeof(IInfo).IsAssignableFrom(infoType)) { throw new Exception("Only IInfo inherited interface types can be resolved"); } InfoAttribute infoAttribute = infoType.GetCustomAttribute <InfoAttribute>(); if (infoAttribute == null) { throw new Exception("Info attribute not found"); } if (!infoAttribute.Editor) { return(InfoResolver.Resolve(infoType)); } if (Infoes.ContainsKey(infoType)) { return(Infoes[infoType]); } FortScriptableObject fortScriptableObject = AssetDatabase.LoadAssetAtPath <FortScriptableObject>(GetInfoLocation(infoType)); if (fortScriptableObject == null) { LoadingSequences[infoType] = true; IInfo result = (IInfo)Activator.CreateInstance(infoType); Infoes[infoType] = result; LoadingSequences[infoType] = false; return(result); } LoadingSequences[infoType] = true; IInfo info = fortScriptableObject.Load(infoType); Infoes[infoType] = info; LoadingSequences[infoType] = false; return(info); }