Exemplo n.º 1
0
        private void OnEnable()
        {
            m_Controller = new ResourcePackBuilderController();
            m_Controller.OnBuildResourcePacksStarted   += OnBuildResourcePacksStarted;
            m_Controller.OnBuildResourcePacksCompleted += OnBuildResourcePacksCompleted;
            m_Controller.OnBuildResourcePackSuccess    += OnBuildResourcePackSuccess;
            m_Controller.OnBuildResourcePackFailure    += OnBuildResourcePackFailure;

            m_Controller.Load();
            RefreshVersionNames();

            m_CompressionHelperTypeNameIndex = 0;
            string[] compressionHelperTypeNames = m_Controller.GetCompressionHelperTypeNames();
            for (int i = 0; i < compressionHelperTypeNames.Length; i++)
            {
                if (m_Controller.CompressionHelperTypeName == compressionHelperTypeNames[i])
                {
                    m_CompressionHelperTypeNameIndex = i;
                    break;
                }
            }

            m_Controller.RefreshCompressionHelper();
        }
Exemplo n.º 2
0
        private void OnGUI()
        {
            EditorGUILayout.BeginVertical(GUILayout.Width(position.width), GUILayout.Height(position.height));
            {
                GUILayout.Space(5f);
                EditorGUILayout.LabelField("Environment Information", EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical("box");
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Product Name", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.ProductName);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Company Name", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.CompanyName);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Game Identifier", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.GameIdentifier);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Game Framework Version", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.GameFrameworkVersion);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Unity Version", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.UnityVersion);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Applicable Game Version", GUILayout.Width(160f));
                        EditorGUILayout.LabelField(m_Controller.ApplicableGameVersion);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(5f);
                EditorGUILayout.LabelField("Build", EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical("box");
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Working Directory", GUILayout.Width(160f));
                        string directory = EditorGUILayout.TextField(m_Controller.WorkingDirectory);
                        if (m_Controller.WorkingDirectory != directory)
                        {
                            m_Controller.WorkingDirectory = directory;
                            RefreshVersionNames();
                        }
                        if (GUILayout.Button("Browse...", GUILayout.Width(80f)))
                        {
                            BrowseWorkingDirectory();
                            RefreshVersionNames();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Platform", GUILayout.Width(160f));
                        int platformIndex = EditorGUILayout.Popup(m_PlatformIndex, PlatformForDisplay);
                        if (m_PlatformIndex != platformIndex)
                        {
                            m_PlatformIndex       = platformIndex;
                            m_Controller.Platform = (Platform)(1 << platformIndex);
                            RefreshVersionNames();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("Compression Helper", GUILayout.Width(160f));
                        string[] names         = m_Controller.GetCompressionHelperTypeNames();
                        int      selectedIndex = EditorGUILayout.Popup(m_CompressionHelperTypeNameIndex, names);
                        if (selectedIndex != m_CompressionHelperTypeNameIndex)
                        {
                            m_CompressionHelperTypeNameIndex       = selectedIndex;
                            m_Controller.CompressionHelperTypeName = selectedIndex <= 0 ? string.Empty : names[selectedIndex];
                            if (m_Controller.RefreshCompressionHelper())
                            {
                                Debug.Log("Set compression helper success.");
                            }
                            else
                            {
                                Debug.LogWarning("Set compression helper failure.");
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    if (m_Controller.Platform == Platform.Undefined || string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName) || !m_Controller.IsValidWorkingDirectory)
                    {
                        string message = string.Empty;
                        if (!m_Controller.IsValidWorkingDirectory)
                        {
                            if (!string.IsNullOrEmpty(message))
                            {
                                message += Environment.NewLine;
                            }

                            message += "Working directory is invalid.";
                        }

                        if (m_Controller.Platform == Platform.Undefined)
                        {
                            if (!string.IsNullOrEmpty(message))
                            {
                                message += Environment.NewLine;
                            }

                            message += "Platform is invalid.";
                        }

                        if (string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName))
                        {
                            if (!string.IsNullOrEmpty(message))
                            {
                                message += Environment.NewLine;
                            }

                            message += "Compression helper is invalid.";
                        }

                        EditorGUILayout.HelpBox(message, MessageType.Error);
                    }
                    else if (m_VersionNamesForTargetDisplay.Length <= 0)
                    {
                        EditorGUILayout.HelpBox("No version was found in the specified working directory and platform.", MessageType.Warning);
                    }
                    else
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Source Path", GUILayout.Width(160f));
                            GUILayout.Label(m_Controller.SourcePathForDisplay);
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Output Path", GUILayout.Width(160f));
                            GUILayout.Label(m_Controller.OutputPath);
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Backup Diff", GUILayout.Width(160f));
                            m_Controller.BackupDiff = EditorGUILayout.Toggle(m_Controller.BackupDiff);
                        }
                        EditorGUILayout.EndHorizontal();
                        if (m_Controller.BackupDiff)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                EditorGUILayout.LabelField("Backup Version", GUILayout.Width(160f));
                                m_Controller.BackupVersion = EditorGUILayout.Toggle(m_Controller.BackupVersion);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Length Limit", GUILayout.Width(160f));
                            EditorGUILayout.BeginVertical();
                            {
                                int lengthLimitIndex = EditorGUILayout.Popup(m_LengthLimitIndex, LengthLimitForDisplay);
                                if (m_LengthLimitIndex != lengthLimitIndex)
                                {
                                    m_LengthLimitIndex = lengthLimitIndex;
                                    if (m_LengthLimitIndex < LengthLimit.Length)
                                    {
                                        m_Controller.LengthLimit = LengthLimit[m_LengthLimitIndex];
                                    }
                                }

                                if (m_LengthLimitIndex >= LengthLimit.Length)
                                {
                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        m_Controller.LengthLimit = EditorGUILayout.IntField(m_Controller.LengthLimit);
                                        if (m_Controller.LengthLimit < 0)
                                        {
                                            m_Controller.LengthLimit = 0;
                                        }

                                        GUILayout.Label(" MB", GUILayout.Width(30f));
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Target Version", GUILayout.Width(160f));
                            int value = EditorGUILayout.Popup(m_TargetVersionIndex, m_VersionNamesForTargetDisplay);
                            if (m_TargetVersionIndex != value)
                            {
                                m_TargetVersionIndex = value;
                                RefreshSourceVersionCount();
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("Source Version", GUILayout.Width(160f));
                            EditorGUILayout.BeginVertical();
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    EditorGUILayout.LabelField(m_SourceVersionCount.ToString() + (m_SourceVersionCount > 1 ? " items" : " item") + " selected.");
                                    if (GUILayout.Button("Select All Except <None>", GUILayout.Width(180f)))
                                    {
                                        m_SourceVersionIndexes[0] = false;
                                        for (int i = 1; i < m_SourceVersionIndexes.Length; i++)
                                        {
                                            m_SourceVersionIndexes[i] = true;
                                        }

                                        RefreshSourceVersionCount();
                                    }
                                    if (GUILayout.Button("Select All", GUILayout.Width(100f)))
                                    {
                                        for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
                                        {
                                            m_SourceVersionIndexes[i] = true;
                                        }

                                        RefreshSourceVersionCount();
                                    }
                                    if (GUILayout.Button("Select None", GUILayout.Width(100f)))
                                    {
                                        for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
                                        {
                                            m_SourceVersionIndexes[i] = false;
                                        }

                                        RefreshSourceVersionCount();
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                                EditorGUILayout.BeginHorizontal();
                                {
                                    int count  = m_VersionNamesForSourceDisplay.Length;
                                    int column = 5;
                                    int row    = (count - 1) / column + 1;
                                    for (int i = 0; i < column && i < count; i++)
                                    {
                                        EditorGUILayout.BeginVertical();
                                        {
                                            for (int j = 0; j < row; j++)
                                            {
                                                int index = j * column + i;
                                                if (index < count)
                                                {
                                                    bool isTarget = index - 1 == m_TargetVersionIndex;
                                                    EditorGUI.BeginDisabledGroup(isTarget);
                                                    {
                                                        bool selected = GUILayout.Toggle(m_SourceVersionIndexes[index], isTarget ? m_VersionNamesForSourceDisplay[index] + " [Target]" : m_VersionNamesForSourceDisplay[index], "button");
                                                        if (m_SourceVersionIndexes[index] != selected)
                                                        {
                                                            m_SourceVersionIndexes[index] = selected;
                                                            RefreshSourceVersionCount();
                                                        }
                                                    }
                                                    EditorGUI.EndDisabledGroup();
                                                }
                                            }
                                        }
                                        EditorGUILayout.EndVertical();
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    GUILayout.Space(2f);
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(2f);
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(m_Controller.Platform == Platform.Undefined || string.IsNullOrEmpty(m_Controller.CompressionHelperTypeName) || !m_Controller.IsValidWorkingDirectory || m_SourceVersionCount <= 0);
                    {
                        if (GUILayout.Button("Start Build Resource Packs"))
                        {
                            string[] sourceVersions = new string[m_SourceVersionCount];
                            int      count          = 0;
                            for (int i = 0; i < m_SourceVersionIndexes.Length; i++)
                            {
                                if (m_SourceVersionIndexes[i])
                                {
                                    sourceVersions[count++] = i > 0 ? m_VersionNames[i - 1] : null;
                                }
                            }

                            m_Controller.BuildResourcePacks(sourceVersions, m_VersionNames[m_TargetVersionIndex]);
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }