美文网首页
unity实现画板功能

unity实现画板功能

作者: 漂泊的树叶hx | 来源:发表于2018-03-13 18:47 被阅读0次

如题、公司想做早教方面的小游戏、文档中有连线需求

找了几个帖子、直接复制粘贴、运行、不是自己想要的功能、于是尝试改、

逻辑看的我头大、一个List<vector3> 就搞定的逻辑 

非要写vector3[]

然后又自己去封装数组的自增

public class DrawLine : MonoBehaviour {

    public Shader shader;

    private static Material m;

    private GameObject g;

    private List spppp;

    private GUIStyle labelStyle;

    private GUIStyle linkStyle;

    List> linesPoint;

    void Start () {

        labelStyle = new GUIStyle();

        labelStyle.normal.textColor = Color.black;

        linkStyle = new GUIStyle();

        linkStyle.normal.textColor = Color.blue;

        spppp = new List ();

        m = new Material(shader);

        g = new GameObject("g");

        linesPoint = new List> ();

    }

    /** Replace the Update function with this one for a click&drag drawing option */

    void Update() {

        Vector3 e;

        if(Input.GetMouseButtonDown(0)) {

            spppp = new List ();

            List points = new List ();

            linesPoint.Add (points);

        }

        if(Input.GetMouseButton(0)) {

            spppp.Add (GetNewPoint ());

            linesPoint [linesPoint.Count-1].Add (GetNewPoint());

        }

        if(Input.GetMouseButtonUp(0)) {

        }

    }

    Vector3 GetNewPoint() {

        return g.transform.InverseTransformPoint(

            Camera.main.ScreenToWorldPoint(

                new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z * -1.0f)

            )

        );

    }

    void OnPostRender() {

        m.SetPass(0);

        GL.PushMatrix();

        GL.MultMatrix(g.transform.transform.localToWorldMatrix);

        GL.Begin( GL.LINES );

        GL.Color( new Color(1,1,1,1) );

        for (int i = 0; i < spppp.Count-2; i++) {

            GL.Vertex3 (spppp [i].x, spppp [i].y, spppp [i].z);

            GL.Vertex3 (spppp [i+1].x, spppp [i+1].y, spppp [i+1].z);

        }

        for (int i = 0; i < linesPoint.Count; i++) {

            for (int j = 0; j < linesPoint[i].Count-1; j++) {

                GL.Vertex3 (linesPoint [i][j].x, linesPoint [i][j].y, linesPoint [i][j].z);

                GL.Vertex3 (linesPoint [i][j+1].x, linesPoint [i][j+1].y, linesPoint [i][j+1].z);

                //GL.Vertex3 (spppp [j+1].x, spppp [j+1].y, spppp [j+1].z);

            }

        }

        GL.End();

        GL.PopMatrix();

    }

}

相关文章

  • unity实现画板功能

    如题、公司想做早教方面的小游戏、文档中有连线需求 找了几个帖子、直接复制粘贴、运行、不是自己想要的功能、于是尝试改...

  • ios开发实现画板功能

    ios开发实现画板功能 ios开发实现画板功能

  • 画画板功能实现

    1 获取一张背景图片 BitmpFactory.decodeResource 2 创建一个副本 3 设置image...

  • 画板功能的实现

    最近项目中用到了一个客户签字的功能,具体步骤就是客户签字确认,App把客户的签字生成一张PNG图片上传到服务器,服...

  • android实现画板功能

    这两天闲来无事做了一个简易的画板程序,和大家分享一下。效果图: 这是一个灰常简单的画板,不过麻雀虽小,五脏俱全: ...

  • iOS 画板--UIBezierPath和CAShapeLaye

    iOS 画板--UIBezierPath和CAShapeLayer实现 最近在做的项目中,用到画板的功能,现在项目...

  • android各种效果库

    可能是最优雅的切换布局的方法 动态切换布局控件android 实现画板功能 本例详细分析了一个画板功能的实现过程,...

  • 02Canvas 画板

    1.功能描述 实现画画功能,并可切换画笔颜色、细条粗细。可保存、清空画板。 2.思路 创建画板——》监听鼠标(触屏...

  • [Unity]使用Unity开发即时战略游戏(类似红警)

    [Unity]技术学习路线图(长期更新) Unity开发版本 Unity 5.1.2 开发语言 C# 实现功能 视...

  • ios开发实现画板功能

    最近看了一些网上的画板demo,这些demo的实现方式基本上是使用CGContextRef或者UIBezierPa...

网友评论

      本文标题:unity实现画板功能

      本文链接:https://www.haomeiwen.com/subject/toftqftx.html