Exemple #1
0
            private static bool Get(
                ref EntityContainer container,
                int index,
                HashSet <Type> primitiveTypes,
                out StructProxy p)
            {
                var typeIndex    = container.m_Manager.GetComponentTypeIndex(container.m_Entity, index);
                var propertyType = TypeManager.GetType(typeIndex);

                p = new StructProxy();

                if (typeof(ISharedComponentData).IsAssignableFrom(propertyType))
                {
                    try
                    {
                        var o = container.m_Manager.GetSharedComponentData(container.m_Entity, typeIndex);

                        // TODO: skip the StructObjectProxyProperty adapter and have the Accept()
                        // TODO:    handle Struct & Object proxies
                        p = new StructProxy
                        {
                            bag = new StructPropertyBag <StructProxy>(
                                new StructObjectProxyProperty(propertyType, o, primitiveTypes)
                                ),
                            data = default(byte *),
                            type = propertyType
                        };

                        return(true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }

                if (typeof(IBufferElementData).IsAssignableFrom(propertyType))
                {
                    IPropertyBag bag = TypeInformation.GetOrCreate(propertyType, primitiveTypes);

                    p = new StructProxy
                    {
                        bag = new StructPropertyBag <StructProxy>(
                            new BufferListProxyProperty(
                                bag,
                                propertyType,
                                container.m_Manager.GetBufferLength(container.m_Entity, typeIndex)
                                )
                            ),
                        data = (byte *)container.m_Manager.GetBufferRawRW(container.m_Entity, typeIndex),
                        type = propertyType
                    };

                    return(true);
                }

                {
                    IPropertyBag bag = TypeInformation.GetOrCreate(propertyType, primitiveTypes);

                    // We skip the property bag & proxy creation for zero sized types (e.g. MonoBehaviors, etc).
                    // They wont get displayed at all in the inspector since we dont know
                    if (bag.PropertyCount > 1 && !TypeManager.GetTypeInfo(typeIndex).IsZeroSized)
                    {
                        byte *data = (byte *)container.m_Manager.GetComponentDataRawRW(container.m_Entity, typeIndex);
                        if (data != null)
                        {
                            p = new StructProxy
                            {
                                bag  = bag,
                                data = data,
                                type = propertyType
                            };

                            return(true);
                        }
                    }
                }

                return(false);
            }
            private static StructProxy Get(ref EntityContainer container, int index, HashSet <Type> primitiveTypes)
            {
                var typeIndex    = container.m_Manager.GetComponentTypeIndex(container.m_Entity, index);
                var propertyType = TypeManager.GetType(typeIndex);

                if (typeof(ISharedComponentData).IsAssignableFrom(propertyType))
                {
                    try
                    {
                        var o = container.m_Manager.GetSharedComponentData(container.m_Entity, typeIndex);

                        // TODO: skip the StructObjectProxyProperty adapter and have the Accept()
                        // TODO:    handle Struct & Object proxies
                        var p = new StructProxy
                        {
                            bag = new StructPropertyBag <StructProxy>(
                                new StructObjectProxyProperty(propertyType, o, primitiveTypes)
                                ),
                            data = default(byte *),
                            type = propertyType
                        };

                        return(p);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (typeof(IBufferElementData).IsAssignableFrom(propertyType))
                {
                    IPropertyBag bag = TypeInformation.GetOrCreate(propertyType, primitiveTypes);

                    var p = new StructProxy
                    {
                        bag = new StructPropertyBag <StructProxy>(
                            new BufferListProxyProperty(
                                bag,
                                propertyType,
                                container.m_Manager.GetBufferLength(container.m_Entity, typeIndex)
                                )
                            ),
                        data = (byte *)container.m_Manager.GetBufferRawRW(container.m_Entity, typeIndex),
                        type = propertyType
                    };
                    return(p);
                }

                {
                    IPropertyBag bag = TypeInformation.GetOrCreate(propertyType, primitiveTypes);

                    byte *data = null;
                    if (bag.PropertyCount > 1 || !TypeManager.GetTypeInfo(typeIndex).IsZeroSized)
                    {
                        data = (byte *)container.m_Manager.GetComponentDataRawRW(container.m_Entity, typeIndex);
                    }

                    var p = new StructProxy
                    {
                        bag  = bag,
                        data = data,
                        type = propertyType
                    };

                    return(p);
                }
            }