12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Paint : MonoBehaviour
- {
- public GameObject trailPrefab;
- private TrailRenderer thisTrail;
- private Vector3 startPos;
- private Plane objPlane;
- private Vector3 TeacherPos;
- [SerializeField]
- private bool isStart = false;
- void Start()
- {
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_REFRESH_LINE_TARGET_POS_DATA, RefreshData);
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_DRAW_START, DrawStart);
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_DRAW_END, DrawEnd);
- isStart = false;
- }
- private void OnDestroy()
- {
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_REFRESH_LINE_TARGET_POS_DATA, RefreshData);
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_DRAW_START, DrawStart);
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_DRAW_END, DrawEnd);
- }
- void DrawStart(System.Object o)
- {
- StartCoroutine(_DrawStart(o));
- }
- IEnumerator _DrawStart(System.Object o)
- {
- yield return new WaitForEndOfFrame();
- DrawData data = (DrawData)o;
- startPos = DrawingManager._instance.DrawPoint(); // 获取射线点
- GameObject g = Instantiate(trailPrefab, startPos, Quaternion.identity);
- // 加入绘制Stack
- DrawListManager._instance.AddBrush(g);
- thisTrail = g.GetComponent<TrailRenderer>();
- thisTrail.startColor = data.GetColor();
- thisTrail.endColor = data.GetColor();
- // thisTrail.widthMultiplier = data.size;
- isStart = true;
- }
- void DrawEnd(System.Object o)
- {
- isStart = false;
- }
- private void RefreshData(System.Object data)
- {
- if (GamePlayerData.Instance.room_data.IsReconnectOwner())
- {
- return;//如果是老师的话不执行
- }
- TeacherPos = (Vector3)data;
- }
- // Update is called once per frame
- void Update()
- {
- if (isStart)
- {
- Vector3 v;
- if (GamePlayerData.Instance.room_data.IsReconnectOwner())
- {
- v = DrawingManager.Instance.DrawPoint();
- }
- else
- {
- v = TeacherPos;
- }
- if (thisTrail)
- {
- thisTrail.transform.position = v;
- }
-
- }
- }
- }
|