ScrollViewScript.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class ScrollViewScript : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
  6. {
  7. public GameObject prefab;
  8. public Transform contentPanel;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. SetGiventQuestion();
  13. }
  14. public void SetGiventQuestion()
  15. {
  16. // if new game, create one question card to start with
  17. GameObject question = Instantiate(prefab, new Vector2(0,0), Quaternion.identity) as GameObject;
  18. QuestionCard questionCard = question.GetComponent<QuestionCard>();
  19. questionCard.PrepareQuestion();
  20. questionCard.GetQuestion(true);
  21. questionCard.SetQuestionSafe();
  22. questionCard.transform.SetParent(contentPanel);
  23. }
  24. /*
  25. public void OnDrop(PointerEventData eventData) {
  26. Debug.Log(eventData.pointerDrag + " dropped on " + gameObject.name);
  27. Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
  28. if (d != null) {
  29. // Kontrollera om man släppt kortet på en korrekt possition,
  30. d.parent = contentPanel;
  31. }
  32. } */
  33. public void OnDrop(PointerEventData eventData) {
  34. Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
  35. if (d != null) {
  36. d.placeholderParent = this.transform;
  37. }
  38. }
  39. public void OnPointerEnter(PointerEventData eventData) {
  40. if (eventData.pointerDrag == null) {
  41. return;
  42. }
  43. Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
  44. if (d != null) {
  45. d.placeholderParent = this.transform;
  46. }
  47. }
  48. public void OnPointerExit(PointerEventData eventData) {
  49. if (eventData.pointerDrag == null) {
  50. return;
  51. }
  52. Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
  53. if (d != null && d.placeholderParent == this.transform) {
  54. d.placeholderParent = d.parent;
  55. }
  56. }
  57. }