IEnumerator LoadCoroutine() { for (int i = 0; i < savedStrokes.Count; i++) { BrushInfo info = GetBrushInfoByName(savedStrokes[i].BrushInfoName); for (int j = 0; j < savedStrokes[i].Points.Length; j++) { if (j == 0) { info.StartDraw(GameManager.Instance.drawManager.StrokesContainer, info, savedStrokes[i].Width, savedStrokes[i].StrokeColor); } info.Drawing(savedStrokes[i].Points[j]); if (j == savedStrokes[i].Points.Length - 1) { GameManager.Instance.actionManager.AddAction(info.GetAction()); info.EndDraw(); } yield return(new WaitForFixedUpdate()); } } }
// Update is called once per frame void Update() { DrawPoint.GetComponent <Renderer>().material.color = CP.TheColor; if (!DeleteMode) { DrawPoint.gameObject.SetActive(true); if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)) { #if UNITY_EDITOR if (EventSystem.current.IsPointerOverGameObject()) #elif IPHONE || UNITY_ANDROID if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #else if (EventSystem.current.IsPointerOverGameObject()) #endif { return; } //更新DrawPoint UpdateDrawPoint(); startDraw = true; BrushInf.StartDraw(StrokesContainer, BrushInf, BrushWidth, CP.TheColor); } else if (Input.GetMouseButton(0) && (DrawPoint.position - lastDrawPoint).sqrMagnitude > (BrushWidth * BrushWidth / 64)) { if (startDraw) { BrushInf.Drawing(DrawPoint.position); } lastDrawPoint = DrawPoint.position; } else if (Input.GetMouseButtonUp(0) && startDraw) { //将操作加入到操作列表 AddActionToManager(BrushInf.GetAction()); startDraw = false; DrawPoint.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition) + Camera.main.transform.forward * .3f; BrushInf.EndDraw(); } if (startDraw) { UpdateDrawPoint(); } } else { DrawPoint.gameObject.SetActive(false); if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.transform.parent == StrokesContainer) { hit.collider.gameObject.SetActive(false); PaintAction action = new DeleteAction(); action.Init(null, hit.collider.gameObject); AddActionToManager(action); } } } } }