예제 #1
0
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataCodeName,
            string dataFieldName,
            SortInfo[] sorts)
        {
            Sorts            = sorts;
            this.TargetType  = targetType;
            SourceEditor     = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase   = sourceDatabase;
            DataCodeName     = dataCodeName;
            _dataFieldName   = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
            {
                Data = (DataItem[])Array.CreateInstance(TargetType, 0);
            }
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof(DataItemAttribute));

            _dataAttribute = dataAttribute ?? new DataItemAttribute();
        }
        void LoadDatabase(LSDatabase database)
        {
            _database = database;
            bool isValid = false;

            if (_database != null)
            {
                if (database.GetType() != DatabaseType)
                {
                    //Note: A hacky fix for changing the type of a previously saved database is to turn on Debug mode
                    //and change the script type of the database asset in the inspector. Back it up before attempting!
                }
                DatabaseEditor = new EditorLSDatabase();
                DatabaseEditor.Initialize(this, Database, out isValid);
            }
            if (!isValid)
            {
                Debug.Log("Load unsuccesful");
                this.DatabaseEditor = null;
                this._database      = null;
                IsLoaded            = false;
                return;
            }
            LSFSettingsManager.GetSettings().Database = database;
            LSFSettingsModifier.Save();
            IsLoaded = true;
        }
예제 #3
0
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataFieldName,
            SortInfo[] sorts,
            out bool valid)
        {
            Sorts = sorts;
            this.TargetType = targetType;
            SourceEditor = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase = sourceDatabase;
            _dataFieldName = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (info == null) {
                Debug.Log (string.Format ("Field with fieldName of {0} not found.", dataFieldName));
                valid = false;
                return;
            }

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
                Data = (DataItem[])Array.CreateInstance (TargetType,0);
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof (DataItemAttribute));
            _dataAttribute = dataAttribute ?? new DataItemAttribute ();
            valid = true;
        }
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataCodeName,
            string dataFieldName,
            SortInfo[] sorts)
        {
            Sorts = sorts;
            this.TargetType = targetType;
            SourceEditor = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase = sourceDatabase;
            DataCodeName = dataCodeName;
            _dataFieldName = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
                Data = (DataItem[])Array.CreateInstance (TargetType,0);
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof (DataItemAttribute));
            _dataAttribute = dataAttribute ?? new DataItemAttribute ();
        }
예제 #5
0
 void LoadDatabase(LSDatabase database)
 {
     _database       = database;
     _databaseEditor = (EditorLSDatabase)Activator.CreateInstance(DatabaseEditorType);
     _databaseEditor.Initialize(this, Database);
     LSFSettingsManager.GetSettings().Database = database;
     LSFSettingsModifier.Save();
 }
예제 #6
0
        bool LoadDatabaseFromPath(string absolutePath)
        {
            string     relativePath = absolutePath.GetRelativeUnityAssetPath();
            LSDatabase database     = AssetDatabase.LoadAssetAtPath <LSDatabase> (relativePath);

            if (database != null)
            {
                LoadDatabase(database);
                return(true);
            }
            _databaseEditor = null;
            return(false);
        }
예제 #7
0
        void LoadDatabase(LSDatabase database)
        {
            _database       = database;
            _databaseEditor = (EditorLSDatabase)Activator.CreateInstance(typeof(EditorLSDatabase));
            bool isValid;

            _databaseEditor.Initialize(this, Database, out isValid);
            if (!isValid)
            {
                this._databaseEditor = null;
                this._database       = null;
                IsLoaded             = false;
                return;
            }
            LSFSettingsManager.GetSettings().Database = database;
            LSFSettingsModifier.Save();
            IsLoaded = true;
        }
예제 #8
0
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataFieldName,
            SortInfo[] sorts,
            out bool valid)
        {
            Sorts            = sorts;
            this.TargetType  = targetType;
            SourceEditor     = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase   = sourceDatabase;
            _dataFieldName   = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (info == null)
            {
                Debug.Log(string.Format("Field with fieldName of {0} not found.", dataFieldName));
                valid = false;
                return;
            }

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
            {
                Data = (DataItem[])Array.CreateInstance(TargetType, 0);
            }
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof(DataItemAttribute));

            _dataAttribute = dataAttribute ?? new DataItemAttribute();
            valid          = true;
        }
 bool LoadDatabaseFromPath(string absolutePath)
 {
     string relativePath = absolutePath.GetRelativeUnityAssetPath ();
     LSDatabase database = AssetDatabase.LoadAssetAtPath<LSDatabase> (relativePath);
     if (database != null) {
         LoadDatabase (database);
         return true;
     }
     _databaseEditor = null;
     return false;
 }
 void LoadDatabase(LSDatabase database)
 {
     _database = database;
     _databaseEditor = (EditorLSDatabase)Activator.CreateInstance ((Type)DatabaseEditorType);
     bool isValid;
     _databaseEditor.Initialize (this,Database, out isValid);
     if (!isValid) {
         this._databaseEditor = null;
         this._database = null;
         IsLoaded = false;
         return;
     }
     LSFSettingsManager.GetSettings ().Database = database;
     LSFSettingsModifier.Save ();
     IsLoaded = true;
 }
 void LoadDatabase(LSDatabase database)
 {
     _database = database;
     _databaseEditor = (EditorLSDatabase)Activator.CreateInstance (DatabaseEditorType);
     _databaseEditor.Initialize (this,Database);
     LSFSettingsManager.GetSettings ().Database = database;
     LSFSettingsModifier.Save ();
 }