using System.Collections;
public class DragDropUnit : UIDragDropItem {
private GameObject clone;
private SelectUnit baseSelectUnitType;
protected override void OnDragDropStart ()
clone = NGUITools.AddChild(transform.parent.gameObject, gameObject);
clone.transform.localPosition = transform.localPosition;
clone.transform.localRotation = transform.localRotation;
clone.transform.localScale = transform.localScale;
clone.name = transform.gameObject.name;
clone.layer = 5; // UIのlayer
// デッキのアイテムが選択されたかアイテムが選択されたかを保持
if(transform.gameObject.name.IndexOf("DeckUnit") != -1)
baseSelectUnitType = SelectUnit.DECK;
baseSelectUnitType = SelectUnit.ITEM;
clone.transform.FindChild("Sprite").gameObject.GetComponent<UISprite>().color = Color.gray;
// ドラッグするオブジェクトをUI Root直下に移動
transform.parent = GameObject.Find ("UI Root").transform;
transform.gameObject.GetComponent<BoxCollider>().enabled = false;
// ドラッグ中のオブジェクトが手前に来るようにUIPanelをアタッチして強制的に前へ
UIPanel uiPanel = gameObject.AddComponent<UIPanel>();
gameObject.GetComponent<UIDragScrollView>().enabled = false;
// ホバーなどのエフェクトを出したいときにはここでRayを飛ばしてぶつかっていればエフェクト表示などをするとよい
protected override void OnDragDropMove (Vector3 delta)
base.OnDragDropMove(delta);
protected override void OnDragDropRelease (GameObject surface)
if(baseSelectUnitType == SelectUnit.DECK && surface.name.IndexOf("ItemUnit") != -1 ||
baseSelectUnitType == SelectUnit.ITEM && surface.gameObject.name.IndexOf("DeckUnit") != -1)
UISprite baseUISprite = clone.transform.FindChild("Sprite").gameObject.GetComponent<UISprite>();
string baseSpriteName = baseUISprite.spriteName;
UISprite dropUISprite = surface.transform.FindChild("Sprite").gameObject.GetComponent<UISprite>();
string dropSpriteName = dropUISprite.spriteName;
baseUISprite.spriteName = dropSpriteName;
dropUISprite.spriteName = baseSpriteName;
// 元の位置に戻すアニメーション(iTween)
iTween.MoveTo(gameObject, iTween.Hash("x", clone.transform.position.x, "y",clone.transform.position.y, "time", 0.5f, "oncomplete", "moveReset", "oncompletetarget", gameObject));
// 元の位置に戻すアニメーション(iTween)
iTween.MoveTo(gameObject, iTween.Hash("x", clone.transform.position.x, "y",clone.transform.position.y, "time", 0.5f, "oncomplete", "moveReset", "oncompletetarget", gameObject));
clone.transform.FindChild("Sprite").gameObject.GetComponent<UISprite>().color = Color.white;
base.OnDragDropRelease(surface);