private void OnBeginDrag(BaseEventData arg0)
    {
        SetTween(false);
        _canDrag = true;
        PointerEventData ped = arg0 as PointerEventData;

        if (ped == null)
        {
            Debug.LogError(string.Format("ped == null"));
            _canDrag = false;
            return;
        }
        if (ped.pointerId < -1 || ped.pointerId > 1)
        {//不允许鼠标中键和右键响应,不允许移动端多点触控
            Debug.LogError(string.Format("ped.pointerId not valid.ped.pointerId={0}", ped.pointerId));
            _canDrag = false;
            return;
        }
        _curStroke = DrawLetterManager.Instance.GetStroke(charactor, curIdx);
        if (_curStroke == null)
        {
            Debug.LogError(string.Format("_curMeshInfo == null"));
            _canDrag = false;
            return;
        }
        if (_curStroke.curvePoints == null || _curStroke.curvePoints.Count <= 1)
        {
            return;
        }
        _curCurvePointIdx = 0;
        Vector2 localPoint = Vector2.zero;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(transform.GetComponent <RectTransform>(), ped.position, ped.pressEventCamera, out localPoint);
        float distance = Vector2.Distance(localPoint, _curStroke.curvePoints[_curCurvePointIdx]);

        if (distance > BeginDragDistanceThreshold)
        {
            Debug.LogWarning(string.Format("T={0};CurvePoint={1};distance={2}", localPoint, _curStroke.curvePoints[_curCurvePointIdx], distance));
            _canDrag = false;
            return;
        }
        UIStroke[] arr = meshRootD.GetComponentsInChildren <UIStroke>();
        for (int i = 0; i < arr.Length; ++i)
        {
            if (arr[i].gameObject.name.Trim() == curIdx.ToString())
            {
                curStroke = arr[i];
                break;
            }
        }
        _pointS = _curStroke.curvePoints[0];
        _pointE = _curStroke.curvePoints[_curStroke.curvePoints.Count - 1];
    }
Exemple #2
0
    internal void Init(string charactor, UIStroke tplStroke, bool isDraw = false)
    {
        Dictionary <string, Letter> tmpDict = DrawLetterManager.Instance.LetterDict;

        if (tmpDict == null)
        {
            Debug.LogError(string.Format("tmpDict null"));
            return;
        }
        if (!tmpDict.ContainsKey(charactor))
        {
            Debug.LogError(string.Format("不包含字符[{0}]", charactor));
            return;
        }
        Letter tmpLetter = tmpDict[charactor];

        if (tmpLetter == null)
        {
            Debug.LogError(string.Format("tmpLetter null"));
            return;
        }
        List <Stroke> tmpStrokList = tmpLetter.StrokeList;

        for (int i = 0; i < tmpStrokList.Count; i++)
        {
            Stroke tmpStrok = tmpStrokList[i];
            if (tmpStrok == null)
            {
                continue;
            }
            UIStroke stk = GameObject.Instantiate <UIStroke>(tplStroke, transform);
            stk.gameObject.SetActive(true);
            stk.gameObject.name = tmpStrok.index.ToString();
            stk.InitData(tmpStrok.nodeList.ToArray(), tmpStrok.width, tmpStrok.smooth, tmpStrok.isClose);
            if (isDraw)
            {
                stk.color = new Color(1, 0.6353f, 0, 1f);
                stk.UpdatePercent(0);
            }
            else
            {
                stk.color = Color.green;
                stk.UpdatePercent(1);
#if UNITY_EDITOR
                _curvePoints = JsonMapper.ToObject <List <Vector2> >(stk.GetStrokeData());
                _vertices    = JsonMapper.ToObject <List <Vector3> >(stk.GetStrokeVertices());
#endif
            }
            DrawLetterManager.Instance.SetCurvePoints(charactor, tmpStrok.index, stk.GetStrokeData());
        }
    }
Exemple #3
0
 public bool BuildMesh()
 {
     if (_nodeList.Count <= 0)
     {
         Debug.LogError("至少得有一个结点");
         return(false);
     }
     NormalizeNodeList();
     if (_uiStroke == null)
     {
         _uiStroke = GetComponent <UIStroke>();
     }
     _uiStroke.InitData(_nodeList.ToArray(), width, smooth, isClose);
     _uiStroke.UpdatePercent(1);
     _curvePoints = JsonMapper.ToObject <List <Vector2> >(_uiStroke.GetStrokeData());
     UpdateData();
     return(true);
 }
    private void Awake()
    {
        DrawLetterManager.Instance.RegisterExporter();

        meshRoot  = transform.Find("MeshRoot").GetComponent <MeshRoot>();
        meshRootD = transform.Find("MeshRootD").GetComponent <MeshRoot>();

        tplStroke = transform.Find("tplStroke").GetComponent <UIStroke>();
        tplStroke.gameObject.SetActive(false);

        btnDraw = transform.Find("btnDraw").GetComponent <Button>();
        btnDraw.onClick.AddListener(OnClickDraw);
        imgTouchPad = transform.Find("imgTouchPad").GetComponent <Image>();
        EventTrigger et = imgTouchPad.gameObject.AddComponent <EventTrigger>();

        //
        EventTrigger.Entry entry = null;
        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.BeginDrag;
        entry.callback.AddListener(OnBeginDrag);
        et.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.Drag;
        entry.callback.AddListener(OnDrag);
        et.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.EndDrag;
        entry.callback.AddListener(OnEndDrag);
        et.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        entry.callback.AddListener(OnPointerClick);
        et.triggers.Add(entry);
    }
Exemple #5
0
 private void OnEnable()
 {
     _uiStroke = GetComponent <UIStroke>();
     _tplApple = transform.root.Find("tplApple").GetComponent <RectTransform>();
 }