Esempio n. 1
0
            public void DrawComponents()
            {
                EditorGUI.indentLevel += 3;
                using (var scope = new EditorGUILayout.VerticalScope())
                {
                    foreach (var component in components)
                    {
                        if (component == null)
                        {
                            continue;
                        }

                        using (var horizontalScope = new EditorGUILayout.HorizontalScope())
                        {
                            bool saveComponent = false;
                            if (autoSave != null)
                            {
                                saveComponent = autoSave.componentsToSave.Contains(component);
                            }

                            var newValue = EditorGUILayout.ToggleLeft(EditorGUIUtility.ObjectContent(component, component.GetType()), saveComponent);
                            // If the checkbox has changed, we want to save or not save a Component
                            if (newValue != saveComponent)
                            {
                                if (autoSave == null)
                                {
                                    autoSave = t.gameObject.AddComponent <ES3AutoSave>();
                                    autoSave.saveChildren = false;
                                }
                                // If we've unchecked the box, remove the Component from the array.
                                if (newValue == false)
                                {
                                    autoSave.componentsToSave.Remove(component);
                                }
                                // Else, add it to the array.
                                else
                                {
                                    autoSave.componentsToSave.Add(component);
                                }
                            }
                            if (GUILayout.Button(EditorGUIUtility.IconContent("_Popup"), new GUIStyle("Label")))
                            {
                                ES3Window.InitAndShowTypes(component.GetType());
                            }
                        }
                    }
                }
                EditorGUI.indentLevel -= 3;
            }
Esempio n. 2
0
            public void DrawComponents()
            {
                EditorGUI.indentLevel += 3;
                using (var scope = new EditorGUILayout.VerticalScope())
                {
                    bool toggle;
                    toggle = EditorGUILayout.ToggleLeft("active", autoSave != null ? autoSave.saveActive : false);
                    if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent <ES3AutoSave>() : autoSave) != null)
                    {
                        autoSave.saveActive = toggle;
                    }

                    toggle = EditorGUILayout.ToggleLeft("hideFlags", autoSave != null ? autoSave.saveHideFlags : false);
                    if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent <ES3AutoSave>() : autoSave) != null)
                    {
                        autoSave.saveHideFlags = toggle;
                    }

                    toggle = EditorGUILayout.ToggleLeft("layer", autoSave != null ? autoSave.saveLayer : false);
                    if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent <ES3AutoSave>() : autoSave) != null)
                    {
                        autoSave.saveLayer = toggle;
                    }

                    toggle = EditorGUILayout.ToggleLeft("name", autoSave != null ? autoSave.saveName : false);
                    if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent <ES3AutoSave>() : autoSave) != null)
                    {
                        autoSave.saveName = toggle;
                    }

                    toggle = EditorGUILayout.ToggleLeft("tag", autoSave != null ? autoSave.saveTag : false);
                    if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent <ES3AutoSave>() : autoSave) != null)
                    {
                        autoSave.saveTag = toggle;
                    }

                    foreach (var component in components)
                    {
                        if (component == null)
                        {
                            continue;
                        }

                        using (var horizontalScope = new EditorGUILayout.HorizontalScope())
                        {
                            bool saveComponent = false;
                            if (autoSave != null)
                            {
                                saveComponent = autoSave.componentsToSave.Contains(component);
                            }

                            var newValue = EditorGUILayout.ToggleLeft(EditorGUIUtility.ObjectContent(component, component.GetType()), saveComponent);
                            // If the checkbox has changed, we want to save or not save a Component
                            if (newValue != saveComponent)
                            {
                                if (autoSave == null)
                                {
                                    autoSave = t.gameObject.AddComponent <ES3AutoSave>();
                                    autoSave.saveChildren = false;
                                }
                                // If we've unchecked the box, remove the Component from the array.
                                if (newValue == false)
                                {
                                    autoSave.componentsToSave.Remove(component);
                                }
                                // Else, add it to the array.
                                else
                                {
                                    autoSave.componentsToSave.Add(component);
                                }
                            }
                            if (GUILayout.Button(EditorGUIUtility.IconContent("_Popup"), new GUIStyle("Label")))
                            {
                                ES3Window.InitAndShowTypes(component.GetType());
                            }
                        }
                    }
                }

                if (autoSave != null && (autoSave.componentsToSave == null || autoSave.componentsToSave.Count == 0) && !autoSave.saveActive && !autoSave.saveChildren && !autoSave.saveHideFlags && !autoSave.saveLayer && !autoSave.saveName && !autoSave.saveTag)
                {
                    Undo.DestroyObjectImmediate(autoSave);
                    autoSave = null;
                }
                EditorGUI.indentLevel -= 3;
            }