public ObjectValue[] GetChildren(ObjectPath path, int index, int count, IEvaluationOptions options) { try { return(GetChildrenSafe(path, index, count, options)); } catch (Exception e) { myLogger.Error(e); } return(EmptyArray <ObjectValue> .Instance); }
protected override ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count, IEvaluationOptions options) { // Call gameObject.GetComponents(typeof(Component)) var componentType = GetType("UnityEngine.Component"); var typeofComponent = Adaptor.CreateTypeObject(Context, componentType); var componentsArray = InvokeInstanceMethod(myGameObject, "GetComponents", typeofComponent) as ArrayMirror; if (componentsArray == null) { ourLogger.Warn("UnityEngine.Component.GetComponents did not return an instance of ArrayMirror"); return(EmptyArray <ObjectValue> .Instance); } // Component name comes from ObjectNames.GetInspectorTitle(component) var objectNamesType = GetType("UnityEditor.ObjectNames"); var objectValues = new List <ObjectValue>(componentsArray.Length); foreach (var componentValue in componentsArray.GetValues(0, componentsArray.Length)) { try { var name = GetComponentName(objectNamesType, componentValue); objectValues.Add(CreateObjectValue(name, componentValue, options)); } catch (Exception e) { ourLogger.Error(e, "Failed to fetch component {0} of GameObject {1}", componentValue, myGameObject); } } return(objectValues.ToArray()); }
protected override ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count, IEvaluationOptions options) { // Calls scene.GetRootGameObjects (will only be available in Unity 5.3.2 and above) var gameObjects = InvokeInstanceMethod(myScene, "GetRootGameObjects") as ArrayMirror; if (gameObjects == null) { return(EmptyArray <ObjectValue> .Instance); } var objectValues = new List <ObjectValue>(gameObjects.Length); foreach (Value gameObject in gameObjects) { var name = (GetMember(gameObject, "name") as StringMirror)?.Value ?? "GameObject"; objectValues.Add(CreateObjectValue(name, gameObject, options)); } return(objectValues.ToArray()); }
public void SetRawValue(ObjectPath path, IRawValue value, IEvaluationOptions options) { throw new NotSupportedException(); }
public ObjectValue GetValue(ObjectPath path, IEvaluationOptions options) { throw new NotSupportedException(); }
public ValuePresentation SetValue(ObjectPath path, string value, IEvaluationOptions options) { throw new NotSupportedException(); }
protected abstract ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count, IEvaluationOptions options);
protected ObjectValue CreateObjectValue(string name, Value value, IEvaluationOptions options) { return(LiteralValueReference.CreateTargetObjectLiteral(Adaptor, Context, name, value) .CreateObjectValue(options)); }
protected override ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count, IEvaluationOptions options) { // Get the children of the current game object, as seen in the Hierarchy view in the Unity Editor // These are the children of the current game object's transform property var transform = GetMember(myGameObject, "transform"); if (transform == null) { return(EmptyArray <ObjectValue> .Instance); } var childCountValue = (PrimitiveValue)GetMember(transform, "childCount"); if (childCountValue == null) { return(EmptyArray <ObjectValue> .Instance); } var childCount = (int)childCountValue.Value; var objectValues = new List <ObjectValue>(childCount); for (var i = 0; i < childCount; i++) { var currentIndex = Adaptor.CreateValue(Context, i); var child = InvokeInstanceMethod(transform, "GetChild", currentIndex); if (child != null) { var childGameObject = GetMember(child, "gameObject"); if (childGameObject != null) { var name = (GetMember(childGameObject, "name") as StringMirror)?.Value ?? "GameObject"; objectValues.Add(CreateObjectValue(name, childGameObject, options)); } } } return(objectValues.ToArray()); }
protected override ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count, IEvaluationOptions options) { var allocatorTempObject = Evaluate("global::Unity.Collections.Allocator.Temp"); var componentDataType = GetType("Unity.Entities.IComponentData").NotNull(); var sharedComponentDataType = GetType("Unity.Entities.ISharedComponentData").NotNull(); var entityManagerGetComponentTypesMethod = myEntityManagerType.GetMethod("GetComponentTypes"); var entityManagerGetSharedComponentDataMethod = myEntityManagerType.GetMethod("GetSharedComponentData"); var entityManagerGetComponentDataMethod = myEntityManagerType.GetMethod("GetComponentData"); var componentTypesArray = Invoke(entityManagerGetComponentTypesMethod, myEntityManagerType, myEntityManagerObject, myEntityObject, allocatorTempObject.Value).NotNull(); var componentTypesArrayLength = (PrimitiveValue)Adaptor.GetMember(Context, null, componentTypesArray, "Length").Value; var numberOfComponentTypes = (int)componentTypesArrayLength.Value; var objectValues = new List <ObjectValue>(); for (var currentIndex = 0; currentIndex < numberOfComponentTypes; currentIndex++) { try { var currentIndexValue = Adaptor.CreateValue(Context, currentIndex); var currentComponent = Adaptor .GetIndexerReference(Context, componentTypesArray, new[] { currentIndexValue }).Value; var currentComponentType = currentComponent.Type; var getManagedTypeMethod = currentComponentType.GetMethod("GetManagedType"); var dataManagedType = Invoke(getManagedTypeMethod, currentComponentType, currentComponent); var dataManagedTypeFullName = ((StringMirror)Adaptor.GetMember(Context, null, dataManagedType, "FullName").Value).Value; var dataManagedTypeShortName = ((StringMirror)Adaptor.GetMember(Context, null, dataManagedType, "Name").Value).Value; var dataType = GetType(dataManagedTypeFullName); MethodMirror getComponentDataMethod; if (componentDataType.IsAssignableFrom(dataType)) { getComponentDataMethod = entityManagerGetComponentDataMethod; } else if (sharedComponentDataType.IsAssignableFrom(dataType)) { getComponentDataMethod = entityManagerGetSharedComponentDataMethod; } else { ourLogger.Warn("Unknown type of component data: {0}", dataManagedTypeFullName); continue; } var getComponentDataMethodWithTypeArgs = getComponentDataMethod.MakeGenericMethod(new[] { dataType }); var result = Invoke(getComponentDataMethodWithTypeArgs, myEntityManagerType, myEntityManagerObject, myEntityObject); objectValues.Add(LiteralValueReference .CreateTargetObjectLiteral(Adaptor, Context, dataManagedTypeShortName, result) .CreateObjectValue(options)); } catch (Exception e) { ourLogger.Error(e, "Failed to fetch parameter {0} of entity {1}", currentIndex, myEntityObject); } } return(objectValues.ToArray()); }