public void SetGameObj(GameObject gameObj, string arg)
    {
        if (dGameObjects.ContainsKey(gameObj.name))
        {
            dGameObjects[gameObj.name] = gameObj;
        }
        else
        {
            dGameObjects.Add(gameObj.name, gameObj);
        }
        this.gameObj     = gameObj;
        AGameBase.strArg = arg;
        var r = this.gameObj.AddComponent <UEmitMessager>();

        curGame    = this;
        r.gameBase = this;
        r.OnRegistAction((msg) =>
        {
            onReceiveMsg?.Invoke(msg);
        });

        InitComponents();
    }
Exemple #2
0
    public void Update()
    {
        if (graphic == null)
        {
            return;
        }
        if (!graphic.raycastTarget)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (disableDraging)
            {
                return;
            }
            if (EventSystem.current.IsPointerOverGameObject(0))
            {
                if (EventSystem.current.currentSelectedGameObject != gameObject)
                {
                    return;
                }
            }

            if (!RectTransformUtility.RectangleContainsScreenPoint(rectTransform, mouseWorldPoint))
            {
                lastPosition = Vector3.zero;
                return;
            }
            lastPosition = Input.mousePosition;
            if (lastPosition.Equals(Vector3.zero))
            {
                lastPosition = new Vector3(0.001f, 0);
            }
            if (!bDraging)
            {
                bDraging = true;
                if (onDragBegin != null)
                {
                    onDragBegin();
                }

                if (AGameBase.strArg == "teacher")
                {
                    if (!DontSyncDrag)
                    {
                        AGameBase.SendMessageToUnityReceiver(MessageHeadDragBegin + ":" + gameObject.name);
                    }
                }
            }
            return;
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (EventSystem.current.IsPointerOverGameObject(0))
            {
                if (EventSystem.current.currentSelectedGameObject != gameObject)
                {
                    return;
                }
            }
            if (!RectTransformUtility.RectangleContainsScreenPoint(rectTransform, mouseWorldPoint))
            {
                return;
            }
            if (lastPosition.Equals(Vector3.zero))
            {
                if (onDragDrop != null)
                {
                    onDragDrop();
                }
                if (AGameBase.strArg == "teacher")
                {
                    if (!DontSyncDrag)
                    {
                        AGameBase.SendMessageToUnityReceiver(MessageHeadDragDrop + ":" + gameObject.name);
                    }
                }
            }
            else
            {
                if (onDragEnd != null)
                {
                    onDragEnd();
                }
                if (AGameBase.strArg == "teacher")
                {
                    if (!DontSyncDrag)
                    {
                        AGameBase.SendMessageToUnityReceiver(MessageHeadDragEnd + ":" + gameObject.name);
                    }
                }
            }
            StartCoroutine(DelayCancel());
            lastPosition = Vector3.zero;
            return;
        }
        if (Input.GetMouseButton(0))
        {
            if (disableDraging)
            {
                return;
            }
            if (lastPosition.Equals(Vector3.zero))
            {
                return;
            }
            if (onDraging != null)
            {
                onDraging();
            }
            else
            {
                var p = transform.position;
                p.x += (Input.mousePosition.x - lastPosition.x) / (dragcamera == null ? 1 : canvas.scaleFactor);
                p.y += (Input.mousePosition.y - lastPosition.y) / (dragcamera == null ? 1 : canvas.scaleFactor);
                transform.position = p;

                lastPosition = Input.mousePosition;
            }

            if (AGameBase.strArg == "teacher")
            {
                if (!DontSyncDrag)
                {
                    AGameBase.SendMessageToUnityReceiver(MessageHeadDraging + ":" + gameObject.name + ":" + (int)transform.localPosition.x + "," + (int)transform.localPosition.y);
                }
            }
        }
        else
        {
            if (disableDraging)
            {
                return;
            }
            if (!bDraging)
            {
                return;
            }
            if (onDragDrop != null)
            {
                onDragDrop();
            }
            if (onDragEnd != null)
            {
                onDragEnd();
            }
            lastPosition = Vector3.zero;
            bDraging     = false;
            StartCoroutine(DelayCancel());
        }
    }
    private IEnumerator DelaySendMessage(string message, float delay)
    {
        yield return(new WaitForSeconds(delay));

        AGameBase.SendMessageToUnityReceiver(message);
    }