Beispiel #1
0
 /// <summary>
 /// Called from the 'Update' function in response to user input in order
 /// to change the transform pivot for all gizmos. The parameter represents
 /// the desired transform pivot and is of type 'GizmoObjectTransformPivot'.
 /// </summary>
 private void SetTransformPivot(GizmoObjectTransformPivot transformPivot)
 {
     _objectMoveGizmo.SetTransformPivot(transformPivot);
     _objectRotationGizmo.SetTransformPivot(transformPivot);
     _objectScaleGizmo.SetTransformPivot(transformPivot);
     _objectUniversalGizmo.SetTransformPivot(transformPivot);
 }
Beispiel #2
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 #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
            // 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>
        }