public class WCDragDropItemSelection : UIDragDropItem
{
int count;
bool hasShrunkFlag;
private Vector3 _significantMovementDelta;
public UIScrollView scrollView;
UIScrollView mScroll;
bool mAutoFind = false;
private bool _isScrollViewScrolling;
public bool isScrollViewScrolling { get{return _isScrollViewScrolling;} }
public Transform Parent { get {return mParent;} set {mParent = value;} }
public UIPanel rootPanel;
void Awake()
{
_isScrollViewScrolling = true;
_significantMovementDelta
= new Vector3
(); count = 0;
hasShrunkFlag = false;
}
protected override void Start ()
{
base.Start ();
_significantMovementDelta = mTrans.localPosition;
}
void OnEnable()
{
StartCoroutine(FindScrollView());
if(mScroll)
{
mScroll.onDragFinished += scrollingEnd;
}
}
IEnumerator FindScrollView ()
{
yield return new WaitForSeconds
(0
.5f
);
// If the scroll view is on a parent, don't try to remember it (as we want it to be dynamic in case of re-parenting)
UIScrollView sv = NGUITools.FindInParents<UIScrollView>(transform);
if (scrollView == null)
{
scrollView = sv;
mAutoFind = true;
}
else if (scrollView == sv)
{
mAutoFind = true;
}
mScroll = scrollView;
yield return null;
}
public void ManuallyStartDrag (bool isStarting)
{
if(!isStarting)
{
return;
}
// Automatically disable the scroll view
if (mDragScrollView != null) mDragScrollView.enabled = false;
// // Disable the collider so that it doesn't intercept events
if (mCollider != null) mCollider.enabled = false;
mParent = mTrans.parent;
mRoot = NGUITools.FindInParents<UIRoot>(mParent);
mGrid = NGUITools.FindInParents<UIGrid>(mParent);
mTable = NGUITools.FindInParents<UITable>(mParent);
// Re-parent the item
if (UIDragDropRoot.root != null)
mTrans.parent = UIDragDropRoot.root;
Vector3 pos = mTrans.localPosition;
pos.z = 0f;
mTrans.localPosition = pos;
// Notify the widgets that the parent has changed
NGUITools.MarkParentAsChanged(gameObject);
if (mTable != null) mTable.repositionNow = true;
if (mGrid != null) mGrid.repositionNow = true;
}
public void TempSetGrid( UIGrid grid )
{
mGrid = grid;
}
protected override void OnDragDropStart ()
{
base.OnDragDropStart ();
//here
if(mGrid)
{
WCGrid grid = (WCGrid)mGrid;
WCCard card = gameObject.GetComponent<WCCard>();
grid.CardPulledFromGrid(card);
}
}
protected override void OnDragDropMove (Vector3 delta)
{
count++;
if(count > 1)
{
mTrans.localPosition += delta;
Vector3 vec = _significantMovementDelta - mTrans.localPosition;
if(vec.magnitude > 10 && !hasShrunkFlag)
{
hasShrunkFlag = true;
_significantMovementDelta = mTrans.localPosition;
WCSelectionScale selectionScale = gameObject.GetComponent<WCSelectionScale>();
selectionScale.scale(false);
}
}
}
protected override void OnDragDropRelease (GameObject surface)
{
base.OnDragDropRelease (surface);
count = 0;
hasShrunkFlag = false;
UIDragDropContainer container = UICamera.hoveredObject ? NGUITools.FindInParents<UIDragDropContainer>(surface) : null;
if (container != null)
{
WCGrid grid = NGUITools.FindInParents<WCGrid>(transform);
if(mGrid)
{
WCCard card = gameObject.GetComponent<WCCard>();
grid.CardDroppedIntoGrid(card);
}
}
}
void scrollingEnd()
{
_isScrollViewScrolling = false;
}
public void setRoot(UIRoot root)
{
this.mRoot = root;
}
}