private void RegisterViews(UiViewReference reference, Type targetType, TypeViewReferenceDictionary map) { if (map.TryGetValue(targetType, out var items) == false) { items = new UiReferenceList(); map[targetType] = items; } if (items.references.Contains(reference)) { return; } items.references.Add(reference); }
private void ApplyOverrideValues(UiViewReference viewReference) { var overrideValue = previousReferences .FirstOrDefault(x => x.Type.Equals(viewReference.Type) && x.ModelType.Equals(viewReference.ModelType) && string.Equals(x.Tag, viewReference.Tag) && string.Equals(x.ViewName, viewReference.ViewName)); var type = overrideValue?.ViewModelType.Type; if (type == null || type.IsAbstract || type.IsInterface) { return; } viewReference.ViewModelType = overrideValue.ViewModelType; }
private void AddView(ViewsSettings viewsSettings, IView view, bool defaultView, string groupName) { var assetView = view as MonoBehaviour; if (assetView == null) { GameLog.LogError($"View at Path not Unity Asset with View Type {defaultView}"); return; } var gameObject = assetView.gameObject; var guid = gameObject.GetGUID(); var views = viewsSettings.uiViews; if (views.Any(x => string.Equals(guid, x.AssetGUID))) { return; } var assetPath = AssetDatabase.GetAssetPath(gameObject); var tag = defaultView ? string.Empty : Path.GetFileName(Path.GetDirectoryName(assetPath)); var labels = viewsSettings.labels; gameObject.SetAddressableAssetGroup(groupName); var assetReference = gameObject.PrefabToAssetReference(); if (assetReference.RuntimeKeyIsValid() == false) { GameLog.LogError($"Asset {gameObject.name} by path {assetPath} wrong addressable asset"); return; } var viewDescription = new UiViewReference() { Tag = tag, AssetGUID = assetReference.AssetGUID, Type = view.GetType(), View = assetReference, ViewName = assetReference.editorAsset.name }; views.Add(viewDescription); }
public UiViewReference CreateViewReference(IView view, bool defaultView, bool overrideAddressables, string groupName) { var assetView = view as MonoBehaviour; var gameObject = assetView.gameObject; var assetPath = AssetDatabase.GetAssetPath(gameObject); var tag = defaultView ? string.Empty : Path.GetFileName(Path.GetDirectoryName(assetPath)); if (overrideAddressables || !gameObject.IsInAnyAddressableAssetGroup()) { gameObject.SetAddressableAssetGroup(groupName); } var assetReference = gameObject.PrefabToAssetReference(); if (assetReference.RuntimeKeyIsValid() == false) { GameLog.LogError($"Asset {gameObject.name} by path {assetPath} wrong addressable asset"); return(null); } var viewType = view.GetType(); var viewInterface = viewType.GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == ViewSystemConstants.BaseViewType); var modelsArgs = viewInterface.GetGenericArguments(); var modelType = modelsArgs.FirstOrDefault(); var viewModelType = ViewModelsAssemblyMap.GetFirstAssignable(modelType); var viewDescription = new UiViewReference() { Tag = tag, AssetGUID = assetReference.AssetGUID, Type = viewType, ModelType = modelType, ViewModelType = viewModelType, View = assetReference, ViewName = assetReference.editorAsset.name }; return(viewDescription); }
public void RegisterViewReference(UiViewReference viewReference) { RegisterViews(viewReference, viewReference.Type, viewsTypeMap); RegisterViews(viewReference, viewReference.ModelType, modelTypeMap); }