private DataHelper CreateDataHelper(DataItemInfo info, out bool valid)
        {
            DataHelper helper = new DataHelper(info.TargetType, this, Database, info.DataName, info.FieldName, info.Sorts, out valid);

            this.HelperOrder.Add(info.DataName);
            this.DataHelpers.Add(info.DataName, helper);
            return(helper);
        }
        public void Initialize(EditorLSDatabaseWindow window, LSDatabase database, out bool valid)
        {
            this.MainWindow = window;
            Database        = database;
            InitializeData();
            bool isValid = true;

            for (int i = 0; i < DataItemInfos.Count; i++)
            {
                DataItemInfo info = DataItemInfos [i];
                bool         bufferValid;
                CreateDataHelper(info, out bufferValid);
                if (!bufferValid)
                {
                    Debug.LogError("Database does not match database type described by the database editor. Make sure Lockstep_Database.asset is the correct database type.");
                    isValid = false;
                    break;
                }
            }
            valid = isValid;
        }
 public void RegisterData(DataItemInfo info)
 {
     DataItemInfos.Add(info);
 }
        private void InitializeData()
        {
            Type databaseType   = Database.GetType();
            Type foundationType = typeof(LSDatabase);

            if (!databaseType.IsSubclassOf(foundationType))
            {
                throw new System.Exception("Database does not inherit from LSDatabase and cannot be edited.");
            }
            HashSet <string>    nameCollisionChecker = new HashSet <string>();
            FastList <SortInfo> sortInfos            = new FastList <SortInfo>();

            while (databaseType != foundationType)
            {
                FieldInfo[] fields = databaseType.GetFields((BindingFlags) ~0);
                for (int i = 0; i < fields.Length; i++)
                {
                    FieldInfo field      = fields [i];
                    object[]  attributes = field.GetCustomAttributes(typeof(RegisterDataAttribute), false);
                    for (int j = 0; j < attributes.Length; j++)
                    {
                        RegisterDataAttribute registerDataAttribute = attributes [j] as RegisterDataAttribute;
                        if (registerDataAttribute != null)
                        {
                            if (!field.FieldType.IsArray)
                            {
                                Debug.LogError("Serialized data field must be array");
                                continue;
                            }
                            if (!field.FieldType.GetElementType().IsSubclassOf(typeof(DataItem)))
                            {
                                Debug.LogError("Serialized data type must be derived from DataItem");
                                continue;
                            }


                            object[] sortAttributes = field.GetCustomAttributes(typeof(RegisterSortAttribute), false);
                            sortInfos.FastClear();
                            foreach (object obj in sortAttributes)
                            {
                                RegisterSortAttribute sortAtt = obj as RegisterSortAttribute;
                                if (sortAtt != null)
                                {
                                    sortInfos.Add(new SortInfo(sortAtt.Name, sortAtt.DegreeGetter));
                                }
                            }

                            DataItemInfo dataInfo = new DataItemInfo(
                                field.FieldType.GetElementType(),
                                registerDataAttribute.DataName,
                                field.Name,
                                sortInfos.ToArray()
                                );

                            if (nameCollisionChecker.Add(dataInfo.DataName) == false)
                            {
                                throw new System.Exception("Data Name collision detected for '" + dataInfo.DataName + "'.");
                            }
                            RegisterData(dataInfo);
                            break;
                        }
                    }
                }
                databaseType = databaseType.BaseType;
            }
        }