Exemple #1
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);
        }
Exemple #2
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);
        }