static void MergeRecur(KJSON left, KJSON right) { if(right.type == KJSON.Type.OBJECT) { for(int i = 0; i < right.list.Count; i++) { if(right.keys[i] != null) { string key = (string)right.keys[i]; KJSON val = (KJSON)right.list[i]; if(val.type == KJSON.Type.ARRAY || val.type == KJSON.Type.OBJECT) { if(left.HasField(key)) MergeRecur(left[key], val); else left.AddField(key, val); } else { if(left.HasField(key)) left.SetField(key, val); else left.AddField(key, val); } } } }// else left.list.Add(right.list); }
public KJSON(KJSON.Type t) { type = t; switch(t) { case Type.ARRAY: list = new ArrayList(); break; case Type.OBJECT: list = new ArrayList(); keys = new ArrayList(); break; } }
private static IEnumerator screenshot(string type,string message,Dictionary<string,string> data) { yield return new WaitForEndOfFrame(); byte[] bytes = null; try { int width = Screen.width; int height = Screen.height; Texture2D texture = new Texture2D(width,height,TextureFormat.RGB24,false); texture.ReadPixels(new Rect(0,0,width,height),0,0); texture.Apply(); bytes = texture.EncodeToPNG(); MonoBehaviour.Destroy(texture); } finally{} if(bytes == null) return false; KJSON extra = getExtra(); KJSON opaque = new KJSON(data); WWWForm form = new WWWForm(); form.AddField("APIKey",s_apiKey); form.AddField("Extra",extra.ToString()); form.AddField("Message",message); form.AddField("Opaque",opaque.ToString()); form.AddField("Platform",12); form.AddField("Time",getTimestamp().ToString()); form.AddField("Type",type); form.AddField("Version",s_version); form.AddBinaryData("Screenshot",bytes,"screenshot.png","image/png"); form.AddField("marker","complete"); new UnityEngine.WWW(s_server + "/rest/screenshot-add.jsp",form); }
private static KJSON getExtra() { KJSON extra = new KJSON(KJSON.Type.OBJECT); try { KJSON system = new KJSON(KJSON.Type.OBJECT); system.AddField("Device Model",SystemInfo.deviceModel); system.AddField("Device Name",SystemInfo.deviceName); system.AddField("Device Type",SystemInfo.deviceType.ToString()); system.AddField("Device Unique Identifier",SystemInfo.deviceUniqueIdentifier); system.AddField("Graphics Device ID",SystemInfo.graphicsDeviceID); system.AddField("Graphics Device Name",SystemInfo.graphicsDeviceName); system.AddField("Graphics Device Vendor",SystemInfo.graphicsDeviceVendor); system.AddField("Graphics Device Vendor ID",SystemInfo.graphicsDeviceVendorID); system.AddField("Graphics Device Version",SystemInfo.graphicsDeviceVersion); system.AddField("Graphics Memory Size",SystemInfo.graphicsMemorySize); system.AddField("Graphics Pixel Fill-rate",SystemInfo.graphicsPixelFillrate); system.AddField("Graphics Shader Level",SystemInfo.graphicsShaderLevel); system.AddField("Operating System",SystemInfo.operatingSystem); system.AddField("Processor Count",SystemInfo.processorCount); system.AddField("Processor Type",SystemInfo.processorType); system.AddField("Render Target Count",SystemInfo.supportedRenderTargetCount); system.AddField("Supports Accelerometer",SystemInfo.supportsAccelerometer); system.AddField("Supports Gyroscope",SystemInfo.supportsGyroscope); system.AddField("Supports Image Effects",SystemInfo.supportsImageEffects); system.AddField("Supports Location Service",SystemInfo.supportsLocationService); system.AddField("Supports Render Textures",SystemInfo.supportsRenderTextures); system.AddField("Supports Shadows",SystemInfo.supportsShadows); system.AddField("Supports Vertex Programs",SystemInfo.supportsVertexPrograms); system.AddField("Supports Vibration",SystemInfo.supportsVibration); system.AddField("System Memory Size",SystemInfo.systemMemorySize); if(Application.platform == RuntimePlatform.IPhonePlayer) { // TODO: system.AddField("iOS Generation",iPhone.generation.ToString()); } extra.AddField("System",system); KJSON application = new KJSON(KJSON.Type.OBJECT); application.AddField("Is Editor",Application.isEditor); application.AddField("Is Playing",Application.isPlaying); application.AddField("Is Web Player",Application.isWebPlayer); application.AddField("Platform",Application.platform.ToString()); application.AddField("Data Path",Application.dataPath); application.AddField("Streaming Assets Path",Application.streamingAssetsPath); application.AddField("Persistent Data Path",Application.persistentDataPath); application.AddField("Temporary Cache Path",Application.temporaryCachePath); application.AddField("Unity Verstion",Application.unityVersion); application.AddField("Target Frame Rate",Application.targetFrameRate); application.AddField("System Language",Application.systemLanguage.ToString()); application.AddField("Internet Reachability",Application.internetReachability.ToString()); //application.AddField("Is Genuine Check Available",Application.genuineCheckAvailable); //if(Application.genuineCheckAvailable) application.AddField("Is Genuine Application",Application.genuine); extra.AddField("Application",application); KJSON debug = new KJSON(KJSON.Type.OBJECT); debug.AddField("Is Debug Build",Debug.isDebugBuild); extra.AddField("Debug",debug); KJSON input = new KJSON(KJSON.Type.OBJECT); input.AddField("Device Orientation",Input.deviceOrientation.ToString()); input.AddField("Supports Multi Touch",Input.multiTouchEnabled); if(SystemInfo.supportsAccelerometer) input.AddField("Acceleration",Input.acceleration.ToString()); extra.AddField("Input",input); if(Input.compass.enabled) { KJSON compass = new KJSON(KJSON.Type.OBJECT); compass.AddField("Enabled",Input.compass.enabled); if(Input.compass.enabled) { compass.AddField("Geographic Heading",Input.compass.trueHeading); if(SystemInfo.supportsLocationService && Input.location.status == LocationServiceStatus.Running) compass.AddField("Magnetic Heading",Input.compass.magneticHeading); compass.AddField("Raw Vector",Input.compass.rawVector.ToString()); } input.AddField("Compass",compass); } if(SystemInfo.supportsGyroscope) { KJSON gyroscope = new KJSON(KJSON.Type.OBJECT); gyroscope.AddField("Enabled",Input.gyro.enabled); if(Input.gyro.enabled) { gyroscope.AddField("Attitude",Input.gyro.attitude.ToString()); gyroscope.AddField("Gravity",Input.gyro.gravity.ToString()); gyroscope.AddField("Rotation Rate",Input.gyro.rotationRate.ToString()); gyroscope.AddField("Unbiased Rotation Rate",Input.gyro.rotationRateUnbiased.ToString()); gyroscope.AddField("Update Interval",Input.gyro.updateInterval); gyroscope.AddField("User Acceleration",Input.gyro.userAcceleration.ToString()); } input.AddField("Gyroscope",gyroscope); } if(SystemInfo.supportsLocationService) { KJSON location = new KJSON(KJSON.Type.OBJECT); location.AddField("Status",Input.location.status.ToString()); if(Input.location.status == LocationServiceStatus.Running) { LocationInfo l = Input.location.lastData; location.AddField("Latitude",l.latitude); location.AddField("Longitude",l.longitude); location.AddField("Altitude",l.altitude); location.AddField("Horizontal Accuracy",l.horizontalAccuracy); location.AddField("Vertical Accuracy",l.verticalAccuracy); } input.AddField("Location",location); } KJSON screen = new KJSON(KJSON.Type.OBJECT); screen.AddField("Autorotate to Landscape Left",Screen.autorotateToLandscapeLeft); screen.AddField("Autorotate to Landscape Right",Screen.autorotateToLandscapeRight); screen.AddField("Autorotate to Portrait",Screen.autorotateToPortrait); screen.AddField("Autorotate to Portrait Upside Down",Screen.autorotateToPortraitUpsideDown); screen.AddField("Current Orientation",Screen.orientation.ToString()); screen.AddField("Current Resolution",Screen.currentResolution.width + "x" + Screen.currentResolution.height + "@" + Screen.currentResolution.refreshRate + "Hz"); screen.AddField("DPI",Screen.dpi); screen.AddField("Is Fullscreen",Screen.fullScreen); screen.AddField("Sleep Timeout",Screen.sleepTimeout); extra.AddField("Screen",screen); } finally{} return extra; }
public void SetField(string name, KJSON obj) { if(HasField(name)) { list.Remove(this[name]); keys.Remove(name); } AddField(name, obj); }
/* * The Merge function is experimental. Use at your own risk. */ public void Merge(KJSON obj) { MergeRecur(this, obj); }
public void AddField(string name, KJSON obj) { if(obj!=null){ //Don't do anything if the object is null if(type != KJSON.Type.OBJECT){ type = KJSON.Type.OBJECT; //Congratulations, son, you're an OBJECT now //Debug.LogWarning("tried to add a field to a non-object KJSON. We'll do it for you, but you might be doing something wrong."); } keys.Add(name); list.Add(obj); } }
public void Add(KJSON obj) { if(obj!=null) { //Don't do anything if the object is null if(type != KJSON.Type.ARRAY) { type = KJSON.Type.ARRAY; //Congratulations, son, you're an ARRAY now //Debug.LogWarning("tried to add an object to a non-array KJSON. We'll do it for you, but you might be doing something wrong."); } list.Add(obj); } }