Skip to content

Commit 92df455

Browse files
committed
Update with docs and fix
1 parent 9fdbd06 commit 92df455

49 files changed

Lines changed: 1273 additions & 952 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MCPForUnity/Editor/Helpers/ComponentOps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private static bool SetObjectReference(SerializedProperty prop, JToken value, ou
564564
if (value.Type == JTokenType.Integer)
565565
{
566566
int id = value.Value<int>();
567-
var resolved = EditorUtility.InstanceIDToObject(id);
567+
var resolved = EditorUtility.EntityIdToObject(id);
568568
if (resolved == null)
569569
{
570570
error = $"No object found with instanceID {id}.";
@@ -580,7 +580,7 @@ private static bool SetObjectReference(SerializedProperty prop, JToken value, ou
580580
if (idToken != null)
581581
{
582582
int id = ParamCoercion.CoerceInt(idToken, 0);
583-
var resolved = EditorUtility.InstanceIDToObject(id);
583+
var resolved = EditorUtility.EntityIdToObject(id);
584584
if (resolved == null)
585585
{
586586
error = $"No object found with instanceID {id}.";

MCPForUnity/Editor/Resources/Editor/Selection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static object HandleCommand(JObject @params)
2121
activeObject = UnityEditor.Selection.activeObject?.name,
2222
activeGameObject = UnityEditor.Selection.activeGameObject?.name,
2323
activeTransform = UnityEditor.Selection.activeTransform?.name,
24-
activeInstanceID = UnityEditor.Selection.activeInstanceID,
24+
activeInstanceID = UnityEditor.Selection.activeObject?.GetInstanceID() ?? 0,
2525
count = UnityEditor.Selection.count,
2626
objects = UnityEditor.Selection.objects
2727
.Select(obj => new

MCPForUnity/Editor/Resources/Scene/GameObjectResource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static object HandleCommand(JObject @params)
4444

4545
try
4646
{
47-
var go = EditorUtility.InstanceIDToObject(instanceID.Value) as GameObject;
47+
var go = EditorUtility.EntityIdToObject(instanceID.Value) as GameObject;
4848
if (go == null)
4949
{
5050
return new ErrorResponse($"GameObject with instance ID {instanceID} not found.");
@@ -150,7 +150,7 @@ public static object HandleCommand(JObject @params)
150150

151151
try
152152
{
153-
var go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
153+
var go = EditorUtility.EntityIdToObject(instanceID) as GameObject;
154154
if (go == null)
155155
{
156156
return new ErrorResponse($"GameObject with instance ID {instanceID} not found.");
@@ -235,7 +235,7 @@ public static object HandleCommand(JObject @params)
235235

236236
try
237237
{
238-
var go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
238+
var go = EditorUtility.EntityIdToObject(instanceID) as GameObject;
239239
if (go == null)
240240
{
241241
return new ErrorResponse($"GameObject with instance ID {instanceID} not found.");

MCPForUnity/Editor/Resources/Scene/RendererFeaturesResource.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCPForUnity/Editor/Resources/Scene/RenderingStatsResource.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCPForUnity/Editor/Resources/Scene/VolumesResource.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCPForUnity/Editor/Tools/Cameras/CameraControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ internal static class CameraControl
1313
{
1414
internal static object ListCameras(JObject @params)
1515
{
16-
var unityCameras = UnityEngine.Object.FindObjectsOfType<UnityEngine.Camera>();
16+
var unityCameras = UnityEngine.Object.FindObjectsByType<UnityEngine.Camera>(FindObjectsSortMode.None);
1717
var cameraList = new List<object>();
1818
var unityCamList = new List<object>();
1919

2020
// Cinemachine cameras
2121
if (CameraHelpers.HasCinemachine)
2222
{
2323
var cmType = CameraHelpers.CinemachineCameraType;
24-
var allCm = UnityEngine.Object.FindObjectsOfType(cmType);
24+
var allCm = UnityEngine.Object.FindObjectsByType(cmType, FindObjectsSortMode.None);
2525
foreach (Component cm in allCm)
2626
{
2727
var follow = CameraHelpers.GetReflectionProperty(cm, "Follow") as Transform;

MCPForUnity/Editor/Tools/Cameras/CameraHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ internal static Component FindBrain()
141141
if (!HasCinemachine || _cmBrainType == null)
142142
return null;
143143

144-
return UnityEngine.Object.FindObjectOfType(_cmBrainType) as Component;
144+
return UnityEngine.Object.FindFirstObjectByType(_cmBrainType) as Component;
145145
}
146146

147147
internal static UnityEngine.Camera FindMainCamera()
148148
{
149149
var main = UnityEngine.Camera.main;
150150
if (main != null) return main;
151151

152-
var allCams = UnityEngine.Object.FindObjectsOfType<UnityEngine.Camera>();
152+
var allCams = UnityEngine.Object.FindObjectsByType<UnityEngine.Camera>(FindObjectsSortMode.None);
153153
return allCams.Length > 0 ? allCams[0] : null;
154154
}
155155

MCPForUnity/Editor/Tools/Graphics.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCPForUnity/Editor/Tools/Graphics/GraphicsHelpers.cs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ internal static Component FindVolume(JObject @params)
127127
string target = p.Get("target");
128128
if (string.IsNullOrEmpty(target))
129129
{
130-
var allVolumes = UnityEngine.Object.FindObjectsOfType(VolumeType);
130+
var allVolumes = UnityEngine.Object.FindObjectsByType(VolumeType, FindObjectsSortMode.None);
131131
return allVolumes.Length > 0 ? allVolumes[0] as Component : null;
132132
}
133133

134134
if (int.TryParse(target, out int instanceId))
135135
{
136-
var byId = EditorUtility.InstanceIDToObject(instanceId) as GameObject;
136+
var byId = EditorUtility.EntityIdToObject(instanceId) as GameObject;
137137
if (byId != null) return byId.GetComponent(VolumeType);
138138
}
139139

@@ -155,6 +155,84 @@ internal static string GetPipelineName()
155155
};
156156
}
157157

158+
internal static object ReadSerializedValue(SerializedProperty prop)
159+
{
160+
return prop.propertyType switch
161+
{
162+
SerializedPropertyType.Boolean => prop.boolValue,
163+
SerializedPropertyType.Integer => prop.intValue,
164+
SerializedPropertyType.Float => prop.floatValue,
165+
SerializedPropertyType.String => prop.stringValue,
166+
SerializedPropertyType.Enum => prop.enumValueIndex < prop.enumNames.Length
167+
? prop.enumNames[prop.enumValueIndex]
168+
: (object)prop.enumValueIndex,
169+
SerializedPropertyType.ObjectReference => prop.objectReferenceValue != null
170+
? prop.objectReferenceValue.name
171+
: null,
172+
SerializedPropertyType.Color => $"({prop.colorValue.r:F2}, {prop.colorValue.g:F2}, {prop.colorValue.b:F2}, {prop.colorValue.a:F2})",
173+
SerializedPropertyType.Vector2 => new { x = prop.vector2Value.x, y = prop.vector2Value.y },
174+
SerializedPropertyType.Vector3 => new { x = prop.vector3Value.x, y = prop.vector3Value.y, z = prop.vector3Value.z },
175+
SerializedPropertyType.LayerMask => prop.intValue,
176+
_ => prop.propertyType.ToString()
177+
};
178+
}
179+
180+
internal static bool SetSerializedValue(SerializedProperty prop, JToken value)
181+
{
182+
try
183+
{
184+
switch (prop.propertyType)
185+
{
186+
case SerializedPropertyType.Boolean:
187+
prop.boolValue = ParamCoercion.CoerceBool(value, false);
188+
return true;
189+
case SerializedPropertyType.Integer:
190+
prop.intValue = ParamCoercion.CoerceInt(value, 0);
191+
return true;
192+
case SerializedPropertyType.Float:
193+
prop.floatValue = ParamCoercion.CoerceFloat(value, 0f);
194+
return true;
195+
case SerializedPropertyType.String:
196+
prop.stringValue = value.ToString();
197+
return true;
198+
case SerializedPropertyType.Enum:
199+
if (value.Type == JTokenType.String)
200+
{
201+
for (int i = 0; i < prop.enumNames.Length; i++)
202+
{
203+
if (string.Equals(prop.enumNames[i], value.ToString(), StringComparison.OrdinalIgnoreCase))
204+
{ prop.enumValueIndex = i; return true; }
205+
}
206+
}
207+
prop.enumValueIndex = ParamCoercion.CoerceInt(value, 0);
208+
return true;
209+
case SerializedPropertyType.ObjectReference:
210+
if (value.Type == JTokenType.String)
211+
{
212+
string path = value.ToString();
213+
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path);
214+
if (asset != null) { prop.objectReferenceValue = asset; return true; }
215+
}
216+
return false;
217+
case SerializedPropertyType.Color:
218+
if (value is JArray colorArr && colorArr.Count >= 3)
219+
{
220+
prop.colorValue = new Color(
221+
(float)colorArr[0], (float)colorArr[1], (float)colorArr[2],
222+
colorArr.Count >= 4 ? (float)colorArr[3] : 1f);
223+
return true;
224+
}
225+
return false;
226+
case SerializedPropertyType.LayerMask:
227+
prop.intValue = ParamCoercion.CoerceInt(value, 0);
228+
return true;
229+
default:
230+
return false;
231+
}
232+
}
233+
catch { return false; }
234+
}
235+
158236
internal static void MarkDirty(UnityEngine.Object obj)
159237
{
160238
if (obj == null) return;

0 commit comments

Comments
 (0)