Exemple #1
0
        public void OnDrag(PointerEventData eventData)
        {
            if (!dragging)
            {
                return;
            }

            // move the dragged object with the mouse

            transform.position = eventData.position;

            DropZone zone = GetDropZoneUnderMouse();

            Debug.Log(zone);

            if (zone != currentZoneBelow)
            {
                if (zone != null)
                {
                    zone.OnDraggingEnter();
                }

                if (currentZoneBelow != null)
                {
                    currentZoneBelow.OnDraggingExit();
                }

                currentZoneBelow = zone;
            }
        }
Exemple #2
0
        // finds the firstSlot component currently under the mouse
        private DropZone GetDropZoneUnderMouse()
        {
            PointerEventData pointer = new PointerEventData(EventSystem.current);

            pointer.position = Input.mousePosition;
            List <RaycastResult> hits = new List <RaycastResult>();

            EventSystem.current.RaycastAll(pointer, hits);
            foreach (RaycastResult hit in hits)
            {
                DropZone          zone          = hit.gameObject.GetComponent <DropZone>();
                DropZoneExtention zoneExtention = hit.gameObject.GetComponent <DropZoneExtention>();

                if (zoneExtention != null)
                {
                    return(zoneExtention.zone);
                }

                if (zone != null)
                {
                    return(zone);
                }
            }
            return(null);
        }
Exemple #3
0
 public void AddDraggableToZone(DropZone zone)
 {
     zone.OnDraggingExit();
     currentZone = zone;
     transform.SetParent(zone.transform);
     transform.SetAsLastSibling();
     zone.OnDrop(this);
 }
Exemple #4
0
        private void CreateComponents(GameObject prefab, IEnumerable <object> components, DropZone zone, Vector3 position)
        {
            foreach (var c in components)
            {
                var component = Instantiate(prefab, zone.transform);

                component.GetComponent <RectTransform>().anchoredPosition = position;

                var componentUI = component.GetComponent <SpellComponentUIController>();

                if (c is string)
                {
                    componentUI.nameText.text = (string)c;
                }
                else if (c is SpellEffect)
                {
                    componentUI.nameText.text = ((SpellEffect)c).effectName;
                    componentUI.logoText.text = ((SpellEffect)c).effectName.Substring(0, 2).ToUpper();
                }

                var draggable = component.GetComponent <Draggable>();
                draggable.data = c;
            }
        }
Exemple #5
0
 private void CreateComponent(GameObject prefab, object component, DropZone zone, Vector3 position)
 {
     CreateComponents(prefab, new List <object> {
         component
     }, zone, position);
 }
Exemple #6
0
        // Start is called before the first frame update
        void Start()
        {
            currentZone = transform.GetComponentInParent <DropZone>();

            Debug.Log(transform.parent);
        }