public static AssetBankItemData AddAsset( string name, ThumbnailType thumbnailType, string thumbnailPath, GameObject prefab, string tags, Func <AssetBankItemData, Task <GameObject> > importFunction = null, bool builtin = false, bool skipInstantiation = false) { int uid = NextUID; AssetBankItemData data = new AssetBankItemData { uid = uid, assetName = name, thumbnailType = thumbnailType, thumbnailPath = thumbnailPath, prefab = prefab, builtin = builtin, importFunction = importFunction, skipInstantiation = skipInstantiation }; data.AddTags(tags); foreach (var tag in data.tags) { tagList.Add(tag); } items.Add(uid, data); return(data); }
public async void AddPrefab(AssetBankItemData data) { GunPrefabItem gunItem = GunPrefabItem.Create(data); gunItem.AddListener(OnDeletePrefab); UIDynamicListItem dlItem = prefabList.AddItem(gunItem.transform); dlItem.UseColliderForUI = false; // dont use the default global collider, sub-widget will catch UI events and propagate them. gunItem.transform.localScale = Vector3.one; // Items are hidden (scale 0) while they are not added into a list, so activate the item here. gunItem.SetListItem(dlItem); // link i await AssetBankUtils.LoadPrefab(selectedItem); prefabs.Add(data.prefab); }
public static GameObject CreateThumbnail(AssetBankItemData data) { if (null == textThumbnailPrefab) { textThumbnailPrefab = Resources.Load <GameObject>("Prefabs/UI/AssetBankGenericItem"); imageThumbnailPrefab = Resources.Load <GameObject>("Prefabs/UI/AssetBankImageItem"); } GameObject thumbnail = data.thumbnailType switch { ThumbnailType.Object => Create3DThumbnail(data.thumbnailPath), ThumbnailType.Text => CreateTextThumbnail(data.thumbnailPath), ThumbnailType.Image => CreateImageThumbnail(data.thumbnailPath), ThumbnailType.LazyImage => CreateLazyImageThumbnail(data.thumbnailPath), _ => throw new NotImplementedException() }; return(thumbnail); }
public static GunPrefabItem Create(AssetBankItemData data) { GameObject root = new GameObject("GunPrefabItem"); GunPrefabItem item = root.AddComponent <GunPrefabItem>(); root.layer = LayerMask.NameToLayer("CameraHidden"); // // Background Panel // UIPanel panel = UIPanel.Create(new UIPanel.CreatePanelParams { parent = root.transform, widgetName = "GunPrefabPreviewBackgroundPanel", relativeLocation = new Vector3(0.01f, -0.01f, -UIPanel.default_element_thickness), width = 0.14f, height = 0.12f, margin = 0.005f }); panel.SetLightLayer(3); // // Thumbnail & prefab // item.assetBankId = data.uid; item.prefab = data.prefab; item.thumbnail = AssetBankUtils.CreateThumbnail(data); if (item.thumbnail.TryGetComponent(out UIGrabber uiGrabber)) { Destroy(uiGrabber); } item.thumbnail.transform.parent = root.transform; if (data.thumbnailType == AssetBankUtils.ThumbnailType.Object) { item.thumbnail.transform.localPosition = new Vector3(0.07f, -0.06f, -0.03f); } else { item.thumbnail.transform.localPosition = new Vector3(0.03f, -0.01f, -0.01f); } // // Delete Button // UIButton deleteButton = UIButton.Create(new UIButton.CreateButtonParams { parent = panel.transform, widgetName = "DeleteButton", relativeLocation = new Vector3(0.11f, -0.09f, -UIButton.default_thickness), width = 0.03f, height = 0.03f, icon = UIUtils.LoadIcon("trash"), buttonContent = UIButton.ButtonContent.ImageOnly, margin = 0.001f, }); deleteButton.SetLightLayer(3); item.deleteButton = deleteButton; item.panel = panel; return(item); }
private static Task <GameObject> ImportObjectAsync(AssetBankItemData data) { return(GlobalState.GeometryImporter.ImportObjectAsync(data.assetName, bank.transform)); }
public static bool TryGetItem(int uid, out AssetBankItemData item) { return(items.TryGetValue(uid, out item)); }