• 大小: 4.08MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-08
  • 语言: 其他
  • 标签: unity  签字  画笔  

资源简介

试过可用unity2017 和5.6执行
可以在选项进行改变颜色 和条形选项改变笔的粗细
可以取消清除

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Mspaint : MonoBehaviour 
{

    private Color paintColor = Color.red;
private float paintSize = 0.3F;
private LineRenderer currentLine;
private List positions=new List();
    private Listject> lines = new Listject>();
private bool isMouseDown = false;
private Vector3 lastMousePostion = Vector3.zero;
private float lineDistance = 0.1F;


    public Material m_LineMaterial;
    public Text m_SizeValue;

void Update()
    {
if (Input.GetMouseButtonDown (0))
        {
Gameobject go = new Gameobject ();
           
go.transform.SetParent (this.transform);
currentLine = go.AddComponent ();
            currentLine.material = m_LineMaterial;
currentLine.startWidth = paintSize;
currentLine.endWidth = paintSize;
currentLine.startColor = paintColor;
currentLine.endColor = paintColor;
currentLine.numCornerVertices = 10;
currentLine.numCapVertices = 10;
Vector3 position = GetMousePoint ();
AddPosition (position);
isMouseDown = true;
lineDistance += 0.1F;
            lines.Add(go);
}
if (isMouseDown) 
        {
Vector3 position = GetMousePoint ();
            if (Vector3.Distance(position lastMousePostion) > 0.05F)
            {
                AddPosition(position);
            }
}

if (Input.GetMouseButtonUp (0)) 
        {
currentLine = null;
positions.Clear ();
isMouseDown = false;
}
}

    /// 
    /// 添加要的画线包含的点
    /// 

    /// 
void AddPosition(Vector3 position)
    {
position.z -= lineDistance;
positions.Add (position); 
currentLine.positionCount = positions.Count;
currentLine.SetPositions (positions.ToArray ());
lastMousePostion = position;
}

    /// 
    /// 将鼠标的屏幕坐标投影到世界空间中
    /// 

    /// 
Vector3 GetMousePoint()
    {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast (ray out hit);
if (isCollider) {
return hit.point;
}
return Vector3.zero;
}

#region 设置线条的颜色及粗细
public void OnRedColorChanged(bool isOn )
    {
if (isOn)
        {
paintColor = Color.red;
}
}
public void OnGreenColorChanged(bool isOn)
    {
if (isOn) 
        {
paintColor = Color.green;
}
}
public void OnBlueColorChanged(bool isOn)
    {
if (isOn)
        {
paintColor = Color.blue;
}
}

    public void OnSizeChanged(float value)
    {
        paintSize = value;
        m_SizeValue.text = value.ToString();
    }

    public void OnClearBtnClick()
    {
        for (int i = 0; i < lines.Count; i++)
        {
            Destroy(lines[i]);
        }
        lines.Clear();
        lineDistance = 0.1F;
    }

#endregion
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10351  2020-03-31 15:52  LineRenderer\Assembly-CSharp.csproj

     文件       5180  2017-12-23 18:03  LineRenderer\Assets\EmptyMaterial.mat

     文件        207  2017-12-23 17:34  LineRenderer\Assets\EmptyMaterial.mat.meta

     文件      66264  2017-12-23 20:00  LineRenderer\Assets\Scenes\Main.unity

     文件        174  2017-12-23 17:22  LineRenderer\Assets\Scenes\Main.unity.meta

     文件        191  2017-12-23 17:22  LineRenderer\Assets\Scenes.meta

     文件       3072  2017-12-23 19:51  LineRenderer\Assets\scripts\Mspaint.cs

     文件        262  2017-12-23 17:26  LineRenderer\Assets\scripts\Mspaint.cs.meta

     文件        191  2017-12-23 17:27  LineRenderer\Assets\scripts.meta

    I.A....      4116  2017-12-23 17:20  LineRenderer\Library\AnnotationManager

    I.A....   4028024  2020-03-31 15:52  LineRenderer\Library\assetDatabase3

    I.A....         9  2020-03-31 15:52  LineRenderer\Library\AssetImportState

    I.A....      4756  2017-12-23 20:01  LineRenderer\Library\AssetServerCacheV3

    I.A....     14336  2017-12-23 17:27  LineRenderer\Library\AssetVersioning.db

    I.A....         0  2017-12-23 17:20  LineRenderer\Library\BuildPlayer.prefs

    I.A....      4152  2017-12-23 17:20  LineRenderer\Library\BuildSettings.asset

    I.A....     14428  2017-12-23 20:01  LineRenderer\Library\CurrentLayout.dwlt

    I.A....        52  2020-03-31 15:52  LineRenderer\Library\EditorInstance.json

    I.A....      4384  2017-12-23 19:07  LineRenderer\Library\EditorUserBuildSettings.asset

    I.A....      4152  2017-12-23 17:20  LineRenderer\Library\EditorUserSettings.asset

    I.A....      4152  2017-12-23 18:06  LineRenderer\Library\expandedItems

    I.A....      4152  2017-12-23 19:51  LineRenderer\Library\InspectorExpandedItems.asset

    I.A....     23896  2017-12-23 20:01  LineRenderer\Library\LastBuild.buildreport

    I.A....        74  2017-12-23 20:01  LineRenderer\Library\LastSceneManagerSetup.txt

    I.A....        65  2017-12-23 17:20  LineRenderer\Library\LibraryFormatVersion.txt

    I.A....      4253  2020-03-31 15:52  LineRenderer\Library\metadata\00\00000000000000001000000000000000

    I.A....       581  2020-03-31 15:52  LineRenderer\Library\metadata\00\00000000000000001000000000000000.info

    I.A....      4232  2020-03-31 15:51  LineRenderer\Library\metadata\00\00000000000000002000000000000000

    I.A....       577  2020-03-31 15:51  LineRenderer\Library\metadata\00\00000000000000002000000000000000.info

    I.A....      4232  2020-03-31 15:51  LineRenderer\Library\metadata\00\00000000000000003000000000000000

............此处省略1344个文件信息

评论

共有 条评论