ExampleDragDropItem.cs 905 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Drag and Drop Item (Example)")]
  4. public class ExampleDragDropItem : UIDragDropItem
  5. {
  6. protected override void OnDragDropRelease(GameObject surface)
  7. {
  8. if (surface != null)
  9. {
  10. ExampleDragDropSurface component = surface.GetComponent<ExampleDragDropSurface>();
  11. if (component != null)
  12. {
  13. GameObject gameObject = NGUITools.AddChild(component.gameObject, this.prefab);
  14. gameObject.transform.localScale = component.transform.localScale;
  15. Transform transform = gameObject.transform;
  16. transform.position = UICamera.lastWorldPosition;
  17. if (component.rotatePlacedObject)
  18. {
  19. transform.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f);
  20. }
  21. NGUITools.Destroy(base.gameObject);
  22. return;
  23. }
  24. }
  25. base.OnDragDropRelease(surface);
  26. }
  27. public GameObject prefab;
  28. }