Beispiel #1
0
        /// <summary>
        /// Called from the 'Update' function when the user clicks on a game object
        /// that is different from the current target object. The function takes care
        /// of adjusting the gizmo states accordingly.
        /// </summary>
        public void OnTargetObjectChanged(GameObject newTargetObject)
        {
            // Store the new target object
            _targetObject = newTargetObject;

            // Is the target object valid?
            if (_targetObject != null)
            {
                // It is. Now call 'SetTargetObject' for all gizmos. After the next 4 lines
                // of code are executed, all gizmos will be able to control this object.
                _objectMoveGizmo.SetTargetObject(_targetObject);
                _objectRotationGizmo.SetTargetObject(_targetObject);
                _objectScaleGizmo.SetTargetObject(_targetObject);
                _objectUniversalGizmo.SetTargetObject(_targetObject);

                // Make sure the work gizmo is enabled. We always activate the work gizmo when
                // a target object is valid. 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);
            }
            else
            {
                // The target object is null. In this case, we don't want any gizmos to be visible
                // in the scene, so we disable all of them.
                _objectMoveGizmo.Gizmo.SetEnabled(false);
                _objectRotationGizmo.Gizmo.SetEnabled(false);
                _objectScaleGizmo.Gizmo.SetEnabled(false);
                _objectUniversalGizmo.Gizmo.SetEnabled(false);
            }
        }
Beispiel #2
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);
        }