Beispiel #1
0
            private IValue GetElementValue(IValueReference <TValue> elementReference, IValueFetchOptions options)
            {
                try
                {
                    var elementRole = elementReference.AsObjectSafe(options);
                    if (elementRole == null)
                    {
                        return(null);
                    }

                    var isNameFromValue = true;
                    var name            = elementRole.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                                          ?.GetString();
                    if (name == null)
                    {
                        name            = "Game Object";
                        isNameFromValue = false;
                    }

                    // 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 GameObject, it's under a group called "Game Objects"
                    return(new CalculatedValueReferenceDecorator <TValue>(elementRole.ValueReference,
                                                                          myValueServices.RoleFactory, name, !isNameFromValue, 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",
                                                                                   elementReference.OriginatingFrame) as IValue
                           ?? new ErrorValue("Game Object", "Error retrieving child game object"));
                }
            }
Beispiel #2
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));
                }
            }
            private IValue GetElementValue(IValueReference <TValue> elementReference, IValueFetchOptions options)
            {
                var elementRole = elementReference.AsObjectSafe(options);

                if (elementRole == null)
                {
                    return(null);
                }

                var isNameFromValue = true;
                var name            = elementRole.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                                      ?.GetString();

                if (name == null)
                {
                    name            = "Game Object";
                    isNameFromValue = false;
                }

                // 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 GameObject, it's under a group called "Game Objects"
                return(new CalculatedValueReferenceDecorator <TValue>(elementRole.ValueReference,
                                                                      myValueServices.RoleFactory, name, !isNameFromValue, false).ToValue(myValueServices));
            }
            private IValue GetElementValue(IValueReference <TValue> elementReference, IValueFetchOptions options)
            {
                var elementRole = elementReference.AsObjectSafe(options);

                if (elementRole == null)
                {
                    return(null);
                }

                var isNameFromValue = true;
                var name            = elementRole.GetInstancePropertyReference("name", true)?.AsStringSafe(options)
                                      ?.GetString();

                if (name == null)
                {
                    name            = "Game Object";
                    isNameFromValue = false;
                }

                return(new NamedReferenceDecorator <TValue>(elementRole.ValueReference, name,
                                                            ValueOriginKind.Property, ValueFlags.None | ValueFlags.IsReadOnly,
                                                            elementRole.ReifiedType.MetadataType, myValueServices.RoleFactory, isNameFromValue)
                       .ToValue(myValueServices));
            }