示例#1
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();
            }
        }
        // PAINT METHODS: -------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }

            serializedObject.Update();
            this.UpdateSubEditors(this.instance.stats);

            int  removeIndex  = -1;
            bool forceRepaint = false;

            int spActionsSize = this.spStats.arraySize;

            for (int i = 0; i < spActionsSize; ++i)
            {
                bool forceSortRepaint = this.editorSortableList.CaptureSortEvents(this.handleRect[i], i);
                forceRepaint = forceSortRepaint || forceRepaint;

                GUILayout.BeginVertical();
                if (this.PaintStatHeader(i))
                {
                    removeIndex = i;
                }

                using (var group = new EditorGUILayout.FadeGroupScope(this.isExpanded[i].faded))
                {
                    if (group.visible)
                    {
                        EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded());
                        if (this.subEditors[i] != null)
                        {
                            this.subEditors[i].OnInspectorGUI();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox(MSG_UNDEF_STAT_1, MessageType.Warning);
                            EditorGUILayout.HelpBox(MSG_UNDEF_STAT_2, MessageType.None);
                        }

                        EditorGUILayout.EndVertical();
                    }
                }

                GUILayout.EndVertical();

                if (Event.current.type == EventType.Repaint)
                {
                    this.objectRect[i] = GUILayoutUtility.GetLastRect();
                }

                this.editorSortableList.PaintDropPoints(this.objectRect[i], i, spActionsSize);
            }

            if (GUILayout.Button("Create Stat"))
            {
                StatAsset statAsset = DatabaseStatsEditor.AddStatsAsset();
                int       addIndex  = this.spStats.arraySize;

                this.spStats.InsertArrayElementAtIndex(addIndex);
                this.spStats.GetArrayElementAtIndex(addIndex).objectReferenceValue = statAsset;
                this.AddSubEditorElement(statAsset, addIndex, true);
            }

            if (removeIndex >= 0)
            {
                StatAsset source = (StatAsset)this.spStats.GetArrayElementAtIndex(removeIndex).objectReferenceValue;

                this.spStats.RemoveFromObjectArrayAt(removeIndex);
                this.RemoveSubEditorsElement(removeIndex);
                DestroyImmediate(source, true);
            }

            EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes();
            if (swapIndexes != null)
            {
                this.spStats.MoveArrayElement(swapIndexes.src, swapIndexes.dst);
                this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst);
            }

            if (EditorApplication.isPlaying)
            {
                forceRepaint = true;
            }
            if (forceRepaint)
            {
                this.Repaint();
            }

            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }