//---------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2015 Tasharen Entertainment //---------------------------------------------- using UnityEngine; /// /// Allows dragging of the camera object and restricts camera's movement to be within bounds of the area created by the rootForBounds colliders. /// [ExecuteInEditMode] [AddComponentMenu("NGUI/Interaction/Drag Camera")] public class UIDragCamera : MonoBehaviour { /// /// Target object that will be dragged. /// public UIDraggableCamera draggableCamera; /// /// Automatically find the draggable camera if possible. /// void Awake () { if (draggableCamera == null) { draggableCamera = NGUITools.FindInParents(gameObject); } } /// /// Forward the press event to the draggable camera. /// void OnPress (bool isPressed) { if (enabled && NGUITools.GetActive(gameObject) && draggableCamera != null) { draggableCamera.Press(isPressed); } } /// /// Forward the drag event to the draggable camera. /// void OnDrag (Vector2 delta) { if (enabled && NGUITools.GetActive(gameObject) && draggableCamera != null) { draggableCamera.Drag(delta); } } /// /// Forward the scroll event to the draggable camera. /// void OnScroll (float delta) { if (enabled && NGUITools.GetActive(gameObject) && draggableCamera != null) { draggableCamera.Scroll(delta); } } }