コード例 #1
0
        void Start()
        {
            prefabList = panel.Find("Prefabs/List").GetComponent <UIDynamicList>();
            bankList   = panel.Find("BankPanel/List").GetComponent <UIDynamicList>();

            AssetBankUtils.LoadAssets();
            AssetBankUtils.PopulateUIList(bankList, OnUIObjectEnter, OnUIObjectExit);
        }
コード例 #2
0
ファイル: AssetBank.cs プロジェクト: ubisoft/vrtist
        private void AddObject(GameObject gobject)
        {
            if (!AssetBankUtils.TryGetItem(selectedItem, out AssetBankItemData item))
            {
                Debug.LogWarning($"Item {gobject.name} not found in Asset Bank (id: {selectedItem})");
                return;
            }

            // Get the position of the mouthpiece into matrix
            Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix;

            Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _);
            Vector3 scale = Vector3.one;

            CommandGroup group = new CommandGroup("Instantiate Bank Object");

            try
            {
                // Add the object to scene
                ClearSelection();
                CommandAddGameObject command = new CommandAddGameObject(gobject);
                command.Submit();
                GameObject newObject = command.newObject;
                if (item.imported)
                {
                    ParametersController controller = newObject.GetComponent <ParametersController>();
                    if (null == controller)
                    {
                        controller            = newObject.AddComponent <ParametersController>();
                        controller.isImported = true;
                        controller.importPath = item.assetName;
                    }
                }

                // Set the object size to 20cm in the user space
                Bounds bounds = new Bounds();
                foreach (var subMeshFilter in newObject.GetComponentsInChildren <MeshFilter>())
                {
                    if (!useDefaultInstantiationScale)
                    {
                        bounds.Encapsulate(subMeshFilter.mesh.bounds);
                    }
                }
                if (bounds.size.magnitude > 0)
                {
                    scale *= (0.2f / bounds.size.magnitude) / GlobalState.WorldScale;  // 0.2: 20cm
                }
                AddToSelection(newObject);
                SceneManager.SetObjectMatrix(newObject, Matrix4x4.TRS(t, Quaternion.identity, scale));
                Selection.HoveredObject = newObject;
            }
            finally
            {
                group.Submit();
            }
        }
コード例 #3
0
ファイル: AssetBank.cs プロジェクト: AnthonyMir/vrtist
        void Start()
        {
            Init();

            uiList = panel.GetComponentInChildren <UIDynamicList>();
            uiList.focusItemOnAdd = false;

            filterLabel = panel.Find("ListPanel/FilterLabel").GetComponent <UILabel>();

            AssetBankUtils.LoadAssets();
            AssetBankUtils.PopulateUIList(uiList, OnUIObjectEnter, OnUIObjectExit);
        }
コード例 #4
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);
        }
コード例 #5
0
 protected override void DoUpdateGui()
 {
     VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.triggerButton, () =>
     {
     }, () =>
     {
         // Manage click on an asset bank item
         if (selectedItem != -1)
         {
             if (AssetBankUtils.TryGetItem(selectedItem, out AssetBankItemData data))
             {
                 AddPrefab(data);
             }
         }
     });
 }
コード例 #6
0
        private void RebuildPrefabList()
        {
            List <int> uids = new List <int>();

            foreach (var uiItem in prefabList.GetItems())
            {
                uids.Add(uiItem.Content.GetComponent <GunPrefabItem>().assetBankId);
            }

            ClearPrefabs();
            foreach (int uid in uids)
            {
                if (AssetBankUtils.TryGetItem(uid, out AssetBankItemData data))
                {
                    AddPrefab(data);
                }
            }
        }
コード例 #7
0
ファイル: AssetBank.cs プロジェクト: ubisoft/vrtist
        public async Task OnGrabUIObject()
        {
            await AssetBankUtils.LoadPrefab(selectedItem);

            if (AssetBankUtils.TryGetItem(selectedItem, out AssetBankItemData item))
            {
                if (item.skipInstantiation)
                {
                    // Assets coming from Blender Asset Bank add-on
                    // We will receive them, no need to instantiate them
                    item.prefab = null;
                }
                if (null != item.prefab)
                {
                    GameObject instance = SceneManager.InstantiateObject(item.prefab);
                    AddObject(instance);
                }
            }
            selectedItem = -1;
        }
コード例 #8
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);
        }