예제 #1
0
    // 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");
        }
    }
예제 #2
0
    // convert array of paintstroke info to json
    public JObject ToJSON()
    {
        // Create a new PaintStrokeInfoArray object with values copied from paintStrokesInfoList(a List of PaintStrokeInfo)
        // We need this array so it can convert to a JObject

        PaintStrokeInfoArray paintStrokeInfoArray = new PaintStrokeInfoArray();

        // define the array to assign
        PaintStrokeInfo[] psiArray = new PaintStrokeInfo[infoList.Count];
        paintStrokeInfoArray.paintStrokeInfos = psiArray;
        // populate the array
        for (int i = 0; i < infoList.Count; i++)
        {
            psiArray[i]              = new PaintStrokeInfo();
            psiArray[i].verts        = infoList[i].verts;
            psiArray[i].pointColors  = infoList[i].pointColors;
            psiArray[i].pointSizes   = infoList[i].pointSizes;
            psiArray[i].initialColor = infoList[i].initialColor;
        }

        return(JObject.FromObject(paintStrokeInfoArray));
    }