Esempio n. 1
0
 private JSONNumber ParseNumber()
 {
     db("parsing number");
     JSONNumber ret = new JSONNumber();
     int start = ptr;
     int length = 0;
     while((tok() >= '0' && tok() <= '9') || tok() == '.' || tok() == '-' || tok() == '+' || tok() == 'e' || tok() == 'E') {
         lex();
         length++;
     }
     db("attempting to parse " + data.Substring(start, length));
     ret.val = double.Parse(data.Substring(start, length));
     return ret;
 }
        public void Execute(JSONNode args)
        {
            var result = new JSONNumber(ApiManager.Instance.CurrentFrame);

            ApiManager.Instance.SendResult(result);
        }
Esempio n. 3
0
        public void Execute(string client, JSONNode args)
        {
            var result = new JSONNumber(ApiManager.Instance.CurrentTime);

            ApiManager.Instance.SendResult(client, result);
        }
Esempio n. 4
0
        static void PostProcessDelayed()
        {
            EditorApplication.delayCall -= PostProcessDelayed;
            if (m_ImportedAssets.Count == 0)
            {
                return;
            }

            string[] tImportedAssets = m_ImportedAssets[0];
            m_ImportedAssets.RemoveAt(0);

            bool tSaveAssets = false;

            for (int i = 0; i < tImportedAssets.Length; i++)
            {
                string tPath = tImportedAssets[i];
                if (tPath.EndsWith(".ase"))
                {
                    Object tAsset = AssetDatabase.LoadAssetAtPath <Object>(tPath);

                    bool          tDirty    = false;
                    AssetImporter tImporter = AssetImporter.GetAtPath(tPath);
                    JSONNode      tData     = JSON.Parse(tImporter.userData);
                    if (tData == null)
                    {
                        tData = new JSONObject();
                    }
                    JSONNode        tID  = tData["assetID"];
                    CAsepriteObject tObj = null;
                    if (tID != null)
                    {
                        tObj = GetAssetByID <CAsepriteObject>(tID.Value);
                        if (tObj == null)
                        {
                            tObj = FindAsepriteObject(tAsset);
                        }
                    }
                    else
                    {
                        tID = new JSONNumber(0);
                        tData["assetID"] = tID;
                        tDirty           = true;
                    }

                    if (tObj == null)
                    {
                        tObj = CAsepriteObjectEditor.CreateAsset(tPath);

                        /*
                         * { "targetTexture":"c92e2bd276d32ed4984c0a349da9dcc8",
                         * "targetText":"1cb757cd5d2c60f4cb1d15f7653554bc",
                         * "useTags":"true",
                         * "loopAnim":"false",
                         * "useConfig":"true",
                         * "border":"5",
                         * "useChild":"true",
                         * "alignment":"0",
                         * "pivotX":"0.100000001490116",
                         * "pivotY":"0.200000002980232",
                         * "animType":"0",
                         * "clips":["7ab1c6126e7e91c4d8d19e3f7e8e8f6d","416c940187f463c4f9af57db128e5cbe"],
                         * "autoImport":"false",
                         * "importAnimations":"true",
                         * "importSpritesheet":"true",
                         * "createAnimator":"true",
                         * "targetAnimator":"88400be09d870114491df24486087eb5",
                         * "targetPrefab":"c1df4f5e993e4b347a7ab29909bebb01"}
                         */
                        SetAssetValue(tData, "targetTexture", ref tObj.targetTexture);
                        SetAssetValue(tData, "targetText", ref tObj.targetAtlas);
                        SetBool(tData, "useTags", ref tObj.useTags);
                        SetBool(tData, "loopAnim", ref tObj.loopAnim);
                        SetBool(tData, "useConfig", ref tObj.useConfig);
                        SetInt(tData, "border", ref tObj.border);
                        SetFloat(tData, "pivotX", ref tObj.pivot.x);
                        SetFloat(tData, "pivotY", ref tObj.pivot.y);
                        int alignment = -1;
                        if (SetInt(tData, "alignment", ref alignment))
                        {
                            tObj.alignment = (SpriteAlignment)alignment;
                        }
                        var node = tData["clips"];
                        if (node != null && node.IsArray)
                        {
                            var clips = node.AsArray;
                            tObj.clips = new AnimationClip[clips.Count];
                            for (int j = 0; j < tObj.clips.Length; j++)
                            {
                                tObj.clips[j] = GetAssetByID <AnimationClip>(clips[j].Value);
                            }
                        }
                        SetAssetValue(tData, "targetAnimator", ref tObj.targetAnimator);
                        SetAssetValue(tData, "targetPrefab", ref tObj.targetPrefab);

                        EditorUtility.SetDirty(tObj);
                    }
                    tID.Value          = GetIDByAsset(tObj);
                    tObj.asepriteAsset = tAsset;
                    bool tExported = CAsepriteObjectEditor.Import(tPath, tObj);

                    if (tExported)
                    {
                        tImporter.userData = tData.ToString();
                        tSaveAssets        = true;
                        tDirty             = true;
                    }
                    if (tDirty)
                    {
                        EditorUtility.SetDirty(tAsset);
                        AssetDatabase.WriteImportSettingsIfDirty(tPath);
                    }
                    EditorUtility.SetDirty(tObj);
                }
            }

            if (tSaveAssets)
            {
                AssetDatabase.SaveAssets();
            }
        }
Esempio n. 5
0
        private static JSONNode DoObject2JSONNode(string key, object obj, JSONNode parent)
        {
            if (obj == null)
            {
                JSONNode jnull = new JSONNull();
                if (!DoObject2JSONNode_AddToParent(parent, key, jnull))
                {
                    return(jnull);
                }
            }
            else if (obj is IDictionary)
            {
                JSONObject jobject = Johny.JSONNodePool.Claim(typeof(Johny.JSONObject)).AsObject;
                var        it      = (obj as IDictionary).GetEnumerator();
                while (it.MoveNext())
                {
                    DoObject2JSONNode(it.Key as string, it.Value, jobject);
                }

                if (!DoObject2JSONNode_AddToParent(parent, key, jobject))
                {
                    return(jobject);
                }
            }
            else if (obj is ICollection)
            {
                JSONArray jarray = Johny.JSONNodePool.Claim(typeof(Johny.JSONArray)).AsArray;
                var       it     = (obj as ICollection).GetEnumerator();
                while (it.MoveNext())
                {
                    DoObject2JSONNode(string.Empty, it.Current, jarray);
                }

                if (!DoObject2JSONNode_AddToParent(parent, key, jarray))
                {
                    return(jarray);
                }
            }
            else if (obj is string)
            {
                JSONString jstring = Johny.JSONNodePool.Claim(typeof(Johny.JSONString)) as JSONString;
                jstring.InitString(obj as string);

                if (!DoObject2JSONNode_AddToParent(parent, key, jstring))
                {
                    return(jstring);
                }
            }
            else if (obj is bool)
            {
                JSONBool jbool = new JSONBool((bool)obj);
                if (!DoObject2JSONNode_AddToParent(parent, key, jbool))
                {
                    return(jbool);
                }
            }
            else if (obj is System.Enum)
            {
                JSONNumber jnum = new JSONNumber((int)obj);
                if (!DoObject2JSONNode_AddToParent(parent, key, jnum))
                {
                    return(jnum);
                }
            }
            else if (IsNumeric(obj))
            {
                double     dd   = Convert.ToDouble(obj);
                JSONNumber jnum = new JSONNumber(dd);
                if (!DoObject2JSONNode_AddToParent(parent, key, jnum))
                {
                    return(jnum);
                }
            }
            else
            {
                EB.Debug.LogError($"此类型JSON无法解析,请自行转换成基本类型!==> {obj.GetType().FullName}");
            }

            return(null);
        }
Esempio n. 6
0
 public static string ToString(JSONNumber jsonNumber)
 {
     return(jsonNumber._value.ToString());
 }