public AssetBankItem AddAsset(string name, GameObject thumbnail, GameObject prefab, string tags, Func <AssetBankItem, Task <GameObject> > importFunction = null, bool skipInstantiation = false) { UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>(); if (null == uiGrabber) { Debug.LogError("Thumbnail game object must have a UIGrabber component. Use the UIGrabber.CreateXXXThumbnail helper functions to create such a thumbnail"); return(null); } int uid = thumbnail.GetHashCode(); GameObject root = new GameObject("AssetBankItem") { layer = LayerMask.NameToLayer("CameraHidden") }; AssetBankItem item = root.AddComponent <AssetBankItem>(); item.uid = uid; item.assetName = name; item.gameObject.name = name; item.thumbnail = thumbnail; item.prefab = prefab; item.thumbnail.transform.parent = root.transform; item.thumbnail.transform.localPosition += new Vector3(0, 0, -0.001f); item.builtin = false; item.importFunction = importFunction; item.skipInstantiation = skipInstantiation; item.AddTags(tags); foreach (var tag in item.tags) { this.tags.Add(tag); } item.uiItem = uiList.AddItem(item.transform); items.Add(uid, item); return(item); }
private void AddBuiltinAsset(string tags, string name, string uiPath, string prefabPath) { GameObject prefab = Resources.Load <GameObject>(prefabPath); GameObject thumbnail = UIGrabber.Create3DThumbnail(Instantiate(Resources.Load <GameObject>(uiPath)), OnUIObjectEnter, OnUIObjectExit); AssetBankItem item = AddAsset(name, thumbnail, prefab, tags); item.builtin = true; }
static IEnumerator _PopulateUIList(UIDynamicList uiList, UnityAction <int> onEnter, UnityAction <int> onExit) { while (!assetsLoaded) { yield return(null); } foreach (AssetBankItemData data in items.Values) { // Create thumbnail GameObject thumbnail = CreateThumbnail(data); UIGrabber uiGrabber = data.thumbnailType switch { ThumbnailType.Object => UIGrabber.Create3DGrabber(thumbnail), ThumbnailType.Image => UIGrabber.CreateImageGrabber(thumbnail), ThumbnailType.LazyImage => UIGrabber.CreateLazyImageGrabber(thumbnail, data.thumbnailPath), ThumbnailType.Text => UIGrabber.CreateTextGrabber(thumbnail), _ => throw new NotImplementedException() }; uiGrabber.uid = data.uid; uiGrabber.onEnterUI3DObject.AddListener(onEnter); uiGrabber.onExitUI3DObject.AddListener(onExit); // Create item GameObject root = new GameObject(data.assetName) { layer = LayerMask.NameToLayer("CameraHidden") }; AssetBankItem item = root.AddComponent <AssetBankItem>(); item.thumbnail = thumbnail; item.thumbnail.transform.parent = root.transform; item.thumbnail.transform.localPosition += new Vector3(0, 0, -0.001f); item.data = data; // Add it to the list uiList.AddItem(item.transform); } }
private Task <GameObject> ImportObjectAsync(AssetBankItem item) { return(GlobalState.GeometryImporter.ImportObjectAsync(item.assetName, bank.transform)); }