Esempio n. 1
0
        public string asJSON()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            sb.Append("  \"name\":\"" + Name + "\"");
            sb.Append(", \"type\":\"" + Type.GetHashCode() + "\"");

            sb.Append(", \"pos_x\":\"" + pos_x + "\"");
            sb.Append(", \"pos_y\":\"" + pos_y + "\"");
            sb.Append(", \"pos_z\":\"" + pos_z + "\"");
            sb.Append(", \"radius\":\"" + radius + "\"");
            sb.Append(", \"tangent\":\"" + tangent + "\"");

            sb.Append(", \"angle\":\"" + angle + "\"");
            sb.Append(", \"len\":\"" + len + "\"");

            if (expressions != null && expressions.Count > 0)
            {
                sb.Append(", \"expressions\":" + AXJson.StringListToJSON(expressions));
            }

            sb.Append("}");

            return(sb.ToString());
        }
Esempio n. 2
0
        // CURVE_POINT
        public static string CurvePointToJSON(CurvePoint cp)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            sb.Append("\"curvePointType\":" + cp.curvePointType.GetHashCode());

            sb.Append(", \"position\":" + AXJson.Vector2ToJSON(cp.position));
            sb.Append(", \"localHandleA\":" + AXJson.Vector2ToJSON(cp.localHandleA));
            sb.Append(", \"localHandleB\":" + AXJson.Vector2ToJSON(cp.localHandleB));

            // finish
            sb.Append("}");

            return(sb.ToString());
        }
Esempio n. 3
0
        public static AXHandle fromJSON(AX.SimpleJSON.JSONNode jn)
        {
            AXHandle h = new AXHandle();

            h.Name = jn["name"].Value;

            h.Type = (AXHandle.HandleType)jn["type"].AsInt;

            h.pos_x   = jn["pos_x"].Value;
            h.pos_y   = jn["pos_y"].Value;
            h.pos_z   = jn["pos_z"].Value;
            h.radius  = jn["radius"].Value;
            h.tangent = jn["tangent"].Value;

            h.angle = jn["angle"].Value;
            h.len   = jn["len"].Value;

            if (jn["expressions"] != null)
            {
                h.expressions = AXJson.StringListFromJSON(jn["expressions"]);
            }

            return(h);
        }
Esempio n. 4
0
        public static AXParametricObject ParametricObjectFromJSON(AX.SimpleJSON.JSONNode jn)
        {
            AXParametricObject po = new AXParametricObject(jn["type"], jn["name"]);


            po.Guid = jn["guid"].Value;

            po.basedOnAssetWithGUID = jn["basedOnAssetWithGUID"].Value;

            po.description      = jn["description"].Value;
            po.author           = jn["author"].Value;
            po.tags             = jn["tags"].Value;
            po.documentationURL = jn["documentationURL"].Value;

            if (jn["includeInSidebarMenu"] != null)
            {
                po.includeInSidebarMenu = jn["includeInSidebarMenu"].AsBool;
            }
            else
            {
                po.includeInSidebarMenu = true;
            }

            po.isInitialized = jn["isInitialized"].AsBool;


            po.grouperKey = jn["grouperKey"].Value;

            if (jn["sortval"] != null)
            {
                po.sortval = jn["sortval"].AsFloat;
            }

            po.curve = AXJson.CurveFromJSON(jn["curve"]);

            po.rect        = AXJson.RectFromJSON(jn["rect"]);
            po.bounds      = AXJson.BoundsFromJSON(jn["bounds"]);
            po.transMatrix = AXJson.Matrix4x4FromJSON(jn["transMatrix"]);

            po.combineMeshes = jn["combineMeshes"].AsBool;
            po.isRigidbody   = jn["isRigidbody"].AsBool;
            po.colliderType  = (AXGeometryTools.ColliderType)jn["colliderType"].AsInt;

            po.axStaticEditorFlags = (AXStaticEditorFlags)jn["axStaticEditorFlags"].AsInt;

            //Debug.Log(po.Name + " " + po.grouperKey);

            // material
            // look to see if there is a material matching this name....
                        #if UNITY_EDITOR
            if (jn["material_assetGUID"] != null)
            {
                string path = AssetDatabase.GUIDToAssetPath(jn["material_assetGUID"].Value);

                //Debug.Log("AssetDatabase.GUIDToAssetPath("+jn["material_assetGUID"].Value+") has path: "  + path);


                // REDO
                if (path != null)
                {
                    //Debug.Log(jn["Name"] + ": path="+path);
                    Material matter = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));

                    //Debug.Log("..."+matter);
                    //po.axMat.mat = (Material) AssetDatabase.LoadAssetAtPath(path, typeof(Material)) ;
                    if (po.axMat == null)
                    {
                        po.axMat = new AXMaterial();
                    }
                    po.axMat.mat = matter;
                }
            }
                        #endif



            // code
            if (jn["code"] != null)
            {
                po.code = jn["code"].Value.Replace(";", "\n");
            }
            // parameters

            if (jn["parameters"] != null)
            {
                po.parameters = new List <AXParameter>();

                foreach (AX.SimpleJSON.JSONNode jn_p in jn["parameters"].AsArray)
                {
                    po.addParameter(AXParameter.fromJSON(jn_p));
                }
            }
            // shapes
            if (jn["shapes"] != null)
            {
                po.shapes = new List <AXShape>();
                foreach (AX.SimpleJSON.JSONNode jn_p in jn["shapes"].AsArray)
                {
                    po.shapes.Add(AXShape.fromJSON(po, jn_p));
                }
            }



            // handles
            if (jn["handles"] != null)
            {
                po.handles = new List <AXHandle>();
                foreach (AX.SimpleJSON.JSONNode jn_h in jn["handles"].AsArray)
                {
                    po.handles.Add(AXHandle.fromJSON(jn_h));
                }
            }

            // cameraSettings
            if (jn["cameraSettings"] != null)
            {
                po.cameraSettings = JSONSerializersAX.AXCameraFromJSON(jn["cameraSettings"]);
                po.cameraSettings.setPosition();
            }


            // make the generator for this po
            po.instantiateGenerator();

            return(po);
        }
Esempio n. 5
0
        // JSON SERIALIZATION
        public static string ParametricObjectAsJSON(AXParametricObject po)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            sb.Append(" \"basedOnAssetWithGUID\":\"" + po.basedOnAssetWithGUID + "\"");
            sb.Append(",\"author\":\"" + po.author + "\"");
            sb.Append(",\"tags\":\"" + po.tags + "\"");

            sb.Append(",\"guid\":\"" + po.Guid + "\"");
            sb.Append(", \"name\":\"" + po.Name + "\"");
            sb.Append(", \"description\":\"" + po.description + "\"");
            sb.Append(", \"type\":\"" + po.Type + "\"");
            sb.Append(", \"isInitialized\":\"" + po.isInitialized + "\"");
            sb.Append(", \"documentationURL\":\"" + po.documentationURL + "\"");


            sb.Append(", \"includeInSidebarMenu\":\"" + po.includeInSidebarMenu + "\"");


            sb.Append(",\"grouperKey\":\"" + po.grouperKey + "\"");



            sb.Append(", \"rect\":" + AXJson.RectToJSON(po.rect));
            sb.Append(", \"bounds\":" + AXJson.BoundsToJSON(po.bounds));
            sb.Append(", \"transMatrix\":" + AXJson.Matrix4x4ToJSON(po.transMatrix));

            if (po.curve != null && po.curve.Count > 0)
            {
                sb.Append(", \"curve\":" + AXJson.CurveToJson(po.curve));
            }

            sb.Append(", \"sortval\":\"" + po.sortval + "\"");

            sb.Append(", \"combineMeshes\":\"" + po.combineMeshes + "\"");
            sb.Append(", \"isRigidbody\":\"" + po.isRigidbody + "\"");
            sb.Append(", \"colliderType\":\"" + po.colliderType.GetHashCode() + "\"");

            sb.Append(", \"axStaticEditorFlags\":\"" + po.axStaticEditorFlags.GetHashCode() + "\"");



            // material
            //Debug.Log ("ENCODE MATERIAL::::");
                        #if UNITY_EDITOR
            if (po.axMat != null && po.axMat.mat != null)
            {
                string matPath = AssetDatabase.GetAssetOrScenePath(po.axMat.mat);
                if (!String.IsNullOrEmpty(matPath))
                {
                    sb.Append(", \"material_assetGUID\":\"" + AssetDatabase.AssetPathToGUID(matPath) + "\"");
                }
            }
                        #endif

            // code
            if (po.code != null)
            {
                sb.Append(", \"code\":\"" + po.code.Replace("\n", ";") + "\"");
            }



            // parameters
            sb.Append(", \"parameters\": [");                           // begin parameters
            string the_comma = "";
            foreach (AXParameter p in po.parameters)
            {
                sb.Append(the_comma + p.asJSON());
                the_comma = ", ";
            }
            sb.Append("]");                                                             // end parameters

            // shapes
            if (po.shapes != null)
            {
                sb.Append(", \"shapes\": [");                           // begin parameters
                the_comma = "";
                foreach (AXShape shp in po.shapes)
                {
                    sb.Append(the_comma + shp.asJSON());
                    the_comma = ", ";
                }
                sb.Append("]");                                                                 // end parameters
            }

            // handles

            if (po.handles != null && po.handles.Count > 0)
            {
                sb.Append(", \"handles\": [");                          // begin parameters
                the_comma = "";
                foreach (AXHandle h in po.handles)
                {
                    sb.Append(the_comma + h.asJSON());
                    the_comma = ", ";
                }
                sb.Append("]");
            }            // end parameters


            // cameraSettings
            if (po.cameraSettings != null)
            {
                sb.Append(",\"cameraSettings\":" + JSONSerializersAX.AXCameraAsJSON(po.cameraSettings));
            }



            // finish
            sb.Append("}");             // end parametri_object
            //Debug.Log (sb.ToString());
            return(sb.ToString());
        }