Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
// JSONRuntimeDebug
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace Leguar.TotalJSON.Internal {
public class JSONRuntimeDebug : EditorWindow {
private static int selected=0;
private static List<DebugObject> latestObjects;
private static bool previousWasPlaying = false;
[MenuItem("Window/Total JSON/JSON Runtime Debug")]
static void Init() {
JSONRuntimeDebug window=(JSONRuntimeDebug)(GetWindow(typeof(JSONRuntimeDebug)));
#if UNITY_5 || UNITY_2017
window.titleContent = new GUIContent("JSON Runtime Debug");
#else
Texture2D icon = (Texture2D)(AssetDatabase.LoadAssetAtPath("Assets/TotalJSON/Internal/Editor/window-icon.png", typeof(Texture2D)));
window.titleContent = new GUIContent("JSON Runtime Debug",icon);
#endif
}
void OnGUI() {
GUILayout.Space(15);
if (!Application.isPlaying) {
if (latestObjects==null) {
GUILayout.Label("Application is not running. This debug is available only when application is running and some JSON/Jarray object is added to debug.");
} else {
GUILayout.Label("Application is not running. Below is last state of JSON/Jarray objects from previous run.");
if (previousWasPlaying) {
foreach (DebugObject latestObject in latestObjects) {
latestObject.refresh();
}
}
outputLatestContent();
}
previousWasPlaying=false;
return;
} else {
previousWasPlaying=true;
}
JSONRuntimeDebugContainer jsonRuntimeDebugContainer=null;
GameObject jsonDebugObject=GameObject.Find("TotalJSON_DebugObject");
if (jsonDebugObject!=null) {
jsonRuntimeDebugContainer=jsonDebugObject.GetComponent<JSONRuntimeDebugContainer>();
}
if (jsonRuntimeDebugContainer==null) {
GUILayout.Label("Application is running but no JSON objects are added to debug.");
latestObjects=null;
return;
}
GUILayout.Label("Application is running, choose object below to show.");
if (latestObjects==null) {
latestObjects=new List<DebugObject>();
}
Dictionary<string,JValue> currentContent=jsonRuntimeDebugContainer.getContent();
foreach (string key in currentContent.Keys) {
int listIndex=getDebugObjectIndex(key);
if (listIndex>=0) {
if (latestObjects[listIndex].getValue()!=currentContent[key]) {
latestObjects[listIndex].replace(currentContent[key]);
}
} else {
latestObjects.Add(new DebugObject(key,currentContent[key]));
}
}
outputLatestContent();
}
private int getDebugObjectIndex(string key) {
for (int n=0; n<latestObjects.Count; n++) {
if (latestObjects[n].getKey().Equals(key)) {
return n;
}
}
return -1;
}
private void outputLatestContent() {
GUILayout.Space(10);
int count=latestObjects.Count;
string[] keys=new string[latestObjects.Count];
for (int n=0; n<count; n++) {
keys[n]=latestObjects[n].getKey();
}
int newSelected=GUILayout.Toolbar(selected,keys);
if (newSelected!=selected) {
selected=newSelected;
GUIUtility.keyboardControl=0;
GUIUtility.hotControl=0;
}
GUILayout.Space(10);
EditorGUILayout.BeginHorizontal();
GUILayout.Label(latestObjects[selected].getInfoString());
if (Application.isPlaying) {
GUILayout.FlexibleSpace();
if (GUILayout.Button("Refresh")) {
latestObjects[selected].refresh();
Repaint();
}
}
EditorGUILayout.EndHorizontal();
GUILayout.Space(5);
latestObjects[selected].scrollPos = EditorGUILayout.BeginScrollView(latestObjects[selected].scrollPos);
EditorGUILayout.TextArea(latestObjects[selected].getContentString(),GUILayout.ExpandHeight(true));
EditorGUILayout.EndScrollView();
}
private class DebugObject {
private string key;
private JValue value;
internal Vector2 scrollPos;
private string infoString;
private string contentString;
internal DebugObject(string key, JValue value) {
this.key=key;
this.value=value;
refresh();
}
internal void replace(JValue value) {
this.value=value;
refresh();
}
internal void refresh() {
scrollPos=Vector2.zero;
infoString=null;
contentString=null;
}
internal string getKey() {
return key;
}
internal JValue getValue() {
return value;
}
internal string getInfoString() {
if (infoString==null) {
infoString=value.ToString();
if (isProtected()) {
infoString+=" -- This object is set protected (read only)";
}
}
return infoString;
}
internal string getContentString() {
if (contentString==null) {
contentString=value.CreateString(new CreateStringSettings() { HumanReadable=true });
}
return contentString;
}
private bool isProtected() {
if (value is JSON) {
return ((JSON)(value)).IsProtected();
}
if (value is JArray) {
return ((JArray)(value)).IsProtected();
}
return false;
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: dd472f7a2d8907c4fa13cc27c68a39f4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,192 @@
// JSONValidator
using UnityEngine;
using UnityEditor;
using System;
using System.Text;
using Leguar.TotalJSON;
namespace Leguar.TotalJSON.Internal {
public class JSONValidator : EditorWindow {
private string editorAreaText="Write or copy&paste JSON object or JSON array to this text area. Example JSON:\n\n{\"name\":\"Player\",\"lastLogin\":123456789012,\"achievements\":[42,1337,1703],\"imageUrl\":null,\"have_bought\":true,\"levels\":[{\"passed\":true,\"score\":12345},{\"passed\":false}]}\n\nExtra texts like this before or after JSON object will be removed when clicking button below.";
private string message="";
private string tightJSON="";
private string escapedJSON="";
private Vector2 scrollPos;
private float lineHeight=EditorGUIUtility.singleLineHeight;
[MenuItem("Window/Total JSON/JSON Validator")]
static void Init() {
JSONValidator window=(JSONValidator)(GetWindow(typeof(JSONValidator)));
#if UNITY_5 || UNITY_2017
window.titleContent = new GUIContent("JSON Validator");
#else
Texture2D icon = (Texture2D)(AssetDatabase.LoadAssetAtPath("Assets/TotalJSON/Internal/Editor/window-icon.png", typeof(Texture2D)));
window.titleContent = new GUIContent("JSON Validator",icon);
#endif
}
void OnGUI() {
GUILayout.Space(20);
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
EditorGUI.BeginChangeCheck();
editorAreaText = EditorGUILayout.TextArea(editorAreaText,GUILayout.ExpandHeight(true));
bool changes = EditorGUI.EndChangeCheck();
EditorGUILayout.EndScrollView();
if (changes) {
message = "";
tightJSON = "";
escapedJSON = "";
}
GUILayout.Space(10);
if (GUILayout.Button("Trim, validate and prettify above JSON object or array")) {
string trimmedEditorText=editorAreaText.Trim();
if (trimmedEditorText.Length<editorAreaText.Length) {
editorAreaText=trimmedEditorText; // Needed in case of errors, so that line numbers will match
GUIUtility.keyboardControl=0;
GUIUtility.hotControl=0;
EditorUtility.SetDirty(this);
}
if (string.IsNullOrEmpty(trimmedEditorText)) {
message = "Input is empty";
tightJSON = "";
escapedJSON = "";
} else {
object objectOrError = findAndGetJSONOrJArray(trimmedEditorText);
if (objectOrError==null) {
message = "Can't find JSON start from input";
tightJSON = "";
escapedJSON = "";
} else if (objectOrError is string) {
message = "Invalid input: "+((string)(objectOrError));
tightJSON = "";
escapedJSON = "";
} else {
CreateStringSettings prettySettings=new CreateStringSettings() {
HumanReadable=true,
IndentUsingTab=true,
NewLine=CreateStringSettings.NewLineTypes.LF // \r characters (may be part of environment default) seem to be problem in editor textarea, causing invisible linefeeds, so using plain \n
};
if (objectOrError is JSON[]) {
JSON[] jsons = (JSON[])(objectOrError);
if (jsons.Length==1) {
message = "JSON is valid. Top level JSON key/value pair count = "+jsons[0].Count;
editorAreaText = jsons[0].CreateString(prettySettings)+"\n";
tightJSON = jsons[0].CreateString(new CreateStringSettings() { HumanReadable = false });
escapedJSON = "\""+getEscapedString(tightJSON)+"\"";
} else {
message = "JSONs are valid. JSON object count = "+jsons.Length;
editorAreaText = "";
tightJSON = "";
for (int n = 0; n<jsons.Length; n++) {
editorAreaText += jsons[n].CreateString(prettySettings)+"\n";
if (n<jsons.Length-1) {
editorAreaText += '\n';
}
tightJSON += jsons[n].CreateString(new CreateStringSettings() { HumanReadable = false });
}
escapedJSON = "\""+getEscapedString(tightJSON)+"\"";
}
} else {
JArray jArray = (JArray)(objectOrError);
message = "JSON Array is valid. Top level array length = "+jArray.Length;
editorAreaText = jArray.CreateString(prettySettings)+"\n";
tightJSON = jArray.CreateString(new CreateStringSettings() { HumanReadable = false });
escapedJSON = "\""+getEscapedString(tightJSON)+"\"";
}
GUIUtility.keyboardControl=0;
GUIUtility.hotControl=0;
EditorUtility.SetDirty(this);
}
}
}
GUILayout.Space(20);
GUILayout.Label(message);
GUILayout.Space(20);
EditorGUI.BeginDisabledGroup(tightJSON.Length==0);
GUILayout.Label("JSON formatted and encoded string ("+tightJSON.Length+" bytes):");
GUILayout.Space(5);
EditorGUILayout.SelectableLabel(tightJSON,EditorStyles.textField,GUILayout.Height(lineHeight+2));
GUILayout.Space(15);
GUILayout.Label("Above string with escapes (to be used for example directly in c# source code):");
GUILayout.Space(5);
EditorGUILayout.SelectableLabel(escapedJSON,EditorStyles.textField,GUILayout.Height(lineHeight+2));
GUILayout.Space(20);
EditorGUI.EndDisabledGroup();
}
private object findAndGetJSONOrJArray(string dirtySourceString) {
// Remove any heading "trash", for example in case that JSON is pasted from Unity Console
int jsonStartIndex=dirtySourceString.IndexOf('{');
int jArrayStartIndex=dirtySourceString.IndexOf('[');
// Debug.Log("jsonStartIndex = "+jsonStartIndex);
// Debug.Log("jArrayStartIndex = "+jArrayStartIndex);
// Nothing?
if (jsonStartIndex<0 && jArrayStartIndex<0) {
return null;
}
// Try parse array
if (jArrayStartIndex>=0 && (jArrayStartIndex<jsonStartIndex || jsonStartIndex<0)) {
try {
return JArray.ParseString(dirtySourceString,new ParseStringSettings(){ ParseStartIndex=jArrayStartIndex, AllowNonWhiteCharactersAfterObject=true });
}
catch (ParseException e) {
if (jsonStartIndex<0) {
return e.Message;
}
}
}
// Parse one or more JSONs
try {
return JSON.ParseStringToMultiple(dirtySourceString,new ParseStringSettings(){ ParseStartIndex=jsonStartIndex, AllowNonWhiteCharactersAfterObject=true });
}
catch (ParseException e) {
return e.Message;
}
}
private static string getEscapedString(string source) {
int length=source.Length;
StringBuilder sb=new StringBuilder(length);
for (int n=0; n<length; n++) {
if (source[n]=='"') {
sb.Append('\\');
sb.Append('"');
} else if (source[n]=='\\') {
sb.Append('\\');
sb.Append('\\');
} else {
sb.Append(source[n]);
}
}
return sb.ToString();
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9a3e3d053758ae04d8a800e805da99ba
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

View File

@@ -0,0 +1,123 @@
fileFormatVersion: 2
guid: 7de077ad9b723ed40b5ae6d8a8320274
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 32
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 16
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant: