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 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); } } }
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) { throw new Exception("Only None editor info can be resolve from Info resolver.Use EditorInfoResolver instead"); } if (Infoes.ContainsKey(infoType)) { return(Infoes[infoType]); } FortScriptableObject fortScriptableObject = (FortScriptableObject)Resources.Load(GetInfoResourceRelativeLocation(infoType)); if (fortScriptableObject == null) { LoadingSequences[infoType] = true; IInfo result = (IInfo)Activator.CreateInstance(infoType); if (result != null) { Infoes[infoType] = result; } LoadingSequences[infoType] = false; return(result); } LoadingSequences[infoType] = true; IInfo info = fortScriptableObject.Load(infoType); if (info != null) { Infoes[infoType] = info; } LoadingSequences[infoType] = false; return(info); }
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); }