示例#1
0
        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();
            }
        }
示例#2
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);
             }
         }
     });
 }
示例#3
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);
                }
            }
        }
示例#4
0
        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;
        }