Skip to content
Snippets Groups Projects
DropHandling.cs 2.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • BenniHome's avatar
    BenniHome committed
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;
    
    public class DropHandling : MonoBehaviour, IDropHandler 
    {
        GameObject current;
    
        public Fact currentFact;
    
    BenniHome's avatar
    BenniHome committed
        public void OnDrop(PointerEventData eventData){
    
    Richard Marcus's avatar
    Richard Marcus committed
            
    
    Richard Marcus's avatar
    Richard Marcus committed
            var scrollFact = gameObject.GetComponent<RenderedScrollFact>();
    
    Richard Marcus's avatar
    Richard Marcus committed
            Debug.Log(eventData.pointerDrag.GetComponent<FactWrapper>().fact.Label+ " was dropped on "
                + gameObject.name+ " " +scrollFact.ID + "/" +
                ScrollDetails.ParameterDisplays.Count+" label: "+scrollFact.Label);
    
            //TODO modularize this with functions when feature is approved
    
    
            //changes assigned label, used for later processing, if this should not be changed, use another variable for rhs data
            if (Scroll.FactOccurences[scrollFact.ID] != null)
            {
                scrollFact.Label = eventData.pointerDrag.GetComponent<FactWrapper>().fact.Label;
                Debug.Log(Scroll.FactOccurences[scrollFact.ID].Count);
                foreach (var id in Scroll.FactOccurences[scrollFact.ID])
                {
                    //change occurences in scroll description
                    if (id.Key == -1)
                    {
    
    
                        string label = ScrollDetails.ScrollDescription;
                        label = label.Remove(id.Value, 1);
                        label = label.Insert(id.Value, scrollFact.Label);
                        ScrollDetails.ScrollDescription = label;
                    }
                    // and also in facts
                    else
                    {
    
    Richard Marcus's avatar
    Richard Marcus committed
                        var affectedFact = ScrollDetails.ParameterDisplays[id.Key].GetComponentInChildren<RenderedScrollFact>();
    
    Richard Marcus's avatar
    Richard Marcus committed
                        string label = affectedFact.Label;
                        label = label.Remove(id.Value, 1);
                        label = label.Insert(id.Value, scrollFact.Label);
                        affectedFact.Label = label;
    
                    }
                }
    
            }
    
    
    
    BenniHome's avatar
    BenniHome committed
            Destroy(current);
            current = Instantiate(eventData.pointerDrag,Vector3.zero, Quaternion.identity);
            current.transform.SetParent(gameObject.transform, false);
    
            //PythagorasScript pythagorasScript = scrollShow.GetComponent<PythagorasScript>();
    
            currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact;
            Debug.Log("recieved Fact: " + currentFact.backendURI);
    
            //pythagorasScript.putFact(gameObject.name, fact);
    
    BenniHome's avatar
    BenniHome committed
        }
    
    }