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)); }
public ObjectTransformGizmo CreateObjectMoveGizmo() { MoveGizmo moveGizmo = CreateMoveGizmo(); var transformGizmo = moveGizmo.Gizmo.AddBehaviour <ObjectTransformGizmo>(); transformGizmo.SetTransformChannelFlags(ObjectTransformGizmo.Channels.Position); transformGizmo.SharedSettings = _objectMoveGizmoSettings; return(transformGizmo); }
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); }
public MoveGizmo CreateMoveGizmo() { Gizmo gizmo = CreateGizmo(); MoveGizmo moveGizmo = new MoveGizmo(); gizmo.AddBehaviour(moveGizmo); moveGizmo.SharedHotkeys = _moveGizmoHotkeys; moveGizmo.SharedLookAndFeel2D = _moveGizmoLookAndFeel2D; moveGizmo.SharedLookAndFeel3D = _moveGizmoLookAndFeel3D; moveGizmo.SharedSettings2D = _moveGizmoSettings2D; moveGizmo.SharedSettings3D = _moveGizmoSettings3D; return(moveGizmo); }
/// <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); }