Пример #1
0
            private bool TryInvokeGetIterator(IObjectValueRole <TValue> serializedObjectRole,
                                              IValueFetchOptions options,
                                              out IObjectValueRole <TValue> returnedSerializedPropertyRole)
            {
                returnedSerializedPropertyRole = null;

                var method = MetadataTypeLiteEx.LookupInstanceMethodSafe(serializedObjectRole.ReifiedType.MetadataType,
                                                                         MethodSelectors.SerializedObject_GetIterator, false);

                if (method == null)
                {
                    myLogger.Warn("Cannot find GetIterator method on SerializedObject");
                    return(false);
                }

                returnedSerializedPropertyRole = new SimpleValueReference <TValue>(
                    serializedObjectRole.CallInstanceMethod(method),
                    serializedObjectRole.ValueReference.OriginatingFrame, myValueServices.RoleFactory)
                                                 .AsObjectSafe(options);
                if (returnedSerializedPropertyRole == null)
                {
                    myLogger.Warn("Unable to invoke GetIterator");
                    return(false);
                }

                return(true);
            }
Пример #2
0
            public override IEnumerable <IValueEntity> GetChildren(IPresentationOptions options,
                                                                   CancellationToken token = new CancellationToken())
            {
                var gameObjectsArray = new SimpleValueReference <TValue>(
                    myValueRole.CallInstanceMethod(myGetRootObjectMethod),
                    myValueRole.ValueReference.OriginatingFrame, myValueServices.RoleFactory)
                                       .GetExactPrimaryRoleSafe <TValue, IArrayValueRole <TValue> >(options);

                if (gameObjectsArray == null)
                {
                    yield break;
                }

                var childReferencesEnumerator = (IChildReferencesEnumerator <TValue>)gameObjectsArray;

                foreach (var childReference in childReferencesEnumerator.GetChildReferences())
                {
                    var childRole = childReference.AsObjectSafe(options);
                    if (childRole == null)
                    {
                        continue;
                    }

                    var name = childRole.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                               ?.GetString() ?? "Game Object";
                    yield return(new NamedReferenceDecorator <TValue>(childRole.ValueReference, name,
                                                                      ValueOriginKind.Property, childRole.ReifiedType.MetadataType, myValueServices.RoleFactory)
                                 .ToValue(myValueServices));
                }
            }
            private bool TryCopySerializedProperty(IObjectValueRole <TValue> serializedPropertyRole,
                                                   IValueFetchOptions options,
                                                   out IObjectValueRole <TValue> copiedSerializedPropertyRole)
            {
                copiedSerializedPropertyRole = null;

                // Get a copy of the property, so we can call Next(true) without updating the current instance
                var copyMethod = MetadataTypeLiteEx.LookupInstanceMethodSafe(
                    mySerializedPropertyRole.ReifiedType.MetadataType,
                    MethodSelectors.SerializedProperty_Copy, false);

                if (copyMethod == null)
                {
                    myLogger.Warn("Cannot find Copy method on SerializedProperty");
                    return(false);
                }

                // CallInstanceMethod always returns not null (VoidValue if it fails)
                copiedSerializedPropertyRole = new SimpleValueReference <TValue>(
                    serializedPropertyRole.CallInstanceMethod(copyMethod),
                    mySerializedPropertyRole.ValueReference.OriginatingFrame, myValueServices.RoleFactory)
                                               .AsObjectSafe(options);
                if (copiedSerializedPropertyRole == null)
                {
                    myLogger.Warn("Unable to Copy serializedProperty");
                    return(false);
                }

                return(true);
            }
            private IEnumerable <IValueEntity> GetChildrenImpl(IPresentationOptions options, CancellationToken token)
            {
                // GameObject[] Scene.GetRootObjects()
                var gameObjectArray = new SimpleValueReference <TValue>(
                    mySceneValueRole.CallInstanceMethod(myGetRootObjectsMethod),
                    mySceneValueRole.ValueReference.OriginatingFrame, myValueServices.RoleFactory)
                                      .GetExactPrimaryRoleSafe <TValue, IArrayValueRole <TValue> >(options);

                if (gameObjectArray == null)
                {
                    myLogger.Warn("Unable to retrieve GameObject array, or unexpectedly returned null");
                    yield break;
                }

                if (options.ClusterArrays)
                {
                    var absoluteElementCount = ArrayIndexUtil.GetAbsoluteElementCount(gameObjectArray.Dimensions);
                    foreach (var valueEntity in GetChunkedChildren(gameObjectArray, 0, absoluteElementCount, options, token))
                    {
                        yield return(valueEntity);
                    }
                }
                else
                {
                    var enumerator = (IChildReferencesEnumerator <TValue>)gameObjectArray;
                    foreach (var childReference in enumerator.GetChildReferences())
                    {
                        yield return(GetElementValue(childReference, options));
                    }
                }
            }
            protected override IValue GetElementValueAt(IObjectValueRole <TValue> collection, int index, IValueFetchOptions options)
            {
                var name = $"[{index}]";

                try
                {
                    var frame      = mySerializedPropertyRole.ValueReference.OriginatingFrame;
                    var indexValue = myValueServices.ValueFactory.CreatePrimitive(frame, options, index);
                    var childSerializedPropertyValue = collection.CallInstanceMethod(myGetElementMethod, indexValue);
                    var valueReference = new SimpleValueReference <TValue>(childSerializedPropertyValue,
                                                                           mySerializedPropertyRole.ReifiedType.MetadataType, name, ValueOriginKind.ArrayElement,
                                                                           ValueFlags.None | ValueFlags.IsReadOnly, frame, myValueServices.RoleFactory);

                    // Tell the value presenter to hide the name, because it's always "data" (DefaultName is the key name)
                    // Also hide the type presentation - they can only ever be SerializedProperty instances
                    return(new CalculatedValueReferenceDecorator <TValue>(valueReference, myValueServices.RoleFactory,
                                                                          valueReference.DefaultName, false, false).ToValue(myValueServices));
                }
                catch (Exception e)
                {
                    // We must always return a value, as we're effectively showing the contents of an array here. We're
                    // possibly also being evaluated lazily, thanks to chunked arrays, so can't rely on the caller
                    // catching exceptions.
                    myLogger.LogExceptionSilently(e);
                    return(myValueServices.ValueRenderers.GetValueStubForException(e, name,
                                                                                   collection.ValueReference.OriginatingFrame) as IValue
                           ?? new ErrorValue(name, "Unable to retrieve child serialized property"));
                }
            }
Пример #6
0
            protected override IValue GetElementValueAt(IObjectValueRole <TValue> collection, int index, IValueFetchOptions options)
            {
                try
                {
                    var frame               = myGameObjectRole.ValueReference.OriginatingFrame;
                    var indexValue          = myValueServices.ValueFactory.CreatePrimitive(frame, options, index);
                    var childTransformValue = collection.CallInstanceMethod(myGetChildMethod, indexValue);
                    var childTransform      = new SimpleValueReference <TValue>(childTransformValue,
                                                                                frame, myValueServices.RoleFactory).AsObjectSafe(options);
                    var gameObject = childTransform?.GetInstancePropertyReference("gameObject", true)
                                     ?.AsObjectSafe(options);
                    if (gameObject == null)
                    {
                        return(new ErrorValue("Game Object", "Unable to find child gameObject, or value is null"));
                    }

                    var name = gameObject.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                               ?.GetString() ?? "Game Object";

                    // Tell the value presenter to not show the name field, we're already showing it as the key. Also don't
                    // show the type - a GameObject's child can only be a GameObject
                    return(new CalculatedValueReferenceDecorator <TValue>(gameObject.ValueReference,
                                                                          myValueServices.RoleFactory, name, false, false).ToValue(myValueServices));
                }
                catch (Exception e)
                {
                    // We must always return a value, as we're effectively showing the contents of an array here. We're
                    // possibly also being evaluated lazily, thanks to chunked arrays, so can't rely on the caller
                    // catching exceptions.
                    myLogger.LogExceptionSilently(e);
                    return(myValueServices.ValueRenderers.GetValueStubForException(e, "Game Object",
                                                                                   collection.ValueReference.OriginatingFrame) as IValue
                           ?? new ErrorValue("Game Object", "Unable to retrieve child game object"));
                }
            }
Пример #7
0
            public override IEnumerable <IValueEntity> GetChildren(IPresentationOptions options,
                                                                   CancellationToken token = new CancellationToken())
            {
                var frame         = myGameObjectRole.ValueReference.OriginatingFrame;
                var componentType =
                    myValueServices.TypeUniverse.GetReifiedType(frame, "UnityEngine.Component, UnityEngine.CoreModule")
                    ?? myValueServices.TypeUniverse.GetReifiedType(frame, "UnityEngine.Component, UnityEngine");

                if (componentType == null)
                {
                    yield break;
                }

                var getComponentsMethod = myGameObjectRole.ReifiedType.MetadataType.GetMethods()
                                          .FirstOrDefault(ourGetComponentsSelector);

                if (getComponentsMethod == null)
                {
                    yield break;
                }

                // Component[] GameObject.GetComponents(typeof(Component))
                var typeObject      = (IValueReference <TValue>)componentType.GetTypeObject(frame);
                var componentsArray =
                    myGameObjectRole.CallInstanceMethod(getComponentsMethod, typeObject.GetValue(options));
                var componentArray =
                    new SimpleValueReference <TValue>(componentsArray, frame, myValueServices.RoleFactory)
                    .GetExactPrimaryRoleSafe <TValue, IArrayValueRole <TValue> >(options);

                if (componentArray == null)
                {
                    yield break;
                }

                // string UnityEditor.ObjectNames.GetInspectorTitle(UnityEngine.Object)
                // Returns the name of the component, formatted the same as in the Inspector. Values are also cached per
                // type. This obviously won't be available for standalone players, where we'll display the short type
                // name instead.
                // TODO: Support extra fallback names
                // Unity doesn't use the short name, but will look at the type and use GameObject.name,
                // MonoBehaviour.GetScriptClassName and so on.
                var objectNamesType = (IReifiedType <TValue>)
                                          (myValueServices.TypeUniverse.GetReifiedType(frame, "UnityEditor.ObjectNames, UnityEditor")
                                          ?? myValueServices.TypeUniverse.GetReifiedType(frame, "UnityEditor.ObjectNames, UnityEditor.CoreModule"));
                var getInspectorTitleMethod = objectNamesType?.MetadataType.GetMethods()
                                              .FirstOrDefault(ourGetInspectorTitleSelector);

                var childReferencesEnumerator = (IChildReferencesEnumerator <TValue>)componentArray;

                foreach (var componentReference in childReferencesEnumerator.GetChildReferences())
                {
                    var componentName = GetComponentName(componentReference, objectNamesType, getInspectorTitleMethod,
                                                         frame, options, myValueServices);
                    yield return(new NamedReferenceDecorator <TValue>(componentReference, componentName,
                                                                      ValueOriginKind.ArrayElement, componentType.MetadataType, myValueServices.RoleFactory)
                                 .ToValue(myValueServices));
                }
            }
            protected override IValue GetElementValueAt(IObjectValueRole <TValue> collection, int index, IValueFetchOptions options)
            {
                var frame      = mySerializedPropertyRole.ValueReference.OriginatingFrame;
                var indexValue = myValueServices.ValueFactory.CreatePrimitive(frame, options, index);
                var childSerializedPropertyValue = collection.CallInstanceMethod(myGetElementMethod, indexValue);
                var valueReference = new SimpleValueReference <TValue>(childSerializedPropertyValue,
                                                                       mySerializedPropertyRole.ReifiedType.MetadataType, $"[{index}]", ValueOriginKind.ArrayElement,
                                                                       ValueFlags.None | ValueFlags.IsReadOnly, frame, myValueServices.RoleFactory);

                // Tell the value presenter to hide the name, because it's always "data" (DefaultName is the key name)
                // Also hide the type presentation - they can only ever be SerializedProperty instances
                return(new CalculatedValueReferenceDecorator <TValue>(valueReference, myValueServices.RoleFactory,
                                                                      valueReference.DefaultName, false, false).ToValue(myValueServices));
            }
            protected override IValue GetElementValueAt(IObjectValueRole <TValue> collection, int index, IValueFetchOptions options)
            {
                var frame               = myGameObjectRole.ValueReference.OriginatingFrame;
                var indexValue          = myValueServices.ValueFactory.CreatePrimitive(frame, options, index);
                var childTransformValue = collection.CallInstanceMethod(myGetChildMethod, indexValue);
                var childTransform      = new SimpleValueReference <TValue>(childTransformValue,
                                                                            frame, myValueServices.RoleFactory).AsObjectSafe(options);
                var gameObject = childTransform?.GetInstancePropertyReference("gameObject", true)
                                 ?.AsObjectSafe(options);
                var name = gameObject?.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                           ?.GetString() ?? "Game Object";

                return(new NamedReferenceDecorator <TValue>(gameObject.ValueReference, name,
                                                            ValueOriginKind.Property,
                                                            ValueFlags.None | ValueFlags.IsReadOnly,
                                                            myGameObjectRole.ReifiedType.MetadataType, myValueServices.RoleFactory, true)
                       .ToValue(myValueServices));
            }
            private bool TryInvokeNext(IObjectValueRole <TValue> serializedPropertyRole,
                                       IMetadataMethodLite nextMethod,
                                       TValue boolArg,
                                       IValueFetchOptions options,
                                       out bool returnValue)
            {
                returnValue = false;

                var returnValueRole = new SimpleValueReference <TValue>(
                    serializedPropertyRole.CallInstanceMethod(nextMethod, boolArg),
                    mySerializedPropertyRole.ValueReference.OriginatingFrame,
                    myValueServices.RoleFactory)
                                      .AsPrimitiveSafe(options);

                if (returnValueRole == null)
                {
                    myLogger.Warn("Unable to call Next on serializedProperty");
                    return(false);
                }

                returnValue = returnValueRole.GetPrimitive <bool>();
                return(true);
            }
Пример #11
0
            protected override IValue GetElementValueAt(IObjectValueRole <TValue> collection, int index, IValueFetchOptions options)
            {
                var frame               = myGameObjectRole.ValueReference.OriginatingFrame;
                var indexValue          = myValueServices.ValueFactory.CreatePrimitive(frame, options, index);
                var childTransformValue = collection.CallInstanceMethod(myGetChildMethod, indexValue);
                var childTransform      = new SimpleValueReference <TValue>(childTransformValue,
                                                                            frame, myValueServices.RoleFactory).AsObjectSafe(options);
                var gameObject = childTransform?.GetInstancePropertyReference("gameObject", true)
                                 ?.AsObjectSafe(options);

                if (gameObject == null)
                {
                    return(new ErrorValue("Game Object", "Unable to retrieve child game object"));
                }

                var name = gameObject.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                           ?.GetString() ?? "Game Object";

                // Tell the value presenter to not show the name field, we're already showing it as the key. Also don't
                // show the type - a GameObject's child can only be a GameObject
                return(new CalculatedValueReferenceDecorator <TValue>(gameObject.ValueReference,
                                                                      myValueServices.RoleFactory, name, false, false).ToValue(myValueServices));
            }
Пример #12
0
            private IEnumerable <IValueEntity> GetChildrenImpl(IValueFetchOptions options)
            {
                var frame         = myGameObjectRole.ValueReference.OriginatingFrame;
                var componentType =
                    myValueServices.GetReifiedType(frame, "UnityEngine.Component, UnityEngine.CoreModule")
                    ?? myValueServices.GetReifiedType(frame, "UnityEngine.Component, UnityEngine");

                if (componentType == null)
                {
                    myLogger.Warn("Unable to find UnityEngine.Component");
                    yield break;
                }

                var getComponentsMethod = myGameObjectRole.ReifiedType.MetadataType.GetMethods()
                                          .FirstOrDefault(ourGetComponentsSelector);

                if (getComponentsMethod == null)
                {
                    myLogger.Warn("Unable to find UnityEngine.GameObject.GetComponents method");
                    yield break;
                }

                // Call Component[] GameObject.GetComponents(typeof(Component))
                var typeObject      = (IValueReference <TValue>)componentType.GetTypeObject(frame);
                var componentsArray =
                    myGameObjectRole.CallInstanceMethod(getComponentsMethod, typeObject.GetValue(options));
                var componentArray =
                    new SimpleValueReference <TValue>(componentsArray, frame, myValueServices.RoleFactory)
                    .GetExactPrimaryRoleSafe <TValue, IArrayValueRole <TValue> >(options);

                if (componentArray == null)
                {
                    myLogger.Warn("Cannot get return value of GameObject.GetComponents or method returned null");
                    yield break;
                }

                // string UnityEditor.ObjectNames.GetInspectorTitle(UnityEngine.Object)
                // Returns the name of the component, formatted the same as in the Inspector. Values are also cached per
                // type. This obviously won't be available for standalone players, where we'll display the short type
                // name instead.
                // TODO: Support extra fallback names
                // Unity doesn't use the short name, but will look at the type and use GameObject.name,
                // MonoBehaviour.GetScriptClassName and so on.
                var objectNamesType = myValueServices.GetReifiedType(frame, "UnityEditor.ObjectNames, UnityEditor")
                                      ?? myValueServices.GetReifiedType(frame,
                                                                        "UnityEditor.ObjectNames, UnityEditor.CoreModule");
                var getInspectorTitleMethod = objectNamesType?.MetadataType.GetMethods()
                                              .FirstOrDefault(ourGetInspectorTitleSelector);

                var childReferencesEnumerator = (IChildReferencesEnumerator <TValue>)componentArray;

                foreach (var componentReference in childReferencesEnumerator.GetChildReferences())
                {
                    var componentName = GetComponentName(componentReference, objectNamesType,
                                                         getInspectorTitleMethod, frame, options, myValueServices, out var isNameFromValue);

                    // Tell the value presenter to hide the name field, if we're using it for the key. Also hide the
                    // default type presentation - we know it's a Component, it's under a group called "Components"
                    yield return(new CalculatedValueReferenceDecorator <TValue>(componentReference,
                                                                                myValueServices.RoleFactory, componentName, !isNameFromValue, false).ToValue(myValueServices));
                }
            }