Exemplo n.º 1
0
        public ComponentTypeListView(TreeViewState state, out MultiColumnHeaderState headerState, SelectionChange <ComponentType, object> selectionChange, Func <World> worldChanged) : base(state, BuilMultiColumnHeader(out headerState))
        {
            selectionChanged  = selectionChange;
            this.worldChanged = worldChanged;

            foreach (var type in TypeManager.AllTypes())
            {
                if (type.Type == typeof(Entity))
                {
                    continue;
                }
                var typeIndex     = TypeManager.GetTypeIndex(type.Type);
                var componentType = ComponentType.FromTypeIndex(typeIndex);
                if (componentType.GetManagedType() == null)
                {
                    continue;
                }

                //Currently IsZeroSized is broken and returns true for both SharedComponents and SystemStateSharedComponents //Case #1086719 @
                if (componentType.IsZeroSized())
                {
                    //Debug.Log($"{componentType} : {componentType.IsSharedComponent} : {componentType.IsSystemStateComponent} : {componentType.IsSystemStateSharedComponent} : {componentType.IsZeroSized} : {componentType.BufferCapacity}");
                    Objects.Add(componentType, null);
                }
                else
                {
                    var obj = Activator.CreateInstance(type.Type, true);
                    Objects.Add(componentType, obj);
                    if (componentType.IsSharedComponent || componentType.IsSystemStateSharedComponent)
                    {
                        foreach (var fieldInfo in obj.GetType().GetFields().Where(f => f.FieldType.IsClass))
                        {
                            //if(fieldInfo.FieldType != typeof(Material))
                            if (fieldInfo.FieldType.GetConstructor(Type.EmptyTypes) != null)
                            {
                                var value = Activator.CreateInstance(fieldInfo.FieldType);
                                fieldInfo.SetValue(obj, value);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal void GetTypes()
        {
            if (getWorldSelection() == null)
            {
                return;
            }
            if (!TypeListValid())
            {
                filterTypes.Clear();
                selectedFilterTypes.Clear();
                var requiredTypes    = new List <ComponentType>();
                var subtractiveTypes = new List <ComponentType>();
                filterTypes.Capacity         = TypeManager.TypesCount;
                selectedFilterTypes.Capacity = TypeManager.TypesCount;
                foreach (var type in TypeManager.AllTypes())
                {
                    if (type.Type == typeof(Entity))
                    {
                        continue;
                    }
                    var typeIndex     = TypeManager.GetTypeIndex(type.Type);
                    var componentType = ComponentType.FromTypeIndex(typeIndex);
                    if (componentType.GetManagedType() == null)
                    {
                        continue;
                    }
                    requiredTypes.Add(componentType);
                    componentType.AccessModeType = ComponentType.AccessMode.Subtractive;
                    subtractiveTypes.Add(componentType);
                    selectedFilterTypes.Add(false);
                    selectedFilterTypes.Add(false);
                }

                filterTypes.AddRange(requiredTypes);
                filterTypes.AddRange(subtractiveTypes);

                filterTypes.Sort(ComponentGroupGUI.CompareTypes);
            }
        }