// INITIALIZE: ----------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }

            this.spStatsAsset         = serializedObject.FindProperty("statsAsset");
            this.spAttributesAsset    = serializedObject.FindProperty("attrsAsset");
            this.spStatusEffectsAsset = serializedObject.FindProperty("statusEffectsAsset");

            if (this.spStatsAsset.objectReferenceValue == null)
            {
                string     path       = Path.Combine(ASSETS_PATH, STATSASSET_FILE);
                StatsAsset statsAsset = AssetDatabase.LoadAssetAtPath <StatsAsset>(path);

                if (statsAsset == null)
                {
                    statsAsset = CreateStatsAsset();
                }
                this.spStatsAsset.objectReferenceValue = statsAsset;

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            if (this.spAttributesAsset.objectReferenceValue == null)
            {
                string     path            = Path.Combine(ASSETS_PATH, ATTRSASSET_FILE);
                AttrsAsset attributesAsset = AssetDatabase.LoadAssetAtPath <AttrsAsset>(path);

                if (attributesAsset == null)
                {
                    attributesAsset = CreateAttributesAsset();
                }
                this.spAttributesAsset.objectReferenceValue = attributesAsset;

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            if (this.spStatusEffectsAsset.objectReferenceValue == null)
            {
                string             path = Path.Combine(ASSETS_PATH, STAEFASSET_FILE);
                StatusEffectsAsset statusEffectsAsset = AssetDatabase.LoadAssetAtPath <StatusEffectsAsset>(path);

                if (statusEffectsAsset == null)
                {
                    statusEffectsAsset = CreateStatusEffectsAsset();
                }
                this.spStatusEffectsAsset.objectReferenceValue = statusEffectsAsset;

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            this.statsAssetEditor         = (StatsAssetEditor)CreateEditor(this.spStatsAsset.objectReferenceValue);
            this.attrsAssetEditor         = (AttrsAssetEditor)CreateEditor(this.spAttributesAsset.objectReferenceValue);
            this.statusEffectsAssetEditor = (StatusEffectsAssetEditor)CreateEditor(this.spStatusEffectsAsset.objectReferenceValue);
        }
        // PUBLIC STATIC METHODS: -----------------------------------------------------------------

        public static StatsAsset GetStatsAsset()
        {
            string     path       = Path.Combine(ASSETS_PATH, STATSASSET_FILE);
            StatsAsset statsAsset = AssetDatabase.LoadAssetAtPath <StatsAsset>(path);

            if (statsAsset == null)
            {
                statsAsset = CreateStatsAsset();
            }
            return(statsAsset);
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            this.instance = (StatsAsset)target;

            this.spStats            = serializedObject.FindProperty("stats");
            this.editorSortableList = new EditorSortableList();

            this.UpdateSubEditors(this.instance.stats);
        }
        // PRIVATE METHODS: -----------------------------------------------------------------------

        public static StatsAsset CreateStatsAsset()
        {
            string filepath = ASSETS_PATH;
            string filename = STATSASSET_FILE;

            StatsAsset asset = ScriptableObject.CreateInstance <StatsAsset>();

            GameCreatorUtilities.CreateFolderStructure(filepath);
            string path = Path.Combine(filepath, filename);

            path = AssetDatabase.GenerateUniqueAssetPath(path);

            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.ImportAsset(path);
            return(asset);
        }
Example #5
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            this.instance = (Stats)this.target;

            this.spStatsOverridesList = serializedObject.FindProperty("statsOverrides");
            this.spStatsOverrides     = new Dictionary <string, StatOverride>();

            int overrideCount = this.spStatsOverridesList.arraySize;

            for (int i = 0; i < overrideCount; ++i)
            {
                SerializedProperty spElement    = this.spStatsOverridesList.GetArrayElementAtIndex(i);
                string             statUniqueID = spElement.FindPropertyRelative("statUniqueID").stringValue;
                if (string.IsNullOrEmpty(statUniqueID))
                {
                    continue;
                }

                this.spStatsOverrides.Add(
                    statUniqueID,
                    new StatOverride(spElement)
                    );
            }

            this.statsAsset = DatabaseStatsEditor.GetStatsAsset();
            this.attrsAsset = DatabaseStatsEditor.GetAttrsAsset();

            this.statsAssetHash  = this.statsAsset.GetHashCode();
            this.attrsAssetHash  = this.attrsAsset.GetHashCode();
            this.statsEditorData = new List <EditorData>();

            bool statsListAdded = false;
            int  statsSize      = this.statsAsset.stats.Length;

            for (int i = 0; i < statsSize; ++i)
            {
                this.statsEditorData.Add(new EditorData(this));
                string statUniqueID = this.statsAsset.stats[i].uniqueID;

                if (!this.spStatsOverrides.ContainsKey(statUniqueID))
                {
                    int insertIndex = this.spStatsOverridesList.arraySize;
                    this.spStatsOverridesList.InsertArrayElementAtIndex(insertIndex);

                    SerializedProperty spItem = this.spStatsOverridesList.GetArrayElementAtIndex(insertIndex);

                    spItem.FindPropertyRelative("statUniqueID").stringValue     = statUniqueID;
                    spItem.FindPropertyRelative("overrideValue").boolValue      = false;
                    spItem.FindPropertyRelative("overrideFormula").boolValue    = false;
                    spItem.FindPropertyRelative("baseValue").floatValue         = 0.0f;
                    spItem.FindPropertyRelative("formula").objectReferenceValue = null;

                    this.spStatsOverrides.Add(statUniqueID, new StatOverride(spItem));
                    statsListAdded = true;
                }
            }

            if (statsListAdded)
            {
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
            }
        }