Skip to content
Snippets Groups Projects
DropHandling.cs 1.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • BenniHome's avatar
    BenniHome committed
    using UnityEngine.EventSystems;
    
    
    public class DropHandling : MonoBehaviour, IDropHandler, IPointerClickHandler
    
    BenniHome's avatar
    BenniHome committed
    {
        GameObject current;
    
        public Fact currentFact;
    
        public void OnDrop(PointerEventData eventData)
        {
    
    
    Richard Marcus's avatar
    Richard Marcus committed
            var scrollFact = gameObject.GetComponent<RenderedScrollFact>();
    
            Debug.Log(eventData.pointerDrag.GetComponent<FactWrapper>().fact.Label + " was dropped on "
                + gameObject.name + " " + scrollFact.ID + "/" +
                ScrollDetails.ParameterDisplays.Count + " label: " + scrollFact.Label);
    
    
    BenniHome's avatar
    BenniHome committed
            Destroy(current);
    
            current = Instantiate(eventData.pointerDrag, Vector3.zero, Quaternion.identity);
    
            //Set imageToChangeDefaultColor of current: Fix so that current won't take the color
            //the dragged item was having during animation
            current.GetComponent<ImageHintAnimation>().imageToChangeDefaultColor = eventData.pointerDrag.GetComponent<ImageHintAnimation>().imageToChangeDefaultColor;
            current.GetComponent<ImageHintAnimation>().ResetAnimation();
    
    BenniHome's avatar
    BenniHome committed
            current.transform.SetParent(gameObject.transform, false);
    
            var rect = current.GetComponent<RectTransform>();
            rect.anchorMin = new Vector2(0.5f, 0.5f);
            rect.anchorMax = new Vector2(0.5f, 0.5f);
    
    
            currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact;
    
            current.GetComponent<FactWrapper>().fact = currentFact;
    
            Debug.Log("recieved Fact: " + currentFact.Id);
    
            CommunicationEvents.NewAssignmentEvent.Invoke();
    
    BenniHome's avatar
    BenniHome committed
        }
    
    
        public void OnPointerClick(PointerEventData eventData)
        {
    
            Destroy(current);
            currentFact = null;
            CommunicationEvents.NewAssignmentEvent.Invoke();
        }
    
    
    BenniHome's avatar
    BenniHome committed
    }