Files
tianrunCRM/Assets/trCRM/Scripts/ui/MyDragManager.cs
2020-07-04 14:41:25 +08:00

111 lines
2.2 KiB
C#

using UnityEngine;
using System.Collections;
using Coolape;
using System.Collections.Generic;
public class MyDragManager : UIEventListener
{
public UIDragPageContents _dragPage;
public UIDragPageContents dragPage {
get {
if (_dragPage == null) {
UIGridPage gridpage = GetComponentInParent<UIGridPage> ();
if (gridpage != null) {
_dragPage = gridpage.GetComponentInParent<UIDragPageContents> ();
}
}
return _dragPage;
}
}
public UIDragScrollView _dragContent;
public UIDragScrollView dragContent {
get {
if (_dragContent == null) {
_dragContent = GetComponentInParent<UIDragScrollView> ();
}
return _dragContent;
}
}
// Vector2 totalDelta = Vector2.zero;
public void Start ()
{
if (dragPage != null)
dragPage.enabled = true;
if (dragContent != null)
dragContent.enabled = true;
}
bool canDrag = false;
public void OnPress (bool isPressed)
{
if (!NGUITools.GetActive (this))
return;
if (isPressed) {
canDrag = true;
if (dragPage != null) {
dragPage.enabled = true;
dragPage.OnPress (isPressed);
}
if (dragContent != null) {
dragContent.enabled = true;
dragContent.OnPress (isPressed);
}
} else {
canDrag = false;
if (dragPage != null) {
dragPage.enabled = true;
dragPage.OnPress (isPressed);
}
if (dragContent != null) {
dragContent.enabled = true;
dragContent.OnPress (isPressed);
}
}
}
public void notifyDrag (Vector2 delta)
{
if (!NGUITools.GetActive (this))
return;
if (dragPage != null && dragPage.enabled) {
dragPage.OnDrag (delta);
}
if (dragContent != null && dragContent.enabled) {
dragContent.OnDrag (delta);
}
}
public void OnDrag (Vector2 delta)
{
if (!NGUITools.GetActive (this))
return;
if (!canDrag) {
return;
}
canDrag = false;
if (Mathf.Abs (delta.x) > Mathf.Abs (delta.y)) {
// dragPage.enabled = true;
if (dragPage != null) {
dragPage.enabled = true;
dragContent.enabled = false;
// dragPage.OnPress (true);
// dragPage.OnDrag (delta);
}
} else {
if (dragContent != null) {
dragContent.enabled = true;
dragPage.enabled = false;
// dragContent.OnPress (true);
// dragContent.OnDrag (delta);
}
}
}
}