using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.IO;
using Newtonsoft.Json;
namespace SynapticPro
{
///
/// Unity project state inspection and reporting class
/// Enables AI to understand current implementation status
///
public static class NexusStateInspector
{
///
/// Get scene information
///
public static string GetSceneInformation(bool includeHierarchy = true, int maxDepth = 3)
{
var scene = SceneManager.GetActiveScene();
var info = new System.Text.StringBuilder();
info.AppendLine($"š¬ Scene Information");
info.AppendLine($"Name: {scene.name}");
info.AppendLine($"Path: {scene.path}");
info.AppendLine($"Build Index: {scene.buildIndex}");
var rootObjects = scene.GetRootGameObjects();
info.AppendLine($"Root GameObject Count: {rootObjects.Length}");
if (includeHierarchy)
{
info.AppendLine("\nš Hierarchy Structure:");
foreach (var root in rootObjects)
{
info.Append(GetGameObjectHierarchy(root, 0, maxDepth));
}
}
return info.ToString();
}
///
/// Get GameObject details
///
public static string GetGameObjectDetails(string name)
{
var obj = GameObject.Find(name);
if (obj == null) return $"ā GameObject '{name}' not found";
var info = new System.Text.StringBuilder();
info.AppendLine($"šÆ GameObject Details: {obj.name}");
info.AppendLine($"Path: {GetFullPath(obj)}");
info.AppendLine($"Tag: {obj.tag}");
info.AppendLine($"Layer: {LayerMask.LayerToName(obj.layer)} ({obj.layer})");
info.AppendLine($"Active: {obj.activeSelf}");
info.AppendLine($"Static: {obj.isStatic}");
var transform = obj.transform;
info.AppendLine($"\nš Transform:");
info.AppendLine($" Position: {transform.position}");
info.AppendLine($" Rotation: {transform.rotation.eulerAngles}");
info.AppendLine($" Scale: {transform.localScale}");
info.AppendLine($" Child Count: {transform.childCount}");
info.AppendLine($"\nš§ Components:");
var components = obj.GetComponents();
foreach (var comp in components)
{
if (comp == null) continue;
var compType = comp.GetType();
info.AppendLine($" ⢠{compType.Name}");
// Details of major components
if (comp is Rigidbody rb)
{
info.AppendLine($" - Mass: {rb.mass}");
info.AppendLine($" - Use Gravity: {rb.useGravity}");
info.AppendLine($" - Kinematic: {rb.isKinematic}");
}
else if (comp is Collider col)
{
info.AppendLine($" - Trigger: {col.isTrigger}");
info.AppendLine($" - Enabled: {col.enabled}");
}
else if (comp is Renderer rend)
{
info.AppendLine($" - Material Count: {rend.sharedMaterials.Length}");
info.AppendLine($" - Enabled: {rend.enabled}");
}
}
return info.ToString();
}
///
/// Get project asset information
///
public static string GetProjectAssets(string assetType = "all", string folder = "Assets")
{
var info = new System.Text.StringBuilder();
info.AppendLine($"š Asset Information ({folder})");
string searchFilter = assetType switch
{
"scripts" => "t:MonoScript",
"prefabs" => "t:Prefab",
"materials" => "t:Material",
"textures" => "t:Texture2D",
"audio" => "t:AudioClip",
_ => ""
};
string[] guids = AssetDatabase.FindAssets(searchFilter, new[] { folder });
var assetsByType = new Dictionary>();
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
var type = AssetDatabase.GetMainAssetTypeAtPath(path);
string typeName = type?.Name ?? "Unknown";
if (!assetsByType.ContainsKey(typeName))
assetsByType[typeName] = new List();
assetsByType[typeName].Add(Path.GetFileName(path));
}
foreach (var kvp in assetsByType.OrderBy(k => k.Key))
{
info.AppendLine($"\n{kvp.Key} ({kvp.Value.Count} items):");
foreach (var asset in kvp.Value.Take(10))
{
info.AppendLine($" - {asset}");
}
if (kvp.Value.Count > 10)
{
info.AppendLine($" ... {kvp.Value.Count - 10} more");
}
}
return info.ToString();
}
///
/// Get overall project statistics
///
public static string GetProjectStatistics()
{
try
{
// Scene statistics
var scene = SceneManager.GetActiveScene();
var allGameObjects = GameObject.FindObjectsOfType();
// Component statistics
var componentCounts = new Dictionary();
foreach (var go in allGameObjects)
{
foreach (var comp in go.GetComponents())
{
if (comp == null) continue;
string typeName = comp.GetType().Name;
componentCounts[typeName] = componentCounts.GetValueOrDefault(typeName, 0) + 1;
}
}
// Asset statistics
string[] allAssets = AssetDatabase.FindAssets("");
var scripts = allAssets.Count(g => AssetDatabase.GUIDToAssetPath(g).EndsWith(".cs"));
var prefabs = allAssets.Count(g => AssetDatabase.GUIDToAssetPath(g).EndsWith(".prefab"));
var materials = allAssets.Count(g => AssetDatabase.GUIDToAssetPath(g).EndsWith(".mat"));
var textures = allAssets.Count(g => AssetDatabase.GUIDToAssetPath(g).EndsWith(".png") ||
AssetDatabase.GUIDToAssetPath(g).EndsWith(".jpg"));
// Nexus-created objects
var nexusCreated = allGameObjects.Where(go => go.name.Contains("Nexus_") ||
go.name.Contains("HelloWorld") ||
go.name.Contains("UI")).ToList();
var statistics = new Dictionary
{
["scene_info"] = new Dictionary
{
["name"] = scene.name,
["path"] = scene.path,
["is_loaded"] = scene.isLoaded,
["is_dirty"] = scene.isDirty
},
["gameobject_statistics"] = new Dictionary
{
["total_count"] = allGameObjects.Length,
["active_count"] = allGameObjects.Count(go => go.activeInHierarchy),
["inactive_count"] = allGameObjects.Count(go => !go.activeInHierarchy)
},
["component_statistics"] = componentCounts.OrderByDescending(k => k.Value).Take(10).ToDictionary(k => k.Key, k => k.Value),
["asset_statistics"] = new Dictionary
{
["total_assets"] = allAssets.Length,
["scripts"] = scripts,
["prefabs"] = prefabs,
["materials"] = materials,
["textures"] = textures
},
["nexus_created_objects"] = nexusCreated.Take(10).Select(obj => new Dictionary
{
["name"] = obj.name,
["type"] = obj.GetType().Name,
["active"] = obj.activeInHierarchy,
["tag"] = obj.tag,
["layer"] = obj.layer
}).ToList()
};
return JsonConvert.SerializeObject(statistics, Formatting.Indented);
}
catch (System.Exception e)
{
return $"Error getting project statistics: {e.Message}";
}
}
///
/// Get camera information
///
public static string GetCameraInformation()
{
try
{
var cameras = GameObject.FindObjectsOfType();
var mainCam = Camera.main;
var cameraInfo = new Dictionary
{
["camera_count"] = cameras.Length,
["main_camera"] = mainCam != null ? mainCam.name : null,
["cameras"] = cameras.Select(cam => new Dictionary
{
["name"] = cam.name,
["enabled"] = cam.enabled,
["transform"] = new Dictionary
{
["position"] = new Dictionary
{
["x"] = cam.transform.position.x,
["y"] = cam.transform.position.y,
["z"] = cam.transform.position.z
},
["rotation"] = new Dictionary
{
["x"] = cam.transform.rotation.eulerAngles.x,
["y"] = cam.transform.rotation.eulerAngles.y,
["z"] = cam.transform.rotation.eulerAngles.z
}
},
["camera_settings"] = new Dictionary
{
["field_of_view"] = cam.fieldOfView,
["orthographic"] = cam.orthographic,
["orthographic_size"] = cam.orthographic ? cam.orthographicSize : null,
["depth"] = cam.depth,
["culling_mask"] = cam.cullingMask,
["background_color"] = new Dictionary
{
["r"] = cam.backgroundColor.r,
["g"] = cam.backgroundColor.g,
["b"] = cam.backgroundColor.b,
["a"] = cam.backgroundColor.a
},
["clear_flags"] = cam.clearFlags.ToString(),
["near_clip_plane"] = cam.nearClipPlane,
["far_clip_plane"] = cam.farClipPlane
},
["render_settings"] = new Dictionary
{
["render_texture"] = cam.targetTexture != null ? cam.targetTexture.name : null,
["allow_hdr"] = cam.allowHDR,
["allow_msaa"] = cam.allowMSAA,
["use_physical_properties"] = cam.usePhysicalProperties
},
["has_post_process"] = cam.GetComponent("PostProcessVolume") != null
}).ToList()
};
return JsonConvert.SerializeObject(cameraInfo, Formatting.Indented);
}
catch (System.Exception e)
{
return $"Error getting camera information: {e.Message}";
}
}
///
/// Get terrain information
///
public static string GetTerrainInformation()
{
try
{
var terrains = GameObject.FindObjectsOfType();
var terrainInfo = new Dictionary
{
["terrain_count"] = terrains.Length,
["terrains"] = terrains.Select(terrain => {
var data = terrain.terrainData;
return new Dictionary
{
["name"] = terrain.name,
["position"] = new Dictionary
{
["x"] = terrain.transform.position.x,
["y"] = terrain.transform.position.y,
["z"] = terrain.transform.position.z
},
["terrain_data"] = new Dictionary
{
["size"] = new Dictionary
{
["x"] = data.size.x,
["y"] = data.size.y,
["z"] = data.size.z
},
["heightmap_resolution"] = data.heightmapResolution,
["detail_resolution"] = data.detailResolution,
["alphamap_resolution"] = data.alphamapResolution,
["base_map_resolution"] = data.baseMapResolution
},
["terrain_layers"] = new Dictionary
{
["count"] = data.terrainLayers?.Length ?? 0,
["layers"] = data.terrainLayers != null ?
data.terrainLayers.Take(5).Where(layer => layer != null).Select(layer => new Dictionary
{
["name"] = layer.name,
["diffuse_texture"] = layer.diffuseTexture?.name,
["normal_map"] = layer.normalMapTexture?.name,
["tile_size"] = new Dictionary
{
["x"] = layer.tileSize.x,
["y"] = layer.tileSize.y
}
}).ToList() : new List>()
},
["vegetation"] = new Dictionary
{
["tree_prototype_count"] = data.treePrototypes?.Length ?? 0,
["detail_prototype_count"] = data.detailPrototypes?.Length ?? 0,
["tree_instances"] = data.treeInstanceCount
},
["settings"] = new Dictionary
{
["pixel_error"] = terrain.heightmapPixelError,
["base_map_distance"] = terrain.basemapDistance,
["detail_object_distance"] = terrain.detailObjectDistance,
["tree_distance"] = terrain.treeDistance,
["tree_billboard_distance"] = terrain.treeBillboardDistance
}
};
}).ToList()
};
return JsonConvert.SerializeObject(terrainInfo, Formatting.Indented);
}
catch (System.Exception e)
{
return $"Error getting terrain information: {e.Message}";
}
}
///
/// Get lighting information
///
public static string GetLightingInformation()
{
try
{
var lights = GameObject.FindObjectsOfType();
var probes = GameObject.FindObjectsOfType();
var lightingInfo = new Dictionary
{
["ambient_settings"] = new Dictionary
{
["mode"] = RenderSettings.ambientMode.ToString(),
["intensity"] = RenderSettings.ambientIntensity,
["color"] = new Dictionary
{
["r"] = RenderSettings.ambientLight.r,
["g"] = RenderSettings.ambientLight.g,
["b"] = RenderSettings.ambientLight.b,
["a"] = RenderSettings.ambientLight.a
},
["skybox"] = RenderSettings.skybox != null ? RenderSettings.skybox.name : null
},
["fog_settings"] = new Dictionary
{
["enabled"] = RenderSettings.fog,
["mode"] = RenderSettings.fogMode.ToString(),
["color"] = new Dictionary
{
["r"] = RenderSettings.fogColor.r,
["g"] = RenderSettings.fogColor.g,
["b"] = RenderSettings.fogColor.b,
["a"] = RenderSettings.fogColor.a
},
["density"] = RenderSettings.fogDensity,
["start_distance"] = RenderSettings.fogStartDistance,
["end_distance"] = RenderSettings.fogEndDistance
},
["lights"] = new Dictionary
{
["count"] = lights.Length,
["light_list"] = lights.Select(light => new Dictionary
{
["name"] = light.name,
["enabled"] = light.enabled,
["type"] = light.type.ToString(),
["color"] = new Dictionary
{
["r"] = light.color.r,
["g"] = light.color.g,
["b"] = light.color.b,
["a"] = light.color.a
},
["intensity"] = light.intensity,
["range"] = light.range,
["spot_angle"] = light.spotAngle,
["shadows"] = light.shadows.ToString(),
["transform"] = light.type == LightType.Directional ?
new Dictionary
{
["rotation"] = new Dictionary
{
["x"] = light.transform.rotation.eulerAngles.x,
["y"] = light.transform.rotation.eulerAngles.y,
["z"] = light.transform.rotation.eulerAngles.z
}
} :
new Dictionary
{
["position"] = new Dictionary
{
["x"] = light.transform.position.x,
["y"] = light.transform.position.y,
["z"] = light.transform.position.z
}
}
}).ToList()
},
["reflection_probes"] = new Dictionary
{
["count"] = probes.Length,
["probes"] = probes.Select(probe => new Dictionary
{
["name"] = probe.name,
["enabled"] = probe.enabled,
["resolution"] = probe.resolution,
["hdr"] = probe.hdr,
["clear_flags"] = probe.clearFlags.ToString(),
["culling_mask"] = probe.cullingMask
}).ToList()
}
};
var settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
};
return JsonConvert.SerializeObject(lightingInfo, Formatting.Indented, settings);
}
catch (System.Exception e)
{
return $"Error getting lighting information: {e.Message}";
}
}
///
/// Get material information
///
public static string GetMaterialInformation()
{
try
{
// Materials used in scene
var renderers = GameObject.FindObjectsOfType();
var usedMaterials = new HashSet();
foreach (var renderer in renderers)
{
foreach (var mat in renderer.sharedMaterials)
{
if (mat != null)
{
usedMaterials.Add(mat);
}
}
}
// Classify by shader
var materialsByShader = usedMaterials.GroupBy(m => m.shader.name);
// Material assets in project
var materialAssets = AssetDatabase.FindAssets("t:Material");
var materialInfo = new Dictionary
{
["scene_materials"] = new Dictionary
{
["total_count"] = usedMaterials.Count,
["by_shader"] = materialsByShader.Select(group => new Dictionary
{
["shader_name"] = group.Key,
["count"] = group.Count(),
["materials"] = group.Take(5).Select(mat =>
{
var matData = new Dictionary
{
["name"] = mat.name,
["shader"] = mat.shader.name,
["render_queue"] = mat.renderQueue,
["keywords"] = mat.shaderKeywords.ToList()
};
// Color properties
if (mat.HasProperty("_Color") || mat.HasProperty("_BaseColor"))
{
var color = mat.HasProperty("_Color") ? mat.GetColor("_Color") : mat.GetColor("_BaseColor");
matData["color"] = new Dictionary
{
["r"] = color.r,
["g"] = color.g,
["b"] = color.b,
["a"] = color.a
};
}
// Texture properties
if (mat.HasProperty("_MainTex") || mat.HasProperty("_BaseMap"))
{
var tex = mat.HasProperty("_MainTex") ? mat.GetTexture("_MainTex") : mat.GetTexture("_BaseMap");
if (tex != null)
{
matData["main_texture"] = new Dictionary
{
["name"] = tex.name,
["width"] = tex.width,
["height"] = tex.height
};
}
}
// PBR properties
var pbrData = new Dictionary();
if (mat.HasProperty("_Metallic"))
{
pbrData["metallic"] = mat.GetFloat("_Metallic");
}
if (mat.HasProperty("_Glossiness"))
{
pbrData["smoothness"] = mat.GetFloat("_Glossiness");
}
else if (mat.HasProperty("_Smoothness"))
{
pbrData["smoothness"] = mat.GetFloat("_Smoothness");
}
if (mat.HasProperty("_BumpMap") || mat.HasProperty("_NormalMap"))
{
var normalMap = mat.HasProperty("_BumpMap") ? mat.GetTexture("_BumpMap") : mat.GetTexture("_NormalMap");
pbrData["has_normal_map"] = normalMap != null;
}
if (pbrData.Count > 0)
{
matData["pbr_properties"] = pbrData;
}
return matData;
}).ToList()
}).ToList()
},
["project_materials"] = new Dictionary
{
["total_count"] = materialAssets.Length,
["paths"] = materialAssets.Take(20).Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToList()
}
};
return JsonConvert.SerializeObject(materialInfo, Formatting.Indented);
}
catch (System.Exception e)
{
return $"Error getting material information: {e.Message}";
}
}
///
/// Get UI information
///
public static string GetUIInformation()
{
#if UNITY_EDITOR
try
{
var canvases = GameObject.FindObjectsOfType