| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class ScrollViewScript : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
- {
- public GameObject prefab;
- public Transform contentPanel;
- // Start is called before the first frame update
- void Start()
- {
- SetGiventQuestion();
- }
- public void SetGiventQuestion()
- {
- // if new game, create one question card to start with
- GameObject question = Instantiate(prefab, new Vector2(0,0), Quaternion.identity) as GameObject;
- QuestionCard questionCard = question.GetComponent<QuestionCard>();
- questionCard.PrepareQuestion();
- questionCard.GetQuestion(true);
- questionCard.SetQuestionSafe();
- questionCard.transform.SetParent(contentPanel);
- }
- /*
- public void OnDrop(PointerEventData eventData) {
- Debug.Log(eventData.pointerDrag + " dropped on " + gameObject.name);
- Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
- if (d != null) {
- // Kontrollera om man släppt kortet på en korrekt possition,
- d.parent = contentPanel;
- }
- } */
- public void OnDrop(PointerEventData eventData) {
- Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
- if (d != null) {
- d.placeholderParent = this.transform;
- }
- }
- public void OnPointerEnter(PointerEventData eventData) {
- if (eventData.pointerDrag == null) {
- return;
- }
- Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
- if (d != null) {
- d.placeholderParent = this.transform;
- }
- }
- public void OnPointerExit(PointerEventData eventData) {
- if (eventData.pointerDrag == null) {
- return;
- }
- Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
- if (d != null && d.placeholderParent == this.transform) {
- d.placeholderParent = d.parent;
- }
- }
- }
|