Example #1
0
        void snapItemMouse()
        {
            element.pos = control.hit.point;
            // Debug.Log(control.hit.point.x+"");
            element.status = "air";
            var cols = Physics.OverlapSphere(element.pos, snapRadius, ~0);
            var arr  = U.filter <Container>(cols);

            if (arr.Length > 0)
            {
                Container c = arr[0];
                foreach (var e in arr)
                {
                    if (element.dis(e) < element.dis(c) &&
                        c.element == null)
                    {
                        c = e;
                    }
                }
                element.container       = c;
                element.pos             = c.pos;
                element.tra.eulerAngles = element.eulerAngles + c.tra.eulerAngles;
            }
        }
Example #2
0
 void Update()
 {
     // time record
     timeRecord.text = Mathf.Floor(Time.realtimeSinceStartup - timeStart) + "";
     // main `Element`s drag and drop
     if (!isLocked)
     {
         if (control.isHover)
         {
             var e = control.hit.collider.GetComponent <Element>();
             if (control.isDown && e)
             {
                 if (e.container)
                 {
                     e.container.element          = null;
                     e.container.collider.enabled = true;
                     e.container.gameObject.SetActive(true);
                 }
                 e.collider.enabled = false;
                 element            = e;
             }
         }
         if (element)
         {
             // control.hover(~layerElement.value);
             if (control.isHold)
             {
                 element.pos    = control.hit.point;
                 element.status = "air";
                 var cols = Physics.OverlapSphere(element.pos, 2, ~0);
                 var arr  = U.filter <Container>(cols);
                 // arr=filter(arr);
                 if (arr.Length > 0)
                 {
                     Container c = arr[0];
                     foreach (var e in arr)
                     {
                         if (element.dis(e) < element.dis(c) &&
                             c.element == null)
                         {
                             c = e;
                         }
                     }
                     element.container = c;
                     element.pos       = c.pos;
                     // element.tra.eulerAngles=element.eulerAngles+c.tra.eulerAngles;
                 }
                 //end
             }
             if (control.isUp && element.container)
             {
                 element.pos = element.container.pos;
                 element.container.element          = element;
                 element.container.collider.enabled = false;
                 element.container.gameObject.SetActive(false);
                 element.collider.enabled = true;
                 element = null;
                 refresh = true;
             }
         }
         if (refresh)
         {
             check();
         }
         refresh = false;
     }
 }