Ejemplo n.º 1
0
        /// <summary>
        /// Forces play to grab newly instantiated object on both VR or Desktop
        /// </summary>
        /// <param name="chosenList"></param>
        /// <param name="listIndex"></param>
        /// <param name="instantiatedObject"></param>
        /// <returns></returns>
        IEnumerator DelayGrabInHand(InstantiationList chosenList, int listIndex, GameObject instantiatedObject)
        {
            yield return(new WaitForSeconds(.1f));

            if (chosenList.instantiationList[listIndex].instantiateInHand)
            {
                /*
                 * GrabObject grabObject = instantiatedObject.GetComponent<GrabObject>();
                 * if (grabObject)
                 * {
                 *  grabObject.Grab(1f);
                 * }
                 */
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a single gameObject from the instantiationList at a given index
        /// </summary>
        /// <param name="listIndex"></param>
        private GameObject SingleObjectInstantiation(int listIndex, bool isParticle)
        {
            InstantiationList chosenList = null;

            if (instantiatedObjects.Count == ObjectCountMax) // Clears the latest object added to the list to ensure that there are only the max amount of objects in the room
            {
                GameObject OldRemove = instantiatedObjects[0].gameObject;
                instantiatedObjects.Remove(OldRemove);
                Destroy(OldRemove);
            }

            if (!isParticle)
            {
                chosenList = instantiations;
            }
            else
            {
                if (particles != null)
                {
                    chosenList = particles;
                }
                else
                {
                    Debug.Log("[WARNING] Attempting to use particles without a valid particle list");
                }
            }

            if (chosenList != null && chosenList.instantiationList != null && chosenList.instantiationList[listIndex] != null && chosenList.instantiationList[listIndex].instantiatableGameObject != null)
            {
                GameObject instantiatedObject = null;
                if (chosenList.instantiationList[listIndex].instantiationReferenceObject == null)
                {
                    if (chosenList.instantiationList[listIndex].instantiatableMode == InstantiatableGameObject.InstantiatableVelocityMode.Local)
                    {
                        instantiatedObject = Instantiate(chosenList.instantiationList[listIndex].instantiatableGameObject, transform.position + chosenList.instantiationList[listIndex].instantiationLocation, GetGameObjectQuaterion(transform.forward + chosenList.instantiationList[listIndex].instantiationRotation));
                    }
                    else if (chosenList.instantiationList[listIndex].instantiatableMode == InstantiatableGameObject.InstantiatableVelocityMode.Global)
                    {
                        instantiatedObject = Instantiate(chosenList.instantiationList[listIndex].instantiatableGameObject, chosenList.instantiationList[listIndex].instantiationLocation, GetGameObjectQuaterion(chosenList.instantiationList[listIndex].instantiationRotation));
                    }
                }
                else
                {
                    instantiatedObject = Instantiate(chosenList.instantiationList[listIndex].instantiatableGameObject, chosenList.instantiationList[listIndex].instantiationReferenceObject.position, chosenList.instantiationList[listIndex].instantiationReferenceObject.rotation);
                }

                if (instantiatedObject != null)
                {
                    instantiatedObjects.Add(instantiatedObject); //Adds this Object to the Object List
                    instantiatedObject.name = chosenList.instantiationList[listIndex].instantiatableGameObject.name;
                    instantiatedObject.transform.localScale = chosenList.instantiationList[listIndex].instantiationScale;
                    if (chosenList.instantiationList[listIndex].initialVelocity != Vector3.zero)
                    {
                        if (instantiatedObject && instantiatedObject.GetComponent <Rigidbody>())
                        {
                            if (chosenList.instantiationList[listIndex].instantiationReferenceObject == null)
                            {
                                if (chosenList.instantiationList[listIndex].instantiatableMode == InstantiatableGameObject.InstantiatableVelocityMode.Local)
                                {
                                    instantiatedObject.GetComponent <Rigidbody>().AddForce(transform.forward + chosenList.instantiationList[listIndex].initialVelocity);
                                }
                                else
                                {
                                    instantiatedObject.GetComponent <Rigidbody>().AddForce(chosenList.instantiationList[listIndex].initialVelocity);
                                }
                            }
                            else
                            {
                                instantiatedObject.GetComponent <Rigidbody>().AddForce(chosenList.instantiationList[listIndex].instantiationReferenceObject.forward * (chosenList.instantiationList[listIndex].initialVelocity).magnitude);
                            }
                        }
                    }

                    if (chosenList.instantiationList[listIndex].instantiateInHand)
                    {
                        StartCoroutine(DelayGrabInHand(chosenList, listIndex, instantiatedObject));
                    }
                }
                return(instantiatedObject);
            }
            else if (chosenList == null)
            {
                Debug.Log("[WARNING] Instantiation list property not defined");
            }
            else if (chosenList.instantiationList == null)
            {
                Debug.Log("[WARNING] Nothing set in Instantiation list");
            }
            else if (chosenList.instantiationList[listIndex] == null)
            {
                Debug.Log("[WARNING] Instantiation index of ( " + listIndex + " ) set to nothing");
            }
            else if (chosenList.instantiationList[listIndex].instantiatableGameObject == null)
            {
                Debug.Log("[WARNING] GameObject of Instantiation index ( " + listIndex + " ) not set");
            }
            return(null);
        }