Esempio n. 1
0
        private bool ImportGroupsWithGUI(NodeGUI node)
        {
            string fileSelected = EditorUtility.OpenFilePanelWithFilters(
                "Select JSON files to import",
                Application.dataPath, new string[] { "JSON files", "json", "All files", "*" });

            if (string.IsNullOrEmpty(fileSelected))
            {
                return(false);
            }

            var jsonContent = File.ReadAllText(fileSelected, System.Text.Encoding.UTF8);

            if (m_savedGroups != null)
            {
                using (new RecordUndoScope("Import Saved Group", node, true)){
                    JsonUtility.FromJsonOverwrite(jsonContent, m_savedGroups);
                }
            }
            else
            {
                using (new RecordUndoScope("Import Saved Group", node, true)){
                    m_savedGroups = new SerializableGroups();
                    JsonUtility.FromJsonOverwrite(jsonContent, m_savedGroups);
                }
            }
            return(true);
        }
Esempio n. 2
0
 public SerializableGroups(SerializableGroups rhs)
 {
     m_groups = new List <Group>();
     foreach (var v in rhs.m_groups)
     {
         m_groups.Add(new Group(v.name, v.assets));
     }
 }
Esempio n. 3
0
        public override bool Equals(object rhs)
        {
            SerializableGroups other = rhs as SerializableGroups;

            if (other == null)
            {
                return(false);
            }
            else
            {
                return(other == this);
            }
        }
Esempio n. 4
0
        public override void Build(BuildTarget target,
                                   Model.NodeData nodeData,
                                   IEnumerable <PerformGraph.AssetGroups> incoming,
                                   IEnumerable <Model.ConnectionData> connectionsToOutput,
                                   PerformGraph.Output outputFunc,
                                   Action <Model.NodeData, string, float> progressFunc)
        {
            if (m_freezeGroups)
            {
                m_savedGroups = new SerializableGroups(m_lastOutputGroups);

                // export current setting to file
                var prefabOutputDir = FileUtility.EnsureGroupingCacheDirExists(target, nodeData);
                var outputFilePath  = Path.Combine(prefabOutputDir, nodeData.Name + ".json");

                string jsonString = JsonUtility.ToJson(m_savedGroups, true);
                File.WriteAllText(outputFilePath, jsonString, System.Text.Encoding.UTF8);
            }
        }
Esempio n. 5
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            if (m_groupSizeByte == null)
            {
                return;
            }

            EditorGUILayout.HelpBox("Grouping by size: Create group of assets by size.", MessageType.Info);
            editor.UpdateNodeName(node);

            GUILayout.Space(10f);

            //Show target configuration tab
            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_groupSizeByte.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                    using (new RecordUndoScope("Remove Target Grouping Size Settings", node, true)){
                        if (enabled)
                        {
                            m_groupSizeByte[editor.CurrentEditingGroup] = m_groupSizeByte.DefaultValue;
                            m_groupingType[editor.CurrentEditingGroup]  = m_groupingType.DefaultValue;
                        }
                        else
                        {
                            m_groupSizeByte.Remove(editor.CurrentEditingGroup);
                            m_groupingType.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    }
                });

                using (disabledScope) {
                    var newType = (GroupingType)EditorGUILayout.EnumPopup("Grouping Type", (GroupingType)m_groupingType[editor.CurrentEditingGroup]);
                    if (newType != (GroupingType)m_groupingType[editor.CurrentEditingGroup])
                    {
                        using (new RecordUndoScope("Change Grouping Type", node, true)){
                            m_groupingType[editor.CurrentEditingGroup] = (int)newType;
                            onValueChanged();
                        }
                    }

                    var newSizeText = EditorGUILayout.TextField("Size(KB)", m_groupSizeByte[editor.CurrentEditingGroup].ToString());
                    int newSize     = 0;
                    Int32.TryParse(newSizeText, out newSize);

                    if (newSize != m_groupSizeByte[editor.CurrentEditingGroup])
                    {
                        using (new RecordUndoScope("Change Grouping Size", node, true)){
                            m_groupSizeByte[editor.CurrentEditingGroup] = newSize;
                            onValueChanged();
                        }
                    }
                }
            }

            var newFreezeGroups = EditorGUILayout.ToggleLeft("Freeze group on build", m_freezeGroups);

            if (newFreezeGroups != m_freezeGroups)
            {
                using (new RecordUndoScope("Change Freeze Groups", node, true)){
                    m_freezeGroups = newFreezeGroups;
                    onValueChanged();
                }
            }
            EditorGUILayout.HelpBox("Freezing group will save group when build is performed, and any new asset from there will be put into new group.",
                                    MessageType.Info);
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Group setting");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Import"))
                {
                    if (ImportGroupsWithGUI(node))
                    {
                        onValueChanged();
                    }
                }
                if (GUILayout.Button("Export"))
                {
                    ExportGroupsWithGUI(node);
                }
                if (GUILayout.Button("Reset"))
                {
                    if (EditorUtility.DisplayDialog("Do you want to reset group setting?", "This will erase current saved group setting.", "OK", "Cancel"))
                    {
                        m_savedGroups = null;
                        onValueChanged();
                    }
                }
            }
            GUILayout.Space(8f);

            if (m_groupViewController != null)
            {
                m_groupViewController.OnGroupViewGUI();
            }
        }