public void InitModelsView(List <AssetModel> models) { if (null == models) { Debug.LogWarning("MainSceneView:InitModelsView - Unable to init models lsit. Null data"); return; } _modelsElements = new List <ModelMainSceneElement>(); for (int i = 0; i < _modelsLayout.transform.childCount; i++) { var child = _modelsLayout.transform.GetChild(i); Destroy(child.gameObject); } foreach (var model in models) { var newModel = ModelMainSceneElement.Create(_modelsLayout.transform, model); newModel.OnSelected += OnModelSelectedBtnClick; _modelsElements.Add(newModel); } if (_modelsElements.Count > 0) { _modelsElements[0].SetSelected(true); } }
public static ModelMainSceneElement Create(Transform parent, AssetModel data) { if (parent == null) { Debug.LogError("ModelMainSceneElement:Create - Unable to create ModelGridElement: null parent"); return(null); } if (data == null) { Debug.LogError("ModelMainSceneElement:Create - Unable to create ModelGridElement: null AssetModel"); return(null); } var prefabPath = Path.Combine(AppConstants.FileNames.PrefabsFolderName, AppConstants.FileNames.ModelMainSceneElementPrefabName); var prefab = Resources.Load <ModelMainSceneElement>(prefabPath); if (prefab == null) { Debug.LogError($"ModelMainSceneElement:Create - Unable to load ModelGridElement prefab from {prefabPath}"); return(null); } ModelMainSceneElement res = GameObject.Instantiate(prefab, parent.transform); res._data = data; return(res); }