Пример #1
0
 static public string JsonToString(SimpleJSON.JSONObject jClass)
 {
     if (null == jClass)
     {
         return(string.Empty);
     }
     return(JsonToString(jClass.ToString()));
 }
Пример #2
0
        public static StringMessage BasicValueToStringMsg(string p_event_name, string p_value, string p_playerID)
        {
            SimpleJSON.JSONObject newJSON = new SimpleJSON.JSONObject();
            newJSON["_id"]       = p_event_name;
            newJSON["player_id"] = p_playerID;
            newJSON["message"]   = p_value;

            return(new StringMessage(newJSON.ToString()));
        }
Пример #3
0
    /// <summary>
    /// Builds JSON object of the results and writes it to a file
    /// </summary>
    /// <param name="time"></param>
    /// <param name="usedCheats"></param>
    public static void WriteResultsToFile(float time, bool usedCheats)
    {
        var outputObject = new SimpleJSON.JSONObject();

        outputObject["completionTime"] = time;
        outputObject["usedCheats"]     = usedCheats;

        string   file = Path.Combine(Directory.GetCurrentDirectory(), GameConfiguration.Instance.OutputFile);
        FileInfo fi   = new FileInfo(file);

        if (!fi.Directory.Exists)
        {
            Directory.CreateDirectory(fi.DirectoryName);
        }
        File.WriteAllText(file, outputObject.ToString());
    }
Пример #4
0
    void sendToVuforia()
    {
        //Debug.Log("capturing image for vuforia");
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        sw.Reset();
        sw.Start();
        Texture2D colorTexture = (Texture2D)imageCube.GetComponent <Renderer>().material.mainTexture;

        sw.Stop();
        //Debug.Log("time to acquire texture pointer: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        RenderTexture colorRT = new RenderTexture(colorTexture.width, colorTexture.height, 24, RenderTextureFormat.ARGB32);

        sw.Stop();
        //Debug.Log("time to declare render texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        Graphics.Blit(colorTexture, colorRT); //move it from colortexture gpu to rendertexture
        sw.Stop();
        //Debug.Log("time to blit texture to render texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        RenderTexture.active = colorRT;
        sw.Stop();
        //Debug.Log("time to make render texture active: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));


        //debugFreezeRendertexture = colorRT;
        sw.Reset();
        sw.Start();
        Texture2D colorFreeze = new Texture2D(colorTexture.width, colorTexture.height, TextureFormat.ARGB32, false);

        sw.Stop();
        //Debug.Log("time to declare a freeze texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        colorFreeze.ReadPixels(new UnityEngine.Rect(0, 0, colorTexture.width, colorTexture.height), 0, 0);
        sw.Stop();
        //Debug.Log("time to read pixels from rendertexture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        byte[] c         = colorFreeze.GetRawTextureData();
        string outstring = "";

        for (int i = 0; i < 50; i++)
        {
            outstring += c[i] + "-";
        }
        //Debug.Log("first 50: " + outstring);

        sw.Reset();
        sw.Start();
        colorFreeze.Apply();
        sw.Stop();
        //Debug.Log("time to do apply: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));



        sw.Reset();
        sw.Start();
        byte[] b = colorFreeze.GetRawTextureData();
        sw.Stop();
        //Debug.Log("time to return raw texture data: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));
        //Array.Reverse(b);

        string outstring2 = "";

        for (int i = 0; i < 50; i++)
        {
            outstring2 += b[i] + "-";
        }
        //Debug.Log("first 50: " + outstring2);

        /*
         * //flip up down:
         * byte[] b_flip = new byte[b.Length];
         * for (int i = 0; i < colorFreeze.height; i++)
         * {
         *  for (int j = 0; j < 4 * colorFreeze.width; j++)
         *  {
         *      b_flip[i * (colorFreeze.width * 4) + j] = b[((colorFreeze.height - 1) - i) * (colorFreeze.width * 4) + j];
         *  }
         * }
         * //b = b_flip;
         */

        sw.Reset();
        sw.Start();
        string image_data = System.Convert.ToBase64String(b);

        sw.Stop();
        //Debug.Log("time to convert to base 64: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));


        sw.Reset();
        sw.Start();
        JSONNode vuforiaRequest = new SimpleJSON.JSONObject();

        vuforiaRequest.Add("imageData", image_data);
        vuforiaRequest.Add("imageWidth", colorFreeze.width);
        vuforiaRequest.Add("imageHeight", colorFreeze.height);

        vuforiaRequest.Add("A_offset", 0);
        vuforiaRequest.Add("R_offset", 1);
        vuforiaRequest.Add("G_offset", 2);
        vuforiaRequest.Add("B_offset", 3);
        string data = vuforiaRequest.ToString();

        sw.Stop();
        //Debug.Log("time to make vuforia string: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        GameObject.Find("pusher").GetComponent <Pusher>().sendToVuforia(data);
        sw.Stop();
        //Debug.Log("time to send vuforia string: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        DestroyImmediate(colorRT);
        DestroyImmediate(colorFreeze);
        sw.Stop();
        //Debug.Log("time to destroy resources: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        SerializedProperty list = serializedObject.FindProperty("affixes");

        EditorGUILayout.PropertyField(list);

        EditorGUI.indentLevel += 1;
        if (list.isExpanded)
        {
            for (int i = 0; i < list.arraySize; i++)
            {
                SerializedProperty affix        = list.GetArrayElementAtIndex(i);
                SerializedProperty Name         = affix.FindPropertyRelative("name");
                SerializedProperty ItemLevel    = affix.FindPropertyRelative("item_level");
                SerializedProperty MinAmount    = affix.FindPropertyRelative("min_amount");
                SerializedProperty MaxAmount    = affix.FindPropertyRelative("max_amount");
                SerializedProperty Type         = affix.FindPropertyRelative("type");
                SerializedProperty Modifier     = affix.FindPropertyRelative("modifier");
                SerializedProperty ModifierType = affix.FindPropertyRelative("modifier_type");
                SerializedProperty ItemType     = affix.FindPropertyRelative("item_type");

                float oldlabelwidth = EditorGUIUtility.labelWidth;
                float oldfieldwidth = EditorGUIUtility.fieldWidth;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(affix);
                if (GUILayout.Button("\u2191", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    list.MoveArrayElement(i, i - 1);
                }
                if (GUILayout.Button("\u2193", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    list.MoveArrayElement(i, i + 1);
                }

                bool propertyDeleted = false;
                if (GUILayout.Button("-", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    propertyDeleted = true;
                    list.DeleteArrayElementAtIndex(i);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel += 1;
                if (!propertyDeleted && affix.isExpanded)
                {
                    EditorGUILayout.LabelField("Basic Information", EditorStyles.boldLabel);
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Name", GUILayout.Width(100));
                    EditorGUILayout.PropertyField(Name, new GUIContent(""));
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Item Level", GUILayout.Width(100));
                    EditorGUILayout.PropertyField(ItemLevel, new GUIContent(""));
                    EditorGUILayout.LabelField("Item Type", GUILayout.Width(100));
                    EditorGUILayout.PropertyField(ItemType, new GUIContent(""));
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Affix Information", EditorStyles.boldLabel);
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(Type, new GUIContent(""));
                    EditorGUILayout.PropertyField(Modifier, new GUIContent(""));
                    EditorGUILayout.PropertyField(ModifierType, new GUIContent(""));
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Amounts", EditorStyles.boldLabel);
                    EditorGUIUtility.labelWidth = 60;
                    EditorGUILayout.Space();
                    EditorGUILayout.PropertyField(MinAmount, new GUIContent("Min"));
                    EditorGUILayout.PropertyField(MaxAmount, new GUIContent("Max"));
                    float min = MinAmount.intValue;
                    float max = MaxAmount.intValue;
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.MinMaxSlider(ref min, ref max, 0, 130);
                    EditorGUILayout.EndHorizontal();
                    EditorGUIUtility.labelWidth = oldlabelwidth;
                    MinAmount.intValue          = (int)min;
                    MaxAmount.intValue          = (int)max;
                    if (MinAmount.intValue > MaxAmount.intValue)
                    {
                        MinAmount.intValue = MaxAmount.intValue;
                    }
                }
                EditorGUI.indentLevel -= 1;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            if (GUILayout.Button("+", GUILayout.Width(158)))
            {
                list.InsertArrayElementAtIndex(list.arraySize);
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUI.indentLevel -= 1;


        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Location: Resources/affixes.json", GUILayout.Width(250), GUILayout.Height(20));

        if (GUILayout.Button("Save"))
        {
            SimpleJSON.JSONObject root    = new SimpleJSON.JSONObject();
            SimpleJSON.JSONArray  objects = root["list"].AsArray;
            for (int i = 0; i < list.arraySize; i++)
            {
                SerializedProperty    affix = list.GetArrayElementAtIndex(i);
                SimpleJSON.JSONObject af    = objects[-1].AsObject;
                af["name"]          = affix.FindPropertyRelative("name").stringValue;
                af["item_level"]    = affix.FindPropertyRelative("item_level").intValue;
                af["min_range"]     = affix.FindPropertyRelative("min_amount").intValue;
                af["max_range"]     = affix.FindPropertyRelative("max_amount").intValue;
                af["type"]          = affix.FindPropertyRelative("type").enumNames[affix.FindPropertyRelative("type").enumValueIndex];
                af["modifier"]      = affix.FindPropertyRelative("modifier").enumNames[affix.FindPropertyRelative("modifier").enumValueIndex];
                af["modifier_type"] = affix.FindPropertyRelative("modifier_type").enumNames[affix.FindPropertyRelative("modifier_type").enumValueIndex];
                af["item_type"]     = affix.FindPropertyRelative("item_type").enumNames[affix.FindPropertyRelative("item_type").enumValueIndex];
            }

            File.WriteAllText("Assets/Resources/affixes.json", root.ToString(3));
            Debug.Log("Saved to Assets/Resources/affixes.json!");
        }

        if (GUILayout.Button("Load"))
        {
            SimpleJSON.JSONNode   json    = SimpleJSON.JSON.Parse(File.ReadAllText("Assets/Resources/affixes.json"));
            SimpleJSON.JSONObject root    = (SimpleJSON.JSONObject)json;
            SimpleJSON.JSONArray  objects = root["list"].AsArray;

            list.ClearArray();
            for (int i = 0; i < objects.Count; i++)
            {
                SimpleJSON.JSONObject af = objects[i].AsObject;
                list.InsertArrayElementAtIndex(list.arraySize);
                SerializedProperty affix = list.GetArrayElementAtIndex(list.arraySize - 1);
                affix.FindPropertyRelative("name").stringValue    = af["name"];
                affix.FindPropertyRelative("item_level").intValue = af["item_level"];
                affix.FindPropertyRelative("min_amount").intValue = af["min_range"];
                affix.FindPropertyRelative("max_amount").intValue = af["max_range"];
                for (int j = 0; j < affix.FindPropertyRelative("type").enumNames.Length; j++)
                {
                    if (affix.FindPropertyRelative("type").enumNames[j] == af["type"])
                    {
                        affix.FindPropertyRelative("type").enumValueIndex = j;
                        break;
                    }
                }
                for (int j = 0; j < affix.FindPropertyRelative("modifier").enumNames.Length; j++)
                {
                    if (affix.FindPropertyRelative("modifier").enumNames[j] == af["modifier"])
                    {
                        affix.FindPropertyRelative("modifier").enumValueIndex = j;
                        break;
                    }
                }
                for (int j = 0; j < affix.FindPropertyRelative("modifier_type").enumNames.Length; j++)
                {
                    if (affix.FindPropertyRelative("modifier_type").enumNames[j] == af["modifier_type"])
                    {
                        affix.FindPropertyRelative("modifier_type").enumValueIndex = j;
                        break;
                    }
                }
                for (int j = 0; j < affix.FindPropertyRelative("item_type").enumNames.Length; j++)
                {
                    if (affix.FindPropertyRelative("item_type").enumNames[j] == af["item_type"])
                    {
                        affix.FindPropertyRelative("item_type").enumValueIndex = j;
                        break;
                    }
                }
            }

            Debug.Log("Succesfully loaded affixes.json!");
        }
        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();
    }