Esempio n. 1
0
        public static void AddVitalsSystem()
        {
            var go = NetObjectAssists.GetSelectedGameObject();

            if (!go)
            {
                return;
            }

            AddSystem(go, true);
        }
        public static void AddInventorySystem()
        {
            var go = NetObjectAssists.GetSelectedGameObject();

            if (!go)
            {
                return;
            }

            AddSystem(go, true);

            ///// Add AutoMountHitscan if has rb and doesn't exist yet
            //if (go.transform.GetNestedComponentInParents<Rigidbody>() || go.transform.GetNestedComponentInParents<Rigidbody2D>())
            //	if (!go.transform.GetNestedComponentInChildren<AutoMountHitscan>())
            //		AddAutoMountHitscan();
        }
Esempio n. 3
0
        private static void ConvertToZone(Preset preset)
        {
            var selection = NetObjectAssists.GetSelectedGameObject();

            if (selection != null)
            {
                if (!selection.CheckReparentable())
                {
                    return;
                }
            }

            selection.EnsureComponentExists <ContactTrigger>().UsePreset(preset);
            selection.EnsureComponentExists <VitalsContactReactor>().UsePreset(preset);

            selection.SetAllCollidersAsTriggger(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Add the core components needed for all Pickup types, and add toggles to existing children.
        /// </summary>
        public static GameObject ConvertToPickup(GameObject selection, Space_XD space, Dynamics dynamics, params System.Type[] allowedSystems)
        {
            selection = NetObjectAssists.ConvertToBasicNetObject(selection, Photon.Pun.OwnershipOption.Takeover);

            selection.EnsureComponentExists <ContactTrigger>();

            selection.EnsureComponentExists <SyncContact>();
            var ss = selection.EnsureComponentExists <SyncState>();

            ss.mountableTo.mask = MountSettings.AllTrueMask;
            selection.EnsureComponentExists <SyncOwner>();

            if (dynamics != Dynamics.Static)
            {
                selection.EnsureComponentExists <OnStateChangeKinematic>();
            }

            /// Add OnStateChangeToggle to existing children before creating placeholder children
            selection.EnsureComponentOnNestedChildren <OnStateChangeToggle>(false);

            /// Add ContactGroups, and set to default
            var hga = selection.EnsureComponentExists <ContactGroupAssign>();

            hga.contactGroups.Mask = 0;

            if (dynamics != Dynamics.Static)
            {
                selection.AddRigidbody(space);
                var st = selection.EnsureComponentExists <SyncTransform>();
                st.transformCrusher.SclCrusher.Enabled = false;
            }

            selection.CreateChildStatePlaceholders(space, dynamics, 1.5f);

            return(selection);
        }
Esempio n. 5
0
        public static void ConvertOculus()
        {
            var selection = NetObjectAssists.ConvertToBasicNetObject(null);

            if (selection == null)
            {
                return;
            }

            var t = selection.transform;

            /// Add root transform sync
            if (HasOculusController(t))
            {
                selection.transform.Add3dPosOnly().transform.Add3dEulerOnly();
            }

            selection.EnsureComponentExists <AutoDisableOculusObjects>();

            /// Tracking Space
            var trackingSpace = t.RecursiveFind("TrackingSpace");

            trackingSpace.Add3dEulerOnly();

            /// Hands
            var leftHandAnchor = t.RecursiveFind("LeftHandAnchor");
            var rghtHandAnchor = t.RecursiveFind("RightHandAnchor");

            leftHandAnchor.Add3DHandsPos().transform.Add3DHandsRot();
            rghtHandAnchor.Add3DHandsPos().transform.Add3DHandsRot();

            /// OVRCameraRig
            var cameraRig = t.RecursiveFind("OVRCameraRig");

            if (cameraRig)
            {
                cameraRig.gameObject.EnsureComponentExists <AutoOwnerComponentEnable>();
            }

            /// Add all SyncAnimator
            t.EnsureComponentExists <SyncAnimator, Animator>(null, null, true);

            selection.EnsureComponentExists <AutoDestroyUnspawned>();

            //Type ovrManagerType = Type.GetType("OVRManager");
            //if (ovrManagerType == null)
            //	ovrManagerType = Type.GetType("OVRManager, Oculus.VR, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

            /// Move OVRManager off of this object and onto a non-net object in the scene.
            //if (ovrManagerType != null)
            {
                var manager = t.GetComponentInChildren <OVRManager>();
                if (manager)
                {
                    var founds = UnityEngine.Object.FindObjectsOfType <OVRManager>();
                    UnityEngine.Object existing = null;
                    foreach (var found in founds)
                    {
                        if (found != manager)
                        {
                            Debug.Log("OVRManager exists in scene, removing from '" + selection.name + "'");
                            existing = found;
                            break;
                        }
                    }
                    if (founds == null)
                    {
                        Debug.Log("OVRManager moved from " + selection.name + "' to scene.");
                        manager.ComponentCopy(new GameObject("OVRManager"));
                        GameObject.DestroyImmediate(manager);
                    }
                }
            }

            selection.EnsureComponentExists <SimpleOculusAutomation>();


            Type ovrGrabberType = Type.GetType("OVRGrabber");

            if (ovrGrabberType == null)
            {
                ovrGrabberType = Type.GetType("OVRGrabber, Oculus.VR, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
            }

            var foundGrabbers = selection.transform.GetNestedComponentsInChildren <OVRGrabber, NetObject>(null);

            foreach (OVRGrabber grabber in foundGrabbers)
            {
                // Oculus was kind enough to make all of these vars protected and private... so we get to do all of this reflection trash.
                Type type = grabber.GetType();
                var  gripTransformFieldInfo = type.GetField("m_gripTransform", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                Transform grip = (gripTransformFieldInfo.GetValue(grabber) as Transform);

                Mount mount;
                if (grip)
                {
                    mount = grip.gameObject.EnsureComponentExists <Mount>();
                }
                else
                {
                    mount = grabber.gameObject.EnsureComponentExists <Mount>();
                }

                mount.mountType = MountSettings.GetOrCreate(grabber.name);
            }
        }