Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        private void AddFileAsset(string filename)
        {
            string     name      = Path.GetFileNameWithoutExtension(filename).Replace('_', ' ');
            GameObject thumbnail = UIGrabber.CreateTextThumbnail(name, OnUIObjectEnter, OnUIObjectExit);
            string     tags      = filename.Substring(GlobalState.Settings.assetBankDirectory.Length);

            tags = tags.Substring(0, tags.LastIndexOf('.'));  // remove file extension
            AddAsset(filename, thumbnail, null, tags, importFunction: ImportObjectAsync);
        }
Exemplo n.º 4
0
        public static UIGrabber Create3DGrabber(GameObject thumbnail)
        {
            UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>();

            if (null == uiGrabber)
            {
                uiGrabber = thumbnail.AddComponent <UIGrabber>();
            }
            uiGrabber.rotateOnHover = true;
            return(uiGrabber);
        }
Exemplo n.º 5
0
        public static UIGrabber CreateLazyImageGrabber(GameObject thumbnail, string path)
        {
            UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>();

            if (null == uiGrabber)
            {
                uiGrabber = thumbnail.AddComponent <UIGrabber>();
            }
            uiGrabber.lazyImagePath = path;
            uiGrabber.rotateOnHover = false;
            return(uiGrabber);
        }
Exemplo n.º 6
0
        public static GameObject CreateLazyImageThumbnail(string path, UnityAction <int> onEnter, UnityAction <int> onExit)
        {
            LoadPrefabs();
            GameObject thumbnail = Instantiate(imageThumbnailPrefab);
            UIGrabber  uiGrabber = thumbnail.GetComponent <UIGrabber>();

            uiGrabber.lazyImagePath = path;
            uiGrabber.uid           = thumbnail.GetHashCode();
            uiGrabber.rotateOnHover = false;
            uiGrabber.onEnterUI3DObject.AddListener(onEnter);
            uiGrabber.onExitUI3DObject.AddListener(onExit);
            return(thumbnail);
        }
Exemplo n.º 7
0
        public static GameObject CreateImageThumbnail(Sprite image, UnityAction <int> onEnter, UnityAction <int> onExit)
        {
            LoadPrefabs();
            GameObject thumbnail = Instantiate(imageThumbnailPrefab);

            thumbnail.transform.Find("Canvas/Panel/Image").GetComponent <Image>().sprite = image;
            UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>();

            uiGrabber.uid           = thumbnail.GetHashCode();
            uiGrabber.rotateOnHover = false;
            uiGrabber.onEnterUI3DObject.AddListener(onEnter);
            uiGrabber.onExitUI3DObject.AddListener(onExit);
            return(thumbnail);
        }
Exemplo n.º 8
0
        public static GameObject CreateTextThumbnail(string text, UnityAction <int> onEnter, UnityAction <int> onExit)
        {
            LoadPrefabs();
            GameObject thumbnail = Instantiate(textThumbnailPrefab);

            thumbnail.transform.Find("Canvas/Panel/Name").GetComponent <TextMeshProUGUI>().text = text;
            UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>();

            uiGrabber.uid           = thumbnail.GetHashCode();
            uiGrabber.rotateOnHover = false;
            uiGrabber.onEnterUI3DObject.AddListener(onEnter);
            uiGrabber.onExitUI3DObject.AddListener(onExit);
            return(thumbnail);
        }
Exemplo n.º 9
0
        public static GameObject Create3DThumbnail(GameObject thumbnail, UnityAction <int> onEnter, UnityAction <int> onExit)
        {
            UIGrabber uiGrabber = thumbnail.GetComponent <UIGrabber>();

            if (null == uiGrabber)
            {
                uiGrabber = thumbnail.AddComponent <UIGrabber>();
            }
            uiGrabber.uid           = thumbnail.GetHashCode();
            uiGrabber.rotateOnHover = true;
            uiGrabber.onEnterUI3DObject.AddListener(onEnter);
            uiGrabber.onExitUI3DObject.AddListener(onExit);
            thumbnail.transform.localRotation = thumbnailRotation;

            MeshRenderer[] meshRenderers = thumbnail.GetComponentsInChildren <MeshRenderer>();
            foreach (MeshRenderer meshRenderer in meshRenderers)
            {
                meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            }

            return(thumbnail);
        }
Exemplo n.º 10
0
        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);
            }
        }