Пример #1
0
        public static ModelGridElement Create(Transform parent, AssetModel data)
        {
            if (parent == null)
            {
                Debug.LogError("ModelGridElement:Create - Unable to create ModelGridElement: null parent");
                return(null);
            }

            if (data == null)
            {
                Debug.LogError("ModelGridElement:Create - Unable to create ModelGridElement: null AssetModel");
                return(null);
            }

            var prefabPath = Path.Combine(AppConstants.FileNames.PrefabsFolderName,
                                          AppConstants.FileNames.ModelGridElementPrefabName);
            var prefab = Resources.Load <ModelGridElement>(prefabPath);

            if (prefab == null)
            {
                Debug.LogError($"ModelGridElement:Create - Unable to load ModelGridElement prefab from {prefabPath}");
                return(null);
            }

            ModelGridElement res = GameObject.Instantiate(prefab, parent.transform);

            res._data = data;
            return(res);
        }
Пример #2
0
        protected override async void Start()
        {
            base.Start();
            _assetService = new LocalAssetService(_modelsData);

            var models = await _assetService.GetAssetModels();

            foreach (var model in models.Data)
            {
                var element = ModelGridElement.Create(_gridLayout.transform, model);
                element.OnInfoBtnClicked += ElementOnInfoBtnClicked;
            }
            SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
        }