// Helper func to convert info to a PaintStroke object private PaintStroke PaintStrokeFromInfo(PaintStrokeInfo info) { GameObject psHolder = new GameObject("psholder"); // Since PaintStroke is a Monobehavior, it needs a game object to attach to psHolder.AddComponent <PaintStroke>(); PaintStroke paintStroke = psHolder.GetComponent <PaintStroke>(); paintStroke.color = new Color(info.initialColor.x, info.initialColor.y, info.initialColor.z, info.initialColor.w); List <Vector3> v = new List <Vector3>(); paintStroke.verts = v; List <Color> c = new List <Color>(); paintStroke.pointColors = c; paintStroke.pointSizes = new List <float>(); for (int i = 0; i < info.verts.Length; i++) { paintStroke.verts.Add(info.verts[i]); Color ptColor = new Color(info.pointColors[i].x, info.pointColors[i].y, info.pointColors[i].z, 1f); paintStroke.pointColors.Add(ptColor); paintStroke.pointSizes.Add(info.pointSizes[i]); } return(paintStroke); }
private IEnumerator PaintTrail(GameObject brush, PaintStroke paintstroke, AraTrail araTrail) { Vector3 paintstrokeOffset = new Vector3(0f, 0f, 0.5f); araTrail.hasMoved = true; // on by default, controls whether a point is emitted //brush.transform.parent = paintstrokeParent.transform; for (int i = 0; i < paintstroke.verts.Count; i++) { // can't set point color directly, so set the initialColor, which is then used to create the pointColor for the next point araTrail.initialColor = paintstroke.pointColors[i]; // set the initialThickness, which is then used to create the size of the next point araTrail.initialThickness = paintstroke.pointSizes[i]; brush.transform.position = paintstroke.verts[i] + paintstrokeOffset; yield return(new WaitForSeconds(paintWait)); // allow enough time for the previous mesh section to be generated } araTrail.loading = false; // Now that the PaintStroke has been saved, unparent it from the target so it's positioned in worldspace // TODO: refactor into its own method (repeated (almost) in RemoveBrushFromTarget()) brush.tag = "PaintStroke"; // Remove the reticle and brush, no longer needed foreach (Transform child in brush.transform) { Destroy(child.gameObject); } }
// reconstitute the JSON public void LoadFromJSON(JToken mapMetadata) { Clear(); // Clear the paintstrokes if (mapMetadata is JObject && mapMetadata[jsonKey] is JObject) { Debug.Log("A-LoadPaintStrokesJSON"); // this next line breaks when deserializing a list of vector4's PaintStrokeInfoArray paintStrokes = mapMetadata[jsonKey].ToObject <PaintStrokeInfoArray>(); Debug.Log("B-LoadPaintStrokesJSON"); if (paintStrokes.paintStrokeInfos == null) { Debug.Log("no PaintStrokes were added"); return; } // (may need to do a for loop to ensure they stay in order?) foreach (var paintStrokeInfo in paintStrokes.paintStrokeInfos) { infoList.Add(paintStrokeInfo); PaintStroke paintstroke = PaintStrokeFromInfo(paintStrokeInfo); objList.Add(paintstroke); // should be used by PaintManager to recreate painting Debug.Log("C-LoadPaintStrokesJSON"); } Debug.Log("D-LoadPaintStrokesJSON"); paintManager.paintStrokesList = objList; // not really objects, rather components (Monobehaviors) Debug.Log("E-LoadPaintStrokesJSON"); paintManager.RecreatePaintedStrokes(); Debug.Log("F-LoadPaintStrokesJSON"); } }
private void AddPaintStrokeToList(GameObject brush) { // 3rd party Ara Trails replaces Unity Trail Renderer List <Vector3> vertList = new List <Vector3>(); List <Color> colorList = new List <Color>(); List <float> sizeList = new List <float>(); AraTrail araTrail = brush.GetComponent <AraTrail>(); //araTrail.active = false; // not being actively drawn, so do not need to constantly update rounded end points araTrail.trailstate = AraTrail.TrailState.DrawnFlatEnd; // allow rounding points to be added. araTrail.initialColor = paintColor; araTrail.initialThickness = brushSize; int numPosAra = araTrail.points.Count; for (int i = 0; i < numPosAra; i++) { vertList.Add(araTrail.points[i].position); colorList.Add(araTrail.points[i].color); sizeList.Add(araTrail.points[i].thickness); // alternately, could add the AraTrail points themselves to the Paintstroke, // since they already hold the colors, plus other info such as discontinuous. } // Add the rounding endpoints to the list of points //for (int i = 0; i < araTrail.endPoints.Count; i++) //{ // vertList.Add(araTrail.endPoints[i].position); // colorList.Add(Color.yellow); // test to see if endpoints are added //colorList.Add(araTrail.endPoints[i].color); // sizeList.Add(araTrail.endPoints[i].thickness); //} // Only add the new PaintStrokes if it's newly created, not if loading from a saved map // TODO: Need a bool to prevent saving to list when strokes are being recreated? //if (!paintOnComponent.meshLoading) //{ PaintStroke paintStroke = brush.AddComponent <PaintStroke>(); paintStroke.color = paintColor; paintStroke.verts = vertList; paintStroke.pointColors = colorList; paintStroke.pointSizes = sizeList; paintStrokesList.Add(paintStroke); // } }