Beispiel #1
0
        /// <summary>
        /// Performs all necessary initializations.
        /// </summary>
        private void Start()
        {
            // Create the 4 gizmos
            _objectMoveGizmo      = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            _objectRotationGizmo  = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            _objectScaleGizmo     = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            _objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();

            // Call the 'SetEnabled' function on the parent gizmo to make sure
            // the gizmos are initially hidden in the scene. We want the gizmo
            // to show only when we have a target object available.
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // We initialize the work gizmo to the move gizmo by default. This means
            // that the first time an object is clicked, the move gizmo will appear.
            // You can change the default gizmo, by simply changing these 2 lines of
            // code. For example, if you wanted the scale gizmo to be the default work
            // gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
            // with GizmoId.Scale.
            _workGizmo   = _objectMoveGizmo;
            _workGizmoId = GizmoId.Move;
        }
Beispiel #2
0
        public bool RemoveBehaviour(IGizmoBehaviour behaviour)
        {
            if (behaviour == null)
            {
                return(false);
            }

            if (behaviour == _moveGizmo)
            {
                _moveGizmo = null;
            }
            else if (behaviour == _rotationGizmo)
            {
                _rotationGizmo = null;
            }
            else if (behaviour == _scaleGizmo)
            {
                _scaleGizmo = null;
            }
            else if (behaviour == _universalGizmo)
            {
                _universalGizmo = null;
            }
            else if (behaviour == _sceneGizmo)
            {
                _sceneGizmo = null;
            }
            else if (behaviour == _objectTransformGizmo)
            {
                _objectTransformGizmo = null;
            }

            return(_behaviours.Remove(behaviour));
        }
Beispiel #3
0
        /// <summary>
        /// Performs all necessary initializations.
        /// </summary>
        private void Start()
        {
            // Create the 4 gizmos
            _objectMoveGizmo      = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            _objectRotationGizmo  = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            _objectScaleGizmo     = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            _objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();

            // Call the 'SetEnabled' function on the parent gizmo to make sure
            // the gizmos are initially hidden in the scene. We want the gizmo
            // to show only when we have a target object available.
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // Link the selected objects list to the gizmos
            _objectMoveGizmo.SetTargetObjects(_selectedObjects);
            _objectRotationGizmo.SetTargetObjects(_selectedObjects);
            _objectScaleGizmo.SetTargetObjects(_selectedObjects);
            _objectUniversalGizmo.SetTargetObjects(_selectedObjects);

            // We initialize the work gizmo to the move gizmo by default.
            _workGizmo   = _objectMoveGizmo;
            _workGizmoId = GizmoId.Move;

            // Find side menu
            sideMenu = GameObject.Find("SideMenu");
            scene    = sideMenu.GetComponent <SceneObjects>();
        }
Beispiel #4
0
        /// <summary>
        /// Performs all necessary initializations.
        /// </summary>
        private void Start()
        {
            // Create the 4 gizmos
            _objectMoveGizmo      = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            _objectRotationGizmo  = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            _objectScaleGizmo     = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            _objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();

            // Call the 'SetEnabled' function on the parent gizmo to make sure
            // the gizmos are initially hidden in the scene. We want the gizmo
            // to show only when we have a target object available.
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // Link the selected objects list to the gizmos
            // Note: The 'SetTargetObjects' function will instruct the gizmo to store
            //       a direct reference to the '_selecteObjects' list. This means that
            //       when you add or remove objects from this list, the gizmos will have
            //       access to the most recent/updated collection. You don't need to call
            //       'SetTargetObjects' again when the list changes.
            _objectMoveGizmo.SetTargetObjects(_selectedObjects);
            _objectRotationGizmo.SetTargetObjects(_selectedObjects);
            _objectScaleGizmo.SetTargetObjects(_selectedObjects);
            _objectUniversalGizmo.SetTargetObjects(_selectedObjects);

            // We initialize the work gizmo to the move gizmo by default. This means
            // that the first time an object is clicked, the move gizmo will appear.
            // You can change the default gizmo, by simply changing these 2 lines of
            // code. For example, if you wanted the scale gizmo to be the default work
            // gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
            // with GizmoId.Scale.
            _workGizmo   = _objectMoveGizmo;
            _workGizmoId = GizmoId.Move;

            // <BEGIN TUTORIAL>
            // Get a reference to the object whose pivot we want to modify
            GameObject doorObject = GameObject.Find("GreenCube");

            // Calculate the object's world OBB and then use the 'BoxMath.CalcBoxFaceCenter'
            // to calculate the center of the object's left face in world space. We will use
            // this face center as our pivot.
            OBB     worldOBB   = ObjectBounds.GetMeshWorldOBB(doorObject);
            Vector3 faceCenter = BoxMath.CalcBoxFaceCenter(worldOBB.Center, worldOBB.Size, worldOBB.Rotation, BoxFace.Left);

            // Use the 'SetObjectCustomLocalPivot' function to specify the object's pivot.
            // Note: We need to call 'InverseTransformPoint' on the face center because the function expects
            //       a pivot point expressed in the object's local coordinate system.
            _objectRotationGizmo.SetObjectCustomLocalPivot(doorObject, doorObject.transform.InverseTransformPoint(faceCenter));

            // Change the transform pivot to 'CustomObjectLocalPivot'
            _objectRotationGizmo.SetTransformPivot(GizmoObjectTransformPivot.CustomObjectLocalPivot);
            // <END TUTORIAL>
        }
Beispiel #5
0
        /// <summary>
        /// This function is called to change the type of work gizmo. This is
        /// used in the 'Update' function in response to the user pressing the
        /// W,E,R,T keys to switch between different gizmo types.
        /// </summary>
        private void SetWorkGizmoId(GizmoId gizmoId)
        {
            // If the specified gizmo id is the same as the current id, there is nothing left to do
            if (gizmoId == _workGizmoId)
            {
                return;
            }

            // Start with a clean slate and disable all gizmos
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // At this point all gizmos are disabled. Now we need to check the gizmo id
            // and adjust the '_workGizmo' variable.
            _workGizmoId = gizmoId;
            if (gizmoId == GizmoId.Move)
            {
                _workGizmo = _objectMoveGizmo;
            }
            else if (gizmoId == GizmoId.Rotate)
            {
                _workGizmo = _objectRotationGizmo;
            }
            else if (gizmoId == GizmoId.Scale)
            {
                _workGizmo = _objectScaleGizmo;
            }
            else if (gizmoId == GizmoId.Universal)
            {
                _workGizmo = _objectUniversalGizmo;
            }

            // If we have any selected objects, we need to make sure the work gizmo is enabled
            if (_selectedObjects.Count != 0)
            {
                // Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
                // enabled. The 'SetEnabled' call will simply be ignored if that is the case.
                _workGizmo.Gizmo.SetEnabled(true);

                // When working with transform spaces and pivots, the gizmos need to know about the pivot object.
                // This piece of information is necessary when the transform space is set to local because in that
                // case the gizmo will have its rotation synchronized with the target objects rotation. But because
                // there is more than one target object, we need to tell the gizmo which object to use. This is the
                // role if the pivot object in this case. This pivot object is also useful when the transform pivot
                // is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
                _workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
            }
        }
Beispiel #6
0
        /// <summary>
        /// This function is called to change the type of work gizmo. This is
        /// used in the 'Update' function in response to the user pressing the
        /// W,E,R,T keys to switch between different gizmo types.
        /// </summary>
        private void SetWorkGizmoId(GizmoId gizmoId)
        {
            // If the specified gizmo id is the same as the current id, there is nothing left to do
            if (gizmoId == _workGizmoId)
            {
                return;
            }

            // Start with a clean slate and disable all gizmos
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // At this point all gizmos are disabled. Now we need to check the gizmo id
            // and adjust the '_workGizmo' variable.
            _workGizmoId = gizmoId;
            if (gizmoId == GizmoId.Move)
            {
                _workGizmo = _objectMoveGizmo;
            }
            else if (gizmoId == GizmoId.Rotate)
            {
                _workGizmo = _objectRotationGizmo;
            }
            else if (gizmoId == GizmoId.Scale)
            {
                _workGizmo = _objectScaleGizmo;
            }
            else if (gizmoId == GizmoId.Universal)
            {
                _workGizmo = _objectUniversalGizmo;
            }

            // If we have any selected objects, we need to make sure the work gizmo is enabled
            if (_selectedObjects.Count != 0)
            {
                // Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
                // enabled. The 'SetEnabled' call will simply be ignored if that is the case.
                _workGizmo.Gizmo.SetEnabled(true);

                // The last step we need to perform is to make sure that the work gizmo is positioned
                // and rotated correctly. This is because the gizmos (as will become more clear in
                // later tutorials) have 2 properties such as transform space and transform pivot and
                // when the selected objects change, these 2 properties will dictate how the gizmo should
                // be positioned and rotated. In order to ensure that the correct position and rotation
                // are used, we need to call 'RefreshPositionAndRotation'.
                _workGizmo.RefreshPositionAndRotation();
            }
        }
Beispiel #7
0
        public bool AddBehaviour(IGizmoBehaviour behaviour)
        {
            if (behaviour == null || behaviour.Gizmo != null)
            {
                return(false);
            }

            GizmoBehaviorInitParams initParams = new GizmoBehaviorInitParams();

            initParams.Gizmo = this;

            behaviour.Init_SystemCall(initParams);
            if (!_behaviours.Add(behaviour))
            {
                return(false);
            }

            Type behaviourType = behaviour.GetType();

            if (behaviourType == typeof(MoveGizmo))
            {
                _moveGizmo = behaviour as MoveGizmo;
            }
            else if (behaviourType == typeof(RotationGizmo))
            {
                _rotationGizmo = behaviour as RotationGizmo;
            }
            else if (behaviourType == typeof(ScaleGizmo))
            {
                _scaleGizmo = behaviour as ScaleGizmo;
            }
            else if (behaviourType == typeof(UniversalGizmo))
            {
                _universalGizmo = behaviour as UniversalGizmo;
            }
            else if (behaviourType == typeof(SceneGizmo))
            {
                _sceneGizmo = behaviour as SceneGizmo;
            }
            else if (behaviourType == typeof(ObjectTransformGizmo))
            {
                _objectTransformGizmo = behaviour as ObjectTransformGizmo;
            }

            behaviour.OnAttached();
            behaviour.OnEnabled();

            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// Performs all necessary initializations. In this tutorial, we create
        /// 4 gizmos and assign them to 4 different objects each.
        /// </summary>
        private void Start()
        {
            // We will first create the move gizmo. We make a call to 'RTGizmosEngine.Get.CreateObjectMoveGizmo'
            // and this function will return an instance of the 'ObjectTransformGizmo' class which is configured
            // to act like a move gizmo. The 'ObjectTransformGizmo' class is derived from 'GizmoBehaviour'. You
            // can think of a gizmo behaviour as the equivalent of a 'MonoBehaviour', but for gizmos. The object
            // transform gizmo behaviour is responsible for listening to gizmo drag events (when you drag the gizmo
            // with the mouse) and applying the drag values to the target object which is set via 'SetTargetObject'.
            ObjectTransformGizmo objectTransformGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            GameObject           targetObject         = GameObject.Find("RedCube");

            objectTransformGizmo.SetTargetObject(targetObject);

            // Now we need to add support for vertex snapping. In order to do this, we need to access another gizmo
            // behaviour: 'MoveGizmo'. This behaviour is responsible for drawing the gizmo in the scene and generating
            // the drag values which are then intercepted by 'ObjectTransformGizmo'. In order to support vertex snapping,
            // we have to call 'SetVertexSnapTargetObjects' and pass a list of objects that contain the source vertices.
            // In this case, we only have one target object, so we will use that.
            MoveGizmo moveGizmo = objectTransformGizmo.Gizmo.MoveGizmo;

            moveGizmo.SetVertexSnapTargetObjects(new List <GameObject> {
                targetObject
            });

            // Now we need to do the same thing for the other gizmos. Next one on the list is the rotation gizmo. Again,
            // we use the 'RTGizmosEngine' class to create the gizmo. The return value is the same: an instance of the
            // 'ObjectTransformGizmo' class. The exception in this case is that the returned transform gizmo is configured
            // to intercept rotation values and thus it will rotate objects instead of moving them.
            objectTransformGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            targetObject         = GameObject.Find("GreenCube");
            objectTransformGizmo.SetTargetObject(targetObject);

            // Same for the scale gizmo
            objectTransformGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            targetObject         = GameObject.Find("BlueCube");
            objectTransformGizmo.SetTargetObject(targetObject);

            // Same for the universal gizmo.
            // Note: The object transform gizmo returned from 'CreateObjectUniversalGizmo' is configured to intercept all
            //       types of drag values: offset, rotation and scale. This is because a universal gizmo can be used to
            //       move, rotate and scale objects.
            objectTransformGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
            targetObject         = GameObject.Find("YellowCube");
            objectTransformGizmo.SetTargetObject(targetObject);
        }
Beispiel #9
0
        /// <summary>
        /// Performs all necessary initializations.
        /// </summary>
        private void Start()
        {
            // Create the 4 gizmos
            _objectMoveGizmo      = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            _objectRotationGizmo  = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            _objectScaleGizmo     = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            _objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();

            // Call the 'SetEnabled' function on the parent gizmo to make sure
            // the gizmos are initially hidden in the scene. We want the gizmo
            // to show only when we have a target object available.
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // Link the selected objects list to the gizmos
            // Note: The 'SetTargetObjects' function will instruct the gizmo to store
            //       a direct reference to the '_selecteObjects' list. This means that
            //       when you add or remove objects from this list, the gizmos will have
            //       access to the most recent/updated collection. You don't need to call
            //       'SetTargetObjects' again when the list changes.
            _objectMoveGizmo.SetTargetObjects(_selectedObjects);
            _objectRotationGizmo.SetTargetObjects(_selectedObjects);
            _objectScaleGizmo.SetTargetObjects(_selectedObjects);
            _objectUniversalGizmo.SetTargetObjects(_selectedObjects);

            // We initialize the work gizmo to the move gizmo by default. This means
            // that the first time an object is clicked, the move gizmo will appear.
            // You can change the default gizmo, by simply changing these 2 lines of
            // code. For example, if you wanted the scale gizmo to be the default work
            // gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
            // with GizmoId.Scale.
            _workGizmo   = _objectMoveGizmo;
            _workGizmoId = GizmoId.Move;

            // <BEGIN TUTORIAL>
            // Get a reference to the object whose position we will use as the world pivot
            GameObject pivotObject = GameObject.Find("Sphere");

            // Set the world pivot
            _objectRotationGizmo.SetCustomWorldPivot(pivotObject.transform.position);
            _objectRotationGizmo.SetTransformPivot(GizmoObjectTransformPivot.CustomWorldPivot);
            // <END TUTORIAL>
        }
Beispiel #10
0
        /// <summary>
        /// This function is called to change the type of work gizmo. This is
        /// used in the 'Update' function in response to the user pressing the
        /// W,E,R,T keys to switch between different gizmo types.
        /// </summary>
        private void SetWorkGizmoId(GizmoId gizmoId)
        {
            // If the specified gizmo id is the same as the current id, there is nothing left to do
            if (gizmoId == _workGizmoId)
            {
                return;
            }

            // Start with a clean slate and disable all gizmos
            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotationGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            // At this point all gizmos are disabled. Now we need to check the gizmo id
            // and adjust the '_workGizmo' variable.
            _workGizmoId = gizmoId;
            if (gizmoId == GizmoId.Move)
            {
                _workGizmo = _objectMoveGizmo;
            }
            else if (gizmoId == GizmoId.Rotate)
            {
                _workGizmo = _objectRotationGizmo;
            }
            else if (gizmoId == GizmoId.Scale)
            {
                _workGizmo = _objectScaleGizmo;
            }
            else if (gizmoId == GizmoId.Universal)
            {
                _workGizmo = _objectUniversalGizmo;
            }

            // At this point, the work gizmo points to the correct gizmo based on the
            // specified gizmo id. All that's left to do is to activate the gizmo.
            // Note: We only activate the gizmo if we have a target object available.
            //       If no target object is available, we don't do anything because we
            //       only want to show a gizmo when a target is available for use.
            if (_targetObject != null)
            {
                _workGizmo.Gizmo.SetEnabled(true);
            }
        }
        private void Start()
        {
            _objectMoveGizmo      = RTGizmosEngine.Get.CreateObjectMoveGizmo();
            _objectRotateionGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
            _objectScaleGizmo     = RTGizmosEngine.Get.CreateObjectScaleGizmo();
            _objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();

            _objectMoveGizmo.SetTargetObjects(_selectObjects);
            _objectRotateionGizmo.SetTargetObjects(_selectObjects);
            _objectScaleGizmo.SetTargetObjects(_selectObjects);
            _objectUniversalGizmo.SetTargetObjects(_selectObjects);

            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotateionGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            _workGizmoId = GizmoId.move;
            _workGizmo   = _objectMoveGizmo;
        }
        void SetWorkGizmoId(GizmoId gizmoId)
        {
            if (gizmoId == _workGizmoId)
            {
                return;
            }

            _objectMoveGizmo.Gizmo.SetEnabled(false);
            _objectRotateionGizmo.Gizmo.SetEnabled(false);
            _objectScaleGizmo.Gizmo.SetEnabled(false);
            _objectUniversalGizmo.Gizmo.SetEnabled(false);

            _workGizmoId = gizmoId;
            if (gizmoId == GizmoId.move)
            {
                _workGizmo = _objectMoveGizmo;
            }
            else if (gizmoId == GizmoId.Rotate)
            {
                _workGizmo = _objectRotateionGizmo;
            }
            else if (gizmoId == GizmoId.Scale)
            {
                _workGizmo = _objectScaleGizmo;
            }
            else if (gizmoId == GizmoId.Universal)
            {
                _workGizmo = _objectUniversalGizmo;
            }

            if (_selectObjects.Count != 0)
            {
                _workGizmo.Gizmo.SetEnabled(true);
                _workGizmo.RefreshPositionAndRotation();
            }
        }