コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 private static Task <GameObject> ImportObjectAsync(AssetBankItemData data)
 {
     return(GlobalState.GeometryImporter.ImportObjectAsync(data.assetName, bank.transform));
 }
コード例 #6
0
 public static bool TryGetItem(int uid, out AssetBankItemData item)
 {
     return(items.TryGetValue(uid, out item));
 }