void OnDrop(GameObject go) { targetName = this.gameObject.name; ExampleDragDropItem ddo = go.GetComponent <ExampleDragDropItem>(); if (ddo != null && ddo.gameObject.name == targetName) { Sprite original_sprite = ddo.transform.GetChild(0).GetComponent <UI2DSprite>().sprite2D; //GameObject child = NGUITools.AddChild(gameObject, m_sprite); this.gameObject.GetComponent <SpriteRenderer>().sprite = original_sprite; this.GetComponent <Collider>().enabled = false; Instantiate(prefab_Particle, transform.position, transform.rotation); Camera.main.GetComponent <AudioSource>().Play(); //Transform trans = child.transform; //trans.position = UICamera.lastWorldPosition; //if (rotatePlacedObject) trans.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f); if (GameController.Instance.puzzleCount < maxPuzzlePieces - 1) { GameController.Instance.puzzleCount += 1; } else { Debug.Log("EndGAME"); } Destroy(go); } }
/// <summary> /// Start the dragging operation. /// </summary> void OnDragStart() { if (!enabled || mTouchID != int.MinValue) { return; } // If we have a restriction, check to see if its condition has been met first if (restriction != Restriction.None) { if (restriction == Restriction.Horizontal) { Vector2 delta = UICamera.currentTouch.totalDelta; if (Mathf.Abs(delta.x) < Mathf.Abs(delta.y)) { return; } } else if (restriction == Restriction.Vertical) { Vector2 delta = UICamera.currentTouch.totalDelta; if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { return; } } else if (restriction == Restriction.PressAndHold) { if (mPressTime + 1f > RealTime.time) { return; } } } if (cloneOnDrag) { GameObject clone = NGUITools.AddChild(transform.parent.gameObject, gameObject); clone.transform.localPosition = transform.localPosition; clone.transform.localRotation = transform.localRotation; clone.transform.localScale = transform.localScale; UIButtonColor bc = clone.GetComponent <UIButtonColor>(); if (bc != null) { bc.defaultColor = GetComponent <UIButtonColor>().defaultColor; } UICamera.currentTouch.dragged = clone; ExampleDragDropItem item = clone.GetComponent <ExampleDragDropItem>(); item.Start(); item.OnDragDropStart(); } else { OnDragDropStart(); } }
void Start() { //preview movement tex = blockImageObject.GetComponent <UITexture>(); dDI = blockImageObject.GetComponent <ExampleDragDropItem>(); maxWidth = tex.width; sourceTex = sourceImage.mainTexture as Texture2D; }
void OnDrop(GameObject go) { ExampleDragDropItem ddo = go.GetComponent <ExampleDragDropItem>(); if (ddo != null) { GameObject child = NGUITools.AddChild(gameObject, ddo.prefab); Transform trans = child.transform; trans.position = UICamera.lastWorldPosition; if (rotatePlacedObject) { trans.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f); } Destroy(go); } }