Exemple #1
0
        public static void CreateOrUpdateSavedJob(string JobName, IgorPersistentJobConfig JobConfig)
        {
            IgorConfig Inst = GetInstance();

            if (Inst != null)
            {
                int CurrentJobIndex = 0;

                foreach (IgorPersistentJobConfig CurrentJob in Inst.JobConfigs)
                {
                    if (CurrentJob.JobName == JobName)
                    {
                        Inst.JobConfigs[CurrentJobIndex] = JobConfig;

                        Inst.Save();

                        return;
                    }

                    ++CurrentJobIndex;
                }

                Inst.JobConfigs.Add(JobConfig);

                Inst.Save();
            }
        }
        public override string DrawJobInspectorAndGetEnabledParams(string CurrentParams)
        {
            string EnabledParams = CurrentParams;

            IgorConfigWindow        ConfigurationWindow = IgorConfigWindow.OpenOrGetConfigWindow();
            IgorPersistentJobConfig CurrentJob          = ConfigurationWindow.CurrentJobInst;
            string CurrentJobAsString = CurrentJob != null ? CurrentJob.JobName : string.Empty;
            string TargetDirectory    = kPlayerSettingsFolder + "/" + CurrentJobAsString;

            GUILayout.BeginHorizontal();
            {
                string SelectedProjectSettingsAsString = IgorRuntimeUtils.GetStringParam(EnabledParams, PlayerSettingFilesToOverrideFlag).Trim('"');

                if (!string.IsNullOrEmpty(SelectedProjectSettingsAsString))
                {
                    int OutResult = 0;
                    if (Int32.TryParse(SelectedProjectSettingsAsString, out OutResult))
                    {
                        SelectedProjectSettingsAsInt = OutResult;
                    }
                }

                int newValue = EditorGUILayout.MaskField(SelectedProjectSettingsAsInt, kProjectSettingFiles);

                if (newValue != SelectedProjectSettingsAsInt)
                {
                    SelectedProjectSettingsAsInt = newValue;
                    if (newValue != 0)
                    {
                        EnabledParams = IgorRuntimeUtils.SetStringParam(EnabledParams, PlayerSettingFilesToOverrideFlag, SelectedProjectSettingsAsInt.ToString());
                        EnabledParams = IgorRuntimeUtils.SetStringParam(EnabledParams, PlayerSettingsPathFlag, '"' + TargetDirectory + '"');
                    }
                    else
                    {
                        EnabledParams = IgorRuntimeUtils.ClearParam(EnabledParams, PlayerSettingFilesToOverrideFlag);
                        EnabledParams = IgorRuntimeUtils.ClearParam(EnabledParams, PlayerSettingsPathFlag);
                    }
                }
            }
            GUILayout.EndHorizontal();

            string FilesToSave = string.Empty;

            for (int i = 0; i < kProjectSettingFiles.Length; ++i)
            {
                if (((1 << i) & SelectedProjectSettingsAsInt) != 0)
                {
                    FilesToSave += ((string.IsNullOrEmpty(FilesToSave) ? string.Empty : ", ") + kProjectSettingFiles[i].Replace(".asset", string.Empty));
                }
            }

            GUILayout.Space(5f);
            GUILayout.Label("Files to save: " + FilesToSave);

            if (Directory.Exists(TargetDirectory))
            {
                GUILayout.Space(5f);
                string[] SourceFilesPaths = Directory.GetFiles(TargetDirectory);

                string ExistingOverrides = string.Empty;
                foreach (string SourceFilePath in SourceFilesPaths)
                {
                    ExistingOverrides += ((string.IsNullOrEmpty(ExistingOverrides) ? string.Empty : ", ") + Path.GetFileName(SourceFilePath).Replace(kIgorProjectSettingExtension, string.Empty));
                }

                GUILayout.Label("Existing overrides on disk: " + ExistingOverrides);
                GUILayout.Space(5f);
            }

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = CurrentJob != null && SelectedProjectSettingsAsInt != 0;
                if (GUILayout.Button("Save", GUILayout.ExpandWidth(false)))
                {
                    if (!Directory.Exists(kPlayerSettingsFolder))
                    {
                        Directory.CreateDirectory(kPlayerSettingsFolder);
                    }

                    IgorRuntimeUtils.DeleteDirectory(TargetDirectory);
                    Directory.CreateDirectory(TargetDirectory);

                    string[] SourceFilesPaths = Directory.GetFiles("ProjectSettings");
                    foreach (string SourceFilePath in SourceFilesPaths)
                    {
                        if (!SourceFilePath.EndsWith(".meta"))
                        {
                            string FileName = Path.GetFileName(SourceFilePath);

                            int IndexInKnownAssetList = Array.IndexOf(kProjectSettingFiles, FileName, 0, kProjectSettingFiles.Length);
                            if (IndexInKnownAssetList != -1)
                            {
                                if ((((1 << IndexInKnownAssetList) & SelectedProjectSettingsAsInt) != 0) || SelectedProjectSettingsAsInt == -1)
                                {
                                    string DestFilePath = SourceFilePath.Replace("ProjectSettings\\", string.Empty);
                                    DestFilePath = TargetDirectory + "/" + Path.ChangeExtension(DestFilePath, kIgorProjectSettingExtension);
                                    IgorRuntimeUtils.CopyFile(SourceFilePath, DestFilePath);
                                }
                            }
                        }
                    }

                    AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                }

                string Tooltip = Directory.Exists(TargetDirectory) ? string.Empty : "Expected PlayerSettings directory " + " doesn't exist.";

                GUI.enabled &= Directory.Exists(TargetDirectory);
                if (GUILayout.Button(new GUIContent("Load saved settings file", Tooltip), GUILayout.ExpandWidth(false)))
                {
                    CopyStoredPlayerSettingsOverCurrent(TargetDirectory);
                }

                GUI.enabled = true;
            }
            GUILayout.EndHorizontal();

            return(EnabledParams);
        }