/// Credit GXMark, alexzzzz, CaoMengde777, TroyDavis
/// Original Sourced from (GXMark) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1834806 (with corrections)
/// Scaling fixed for non overlay canvases (alexzzzz) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780612
/// Canvas border fix (CaoMengde777) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1781658
/// Canvas reset position fix (TroyDavis)- http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1782214
using System;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
///
/// Includes a few fixes of my own, mainly to tidy up duplicates, remove unneeded stuff and testing. (nothing major, all the crew above did the hard work!)
///
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/UI Window Base")]
public class UIWindowBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
private bool _isDragging = false;
public static bool ResetCoords = false;
private Vector3 m_originalCoods = Vector3.zero;
private Canvas m_canvas;
private RectTransform m_canvasRectTransform;
[Tooltip("Number of pixels of the window that must stay inside the canvas view.")]
public int KeepWindowInCanvas = 5;
[Tooltip("The transform that is moved when dragging, can be left empty in which case its own transform is used.")]
public RectTransform RootTransform = null;
// Use this for initialization
void Start()
{
if (RootTransform == null)
{
RootTransform = GetComponent();
}
m_originalCoods = RootTransform.position;
m_canvas = GetComponentInParent