Ejemplo n.º 1
0
    IEnumerator OnMouseUp()
    {
        yield return(new WaitForEndOfFrame());

        if (DeployUnitMenu.Instance.IsClicked())
        {
            yield break;
        }

        CameraManager.SetTouchActive(true);

        DeployUnitDisplayHelper.SetCurrent(ArrowGroup, transform, ShipWrapRadius);

        if (DeployUnitMenu.Instance.CurrentFollowTarget != transform)
        {
            DeployUnitMenu.Instance.CurrentFollowTarget = transform;
        }

        if (State == DeployState.OnPlaced)
        {
            bool condition;

#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
            condition = Input.mousePosition == LastTouchDownPosition_;
#else
            float delta_time = Input.GetTouch(0).deltaTime;
            Debugger.Log("touch delta_time :" + delta_time);
            condition = Input.GetTouch(0).deltaPosition.sqrMagnitude < 100f && Input.GetTouch(0).deltaTime < 0.5f;
#endif
            if (!condition)
            {
                yield break;
            }

            //当处于“布阵完成”时,且是点击操作(即按下与弹起是同一点)鼠标弹起被认为确认进入“准备布阵”状态
            State = DeployState.OnPrepare;
        }
        else if (State == DeployState.OnSnapping)
        {
            //当处于“正在布阵”时,鼠标弹起被认为确认进入“完成布阵”状态
            State = DeployState.OnPlaced;

            //此时应当检查是否有交叉,如有,则返回上一个有效位置
            if (Intersecting_ > 0)
            {
                CachedTransform_.position = LastValidPosition_;
                Intersecting_             = 0;
            }
        }
    }
Ejemplo n.º 2
0
    private SnappingUnits EquipSnappingComponent(GameObject attachTarget, float shipWrapRadius)
    {
        //添加布阵格子组件,以供自动排布
        Snapping_ = attachTarget.AddComponent <SnappingUnits>();

        //每个可拖拽单元都受到同一个RectGrid的约束
        Snapping_.Grid           = DeploySceneManager.Instance.PlayerGridDrawer.GridInstance;
        Snapping_.ShipWrapRadius = shipWrapRadius;
        Snapping_.ShipIocnName   = IconName_;
        Snapping_.ArrowGroup     = attachTarget.AddComponent <DeployUnitDisplayHelper>();
        DeployUnitDisplayHelper.SetCurrent(Snapping_.ArrowGroup, attachTarget.transform, shipWrapRadius);
        Snapping_.RebackCursorCallback += delegate { OnDragEnd(); };

        return(Snapping_);
    }