Ejemplo n.º 1
0
        public static GameObject TurnIntoProxyObject(MenuCommand command)
        {
            MARSSession.EnsureRuntimeState();
            EditorEvents.CreationMenuItemUsed.Send(new MarsMenuEventArgs {
                label = k_TurnIntoProxy
            });
            var go = TurnIntoInContext(command, k_ProxyLabel, k_ProxyObjectBaseComponents);

            return(RegisterUndoAndSelect(go, "Turned into Proxy"));
        }
Ejemplo n.º 2
0
        public static GameObject TurnIntoReplicator(MenuCommand command)
        {
            MARSSession.EnsureRuntimeState();
            EditorEvents.CreationMenuItemUsed.Send(new MarsMenuEventArgs {
                label = k_TurnIntoReplicator
            });
            var go = TurnIntoInContext(command, k_ReplicatorLabel, typeof(Replicator));

            return(RegisterUndoAndSelect(go, "Turned into Replicator"));
        }
Ejemplo n.º 3
0
        public static GameObject CreateRulesetObject(MenuCommand command)
        {
            MARSSession.EnsureRuntimeState();
            EditorEvents.CreationMenuItemUsed.Send(new MarsMenuEventArgs {
                label = k_CreateRulesetObjectLabel
            });
            var go = CreateInContext(command, k_RuleSetLabel, new Type[] { typeof(Rules.ProxyRuleSet) });

            return(RegisterUndoAndSelect(go, "Create Rule Set"));
        }
Ejemplo n.º 4
0
        public static GameObject TurnIntoProxyPlane(MenuCommand command)
        {
            MARSSession.EnsureRuntimeState();
            EditorEvents.CreationMenuItemUsed.Send(new MarsMenuEventArgs {
                label = k_TurnIntoProxyPlane
            });
            var types = k_ProxyObjectBaseComponents.ToList();

            types.Add(typeof(PlaneSizeCondition));
            types.Add(typeof(AlignmentCondition));
            var go = TurnIntoInContext(command, k_ProxyLabel, types.ToArray());

            go.GetComponent <PlaneSizeCondition>().maxBounded = false;
            return(RegisterUndoAndSelect(go, "Turned into Proxy Plane"));
        }
Ejemplo n.º 5
0
        static bool SessionConfigured(MARSSession session)
        {
            if (session == null)
            {
                return(false);
            }

            var sessionObject    = session.gameObject;
            var sessionTransform = session.transform;
            var sessionCamera    = session.m_CameraReference;
            var cameraTransform  = sessionCamera.transform;

            return(sessionCamera != null && sessionCamera.gameObject.activeInHierarchy && cameraTransform != sessionTransform &&
                   cameraTransform.IsChildOf(sessionTransform) && session.m_UserReference != null && sessionObject.activeInHierarchy);
        }
Ejemplo n.º 6
0
 public static GameObject CreateMARSSessionObject(MenuCommand command)
 {
     MARSSession.EnsureRuntimeState();
     return(MARSSession.Instance.gameObject);
 }
Ejemplo n.º 7
0
        static void EnsureSessionConfigured(MARSSession session, UndoBlock undoBlock, Transform overrideUserRef = null)
        {
            var sessionObject    = session.gameObject;
            var sessionTransform = session.transform;
            var changed          = false;

            // Make sure we have a properly configured MARS Camera
            if (!TestMode && session.m_CameraReference == null)
            {
                var marsCameraRef = GameObjectUtils.ExhaustiveComponentSearch <MARSCamera>(sessionObject);

                // If we can't find a MARS camera, get the main camera and create one on that
                if (marsCameraRef == null)
                {
                    LogRuntimeIssue("MARSCamera not present in the scene.  Adding one to the main camera.");

                    var createdNewCamera = false;
                    var cameraRef        = GameObjectUtils.ExhaustiveTaggedComponentSearch <Camera>(sessionObject, k_CameraTag);
                    if (cameraRef == null)
                    {
                        cameraRef        = CreateCamera(sessionTransform, undoBlock);
                        createdNewCamera = true;
                    }

                    marsCameraRef = undoBlock.AddComponent <MARSCamera>(cameraRef.gameObject);

                    if (!createdNewCamera)
                    {
                        var nearPlane    = cameraRef.nearClipPlane;
                        var cameraParent = cameraRef.transform.parent;
                        if (cameraParent == null)
                        {
                            cameraParent = sessionTransform;
                        }

                        var worldScale         = cameraParent.localScale.x;
                        var scaledMaxNearPlane = k_MaxNearPlane * worldScale;
                        if (nearPlane > scaledMaxNearPlane)
                        {
                            LogRuntimeIssue("Camera near clip plane is greater than the recommended distance. " +
                                            $"Setting near plane from {nearPlane} to {scaledMaxNearPlane}.");

                            undoBlock.RecordObject(cameraRef);
                            cameraRef.nearClipPlane = scaledMaxNearPlane;
                        }
                    }
                }

                session.m_CameraReference = marsCameraRef;
                changed = true;
            }

            const string correctBrokenSessionMessage = "If you have not customized the MARSSession game object, just delete " +
                                                       "the object and go to Create > MARS > Session.";

            var cameraTrans = session.m_CameraReference.transform;

            if (!TestMode && cameraTrans.GetComponentInParent <MARSSession>() == null)
            {
                const string cameraParentRequirementMessage = "MARSCamera must have a MARSSession object in its list of parents.";
                var          canReparent = true;
#if INCLUDE_AR_FOUNDATION
                if (cameraTrans.GetComponentInParent <ARSessionOrigin>() != null)
                {
                    canReparent = false;
                    Debug.LogError($"{cameraParentRequirementMessage} Please make sure the MARSSession component " +
                                   $"is on the same game object as the ARSessionOrigin. {correctBrokenSessionMessage}");
                }
#endif
                if (canReparent)
                {
                    LogRuntimeIssue($"{cameraParentRequirementMessage} Re-parenting.");
                    var cameraParent = cameraTrans.parent;
                    if (cameraParent)
                    {
                        sessionTransform.position   = cameraParent.position;
                        sessionTransform.rotation   = cameraParent.rotation;
                        sessionTransform.localScale = cameraParent.localScale;
                    }

                    undoBlock.SetTransformParent(cameraTrans, sessionTransform);
                    changed = true;
                }
            }

            // Look for the user object, if it's not in the scene, make a new one
            var userRef = session.m_UserReference;
            if (!TestMode && userRef == null)
            {
                userRef = session.m_CameraReference.transform.Find(k_UserName);
                if (userRef == null)
                {
                    if (overrideUserRef == null)
                    {
                        userRef = GameObjectUtils.Instantiate(MARSRuntimePrefabs.instance.UserPrefab).transform;
                    }
                    else
                    {
                        userRef = overrideUserRef;
                    }

                    userRef.name          = k_UserName;
                    userRef.parent        = session.m_CameraReference.transform;
                    userRef.localPosition = Vector3.zero;
                    userRef.localRotation = Quaternion.identity;
                    userRef.localScale    = Vector3.one;
                    undoBlock.RegisterCreatedObject(userRef.gameObject);
                }

                session.m_UserReference = userRef;
                changed = true;
            }

            // One more bizarre scenario to catch - the MARS Session and Camera being *one* object.
            // We can't just delete the MARS Session since the user might have other scripts there, so we just throw up a warning telling them to fix things manually
            if (!TestMode && session.m_CameraReference.transform == sessionTransform)
            {
                Debug.LogError("The MARS Session should be a parent of the MARSCamera, *NOT* the same object!  " +
                               $"Please correct this in your scene! {correctBrokenSessionMessage}");
            }

            if (sessionObject.activeInHierarchy == false)
            {
                LogRuntimeIssue("There is a MARS Session object in your scene that is *not* active.  Running your scene with an inactive MARS Session will cause problems.");
                sessionObject.SetActive(true);
                changed = true;
            }

            var cameraObject = session.cameraReference.gameObject;
            if (cameraObject.activeInHierarchy == false)
            {
                LogRuntimeIssue("There is a MARS Camera GameObject in your scene that is *not* active.  " +
                                "Re-enabling here, as running your scene with an inactive MARS Camera would cause problems.");

                cameraObject.SetActive(true);
                changed = true;
            }

            if (changed)
            {
                DirtySimulatableSceneIfNeeded();
            }
        }