基于unity的图元绘画系统
图元绘画系统技术性简介
本期期末大作业图元绘画系统简介
什么是系统
先谈绘画系统,要想说清绘画系统,那就要理清2个概念,首先是绘画,但是我不需要再次阐述绘画的内涵因为我们的互动媒体课已经给出了定义和要求,那么我就要仔细的说一下系统以及系统在绘画领域中,即绘画系统到底满足什么条件,能够达到什么样的功能。
“系统是由相互作用相互依赖的若干组成部分结合而成的,具有特定功能的有机整体,而且这个有机整体又是它从属的更大系统的组成部分。”这是钱学森先生给出的定义,我们不妨取它作为标准,再给出我的的一点点润色,依我看来,一个系统称之为系统在软件和IT的领域是因为其具有2个特点,第一个是泛用性,第二个是可以与其他的系统(体系)做交流和沟通,换而言之具有一种可移植性和接受外界输入,并且能够向外界输出的功能。
那么我们应该如何界定该系统可以做到的功能呢?那么我认为最重要的部分就是可以与外界进行信息交流,包括保存,接受输入,这是成为系统的关键,然后,系统内部需要实现泛用的关于绘画的功能,然后可以称为一个系统。
那么,我的系统设计内核就是如此,以下请看我的设计。
我的设计
这就是主界面全部子状态栏拉开的状态,可见有4个子状态栏,分别控制笔刷的状态,图元的选择,每个图元的粒子脚本设定,和保存设定。
笔刷
我们先看看笔刷的状态栏。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Michsky.UI.ModernUIPack;
using UnityEngine.EventSystems;
public class pen : MonoBehaviour {
public static Color32 pen_color = new Color32(255,255,255,255);
public Image pen_shape;
static Quaternion r;
public RectTransform rt = new RectTransform();
static float d = 0.1f;
static bool series = false;
public GameObject pic;
public SwitchAnim sa;
public GameObject drawlayer;
Coroutine c;
// Use this for initialization
void Start () {
pen_color = new Color32(170, 170, 120, 255);
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)&&GetOverUI(gameObject,"uitag")==null)
{
if (!series)
{
//Debug.Log("drawflow");
if(c!=null) StopCoroutine(c);
c = StartCoroutine(draw());
}
else
{
//Debug.Log("drawsingle");
drawpic();
}
}
if (Input.GetMouseButtonUp(2))
{
//Debug.Log("drawflow_stop");
StopCoroutine(c);
}
if (Input.GetKeyDown(KeyCode.D))
{
GameObject pic = GetOverUI(gameObject, "pic");
if (pic != null)
{
Destroy(pic);
}
}
}
IEnumerator draw()
{
while (true)
{
drawpic();
yield return new WaitForSeconds(d);
}
}
void drawpic()
{
GameObject ins = Instantiate(pic, Input.mousePosition, r);
ins.transform.SetParent(gameObject.transform);
ins.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
RectTransform insrt = ins.GetComponent<RectTransform>();
insrt.SetPositionAndRotation(new Vector3(0,0,936*gameObject.transform.localScale.z), r);
insrt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, Input.mousePosition.x-rt.rect.width/2,rt.rect.width);
insrt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom,Input.mousePosition.y-rt.rect.height/2,rt.rect.height);
insrt.rotation = r;
ins.transform.SetParent(drawlayer.transform);
Image i = ins.GetComponent<Image>();
i.sprite = pen_shape.sprite;
i.color = pen_color;
ins.AddComponent<picmovement>();
}
public GameObject GetOverUI(GameObject canvas,string tag)
{
PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
pointerEventData.position = Input.mousePosition;
GraphicRaycaster gr = canvas.GetComponent<GraphicRaycaster>();
List<RaycastResult> results = new List<RaycastResult>();
gr.Raycast(pointerEventData, results);
if (results.Count != 0)
{
for (int i = 0; i < results.Count; i++)
{
if (results[i].gameObject.tag == tag)
{
return results[i].gameObject;
}
}
}
return null;
}
public void setrotate(InputField input)
{
if (input.text.Length > 0)
{
r = Quaternion.Euler(new Vector3(0, 0, float.Parse(input.text)));
rt.rotation = Quaternion.Euler(new Vector3(0, 0, float.Parse(input.text)));
Debug.Log(float.Parse(input.tex