コード例 #1
0
    // Use this for initialization
    void Start()
    {
        m_DrawPointState = DrawPointState.First;

        m_LineGroup = GameObject.Find("lineGroup");


        m_PointRadius = m_PointSpritePrefab.GetComponent <CircleCollider2D>().radius;
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        int inputType = 0;

        //platform specific
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            inputType |= 1;
        }
#elif UNITY_STANDALONE
        if (Input.GetMouseButtonDown(0))
        {
            inputType |= 1;
        }
#elif UNITY_IPHONE
        if (1 == Input.touchCount)
        {
            inputType |= 1;
        }
#elif UNITY_ANDROID
        if (1 == Input.touchCount)
        {
            inputType |= 1;
        }
#endif
        Vector3 tmpPoint = new Vector3();

        switch (inputType)
        {
        case 0:
            return;

        case 1:
            //platform specific
#if UNITY_EDITOR
            tmpPoint = Input.mousePosition;
            break;
#elif UNITY_STANDALONE
            tmpPoint = Input.mousePosition;
            break;
#elif UNITY_IPHONE
            tmpPoint = Input.touches[0].position;
            break;
#elif UNITY_ANDROID
            tmpPoint = Input.touches[0].position;
            break;
#endif
        default:
            break;
        }
        tmpPoint   = Camera.main.ScreenToWorldPoint(tmpPoint);
        tmpPoint.z = m_LineGroup.transform.position.z;

        switch (m_DrawPointState)
        {
        case DrawPointState.First:
        {
            m_FisrtPointPos  = tmpPoint;
            m_DrawPointState = DrawPointState.Second;
            break;
        }

        case DrawPointState.Second:
        {
            m_SecondPointPos = tmpPoint;
            m_DrawPointState = DrawPointState.Finished;
            DrawPoints();
            break;
        }

        case DrawPointState.Finished:
        {
            this.ClearPreviousPoints();
            m_FisrtPointPos  = tmpPoint;
            m_DrawPointState = DrawPointState.Second;
            break;
        }

        default:
            break;
        }
    }