コード例 #1
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"));
                }
            }
            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));
            }
コード例 #3
0
            public override IEnumerable <IValueEntity> GetChildren(IPresentationOptions options,
                                                                   CancellationToken token = new CancellationToken())
            {
                var transformObject = myTransformReference.AsObjectSafe(options);
                var childCountRole  = transformObject?.GetInstancePropertyReference("childCount", true)
                                      ?.AsPrimitiveSafe(options);

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

                if (!(childCountRole.GetPrimitive() is int childCount))
                {
                    yield break;
                }

                var transformType =
                    transformObject.ReifiedType.MetadataType.FindTypeThroughHierarchy("UnityEngine.Transform");
                var getChildMethod = transformType?.GetMethods().FirstOrDefault(ourGetChildSelector);

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

                for (int i = 0; i < childCount; i++)
                {
                    var frame          = myTransformReference.OriginatingFrame;
                    var index          = myServices.ValueFactory.CreatePrimitive(frame, options, i);
                    var childTransform = new SimpleValueReference <TValue>(
                        transformObject.CallInstanceMethod(getChildMethod, index), frame, myServices.RoleFactory)
                                         .AsObjectSafe(options);
                    if (childTransform == null)
                    {
                        continue;
                    }

                    var name = childTransform.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                               ?.GetString() ?? "Game Object";
                    yield return(new NamedReferenceDecorator <TValue>(childTransform.ValueReference, name,
                                                                      ValueOriginKind.Property, transformType, myServices.RoleFactory).ToValue(myServices));
                }
            }
コード例 #4
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));
            }