예제 #1
0
    public void GumClear(Collision2D coll, GameObject go)
    {
        Vector2        touchPenPos  = go.transform.localPosition;
        LineVertsInfo  m_lineVerts  = coll.gameObject.GetComponent <LineVertsInfo>();
        LineRender     m_lineRender = gameObject.GetComponent <LineRender>();
        bool           isStart      = true;
        bool           isEnd        = false;
        int            startIndex   = 0;
        int            endIndex     = m_lineVerts.LineVerts.Count;
        List <Vector2> startLine    = new List <Vector2>();
        List <Vector2> endLine      = new List <Vector2>();

        for (int i = 0; i < m_lineVerts.LineVerts.Count; i++)
        {
            float x = m_lineVerts.LineVerts[i].x - touchPenPos.x;
            float y = m_lineVerts.LineVerts[i].y - touchPenPos.y;
            x = x * x;
            y = y * y;
            if ((x + y) < mLogicHandle.GumAmount)
            {
                if (isStart)
                {
                    isStart    = false;
                    startIndex = i;
                }
                else
                {
                    endIndex = i;
                }
            }
            else if (endIndex > 0)
            {
                isEnd = true;
            }
            if (isStart)
            {
                startLine.Add(m_lineVerts.LineVerts[i]);
            }
            else if (isEnd)
            {
                endLine.Add(m_lineVerts.LineVerts[i]);
            }
        }
        if (startLine.Count > 1)
        {
            m_lineRender.NewVerts = startLine;
            m_lineRender.CreateLineGo();
        }
        if (endLine.Count > 1)
        {
            m_lineRender.NewVerts = endLine;
            m_lineRender.CreateLineGo();
        }
        Destroy(coll.gameObject);
    }
예제 #2
0
    public void setLinePosition(LogicHandle.Direction direct, GameObject lineGo)
    {
        int           lineVertsCount = lineGo.GetComponent <LineVertsInfo>().LineVerts.Count;
        LineVertsInfo lineVertInfo   = lineGo.GetComponent <LineVertsInfo>();
        LineRenderer  lineRenderer   = lineGo.GetComponent <LineRenderer>();

        switch (direct)
        {
        case LogicHandle.Direction.Up:
            for (int i = 0; i < lineVertsCount; i++)
            {
                lineVertInfo.LineVerts[i] += new Vector2(0, mLogicHandle.moveAmount);
                lineRenderer.SetPosition(i, lineGo.GetComponent <LineVertsInfo>().LineVerts[i]);
            }
            break;

        case LogicHandle.Direction.Down:
            for (int i = 0; i < lineVertsCount; i++)
            {
                lineVertInfo.LineVerts[i] -= new Vector2(0, mLogicHandle.moveAmount);
                lineRenderer.SetPosition(i, lineGo.GetComponent <LineVertsInfo>().LineVerts[i]);
            }
            break;

        case LogicHandle.Direction.Left:
            for (int i = 0; i < lineVertsCount; i++)
            {
                lineVertInfo.LineVerts[i] -= new Vector2(mLogicHandle.moveAmount, 0);
                lineRenderer.SetPosition(i, lineGo.GetComponent <LineVertsInfo>().LineVerts[i]);
            }
            break;

        case LogicHandle.Direction.Right:
            for (int i = 0; i < lineVertsCount; i++)
            {
                lineVertInfo.LineVerts[i] += new Vector2(mLogicHandle.moveAmount, 0);
                lineRenderer.SetPosition(i, lineGo.GetComponent <LineVertsInfo>().LineVerts[i]);
            }
            break;
        }

        lineRenderer.SetPosition(lineVertsCount, lineVertInfo.LineVerts[lineVertsCount - 1]);
        lineRenderer.SetPosition(lineVertsCount + 1, lineVertInfo.LineVerts[lineVertsCount - 1]);
        int pointCount = lineVertInfo.LineVerts.Count;

        Vector2[] verts = new Vector2[pointCount];
        for (int i = 0; i < pointCount; i++)
        {
            verts[i] = lineVertInfo.LineVerts[i];
        }
        lineGo.GetComponent <EdgeCollider2D>().points = verts;
    }
예제 #3
0
    void CreateLineGameObject()
    {
        m_LineGo                  = (GameObject)GameObject.Instantiate(go);
        m_LineGo.name             = "line";
        m_LineGo.transform.parent = m_LineBox.transform;
        m_lineRenderer            = m_LineGo.AddComponent <LineRenderer>();
        m_lineVertsInfo           = m_LineGo.AddComponent <LineVertsInfo>();
        m_lineRenderer.SetWidth(.2f, .2f);
        m_lineRenderer.SetColors(Color.white, Color.white);
        m_lineRenderer.material       = m_material;
        m_lineRenderer.material.color = new Color(1, 1, 0, .25f);

        m_EdgeCollider = m_LineGo.AddComponent <EdgeCollider2D>();
    }