Exemplo n.º 1
0
        public void Save(string fileName, ScreenshotHelper ssh)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            if (ssh.shotInfo.Count <= 0)
            {
                var tempDelegate = ssh.DefaultsSet;
                ssh.DefaultsSet = null;
                ssh.SetDefaults();
                ssh.DefaultsSet = tempDelegate;
            }

            sizes          = ssh.shotInfo;
            orientation    = ssh.orientation;
            lastSavePath   = ssh.savePath;
            buildPathRoot  = ssh.buildSavePathRoot;
            buildPathExtra = ssh.buildSavePathExtra;
            textureFormat  = ssh.SSHTextureFormat;

            var serializer = new XmlSerializer(typeof(SSHPreset));

            using (var stream = new FileStream(fileName, FileMode.Create))
                serializer.Serialize(stream, this);
        }
Exemplo n.º 2
0
        void OnEnable()
        {
            ScreenshotHelper ssHelper = (ScreenshotHelper)target;

            bool loadConfig = false;

            if (ssHelper.shotInfo.Count == 0 || !string.IsNullOrEmpty(ssHelper.configFile))
            {
                if (!string.IsNullOrEmpty(ssHelper.configFile))
                {
                    if (File.Exists(ssHelper.configFile))
                    {
                        loadConfig = true;
                    }
                }

                if (loadConfig)
                {
                    LoadPresetFile(ssHelper.configFile, ssHelper);
                }
                else
                {
                    ssHelper.SetDefaults();
                }
            }

            if (!loadConfig)
            {
                LoadPresetFile(SSHPreset.DefaultSavePath(), ssHelper);
                if (File.Exists(SSHPreset.DefaultSavePath()))
                {
                    File.Delete(SSHPreset.DefaultSavePath());
                }
            }

            ssHelper.PathChange = PathChange;
            //myTarget.DefaultsSet = SaveSettings;
        }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            ScreenshotHelper ssHelper = (ScreenshotHelper)target;

            serializedObject.Update();


            var cameraArrayProp = serializedObject.FindProperty("cameras");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(
                cameraArrayProp,
                new GUIContent("Cameras (leave empty to autodetect)"), true);

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }


            RenderTextureToggleAndWarning(ssHelper);

            CameraSolidColorTransparencyWarning(ssHelper);

            MakeSpace(1);

            EditorGUI.BeginChangeCheck();

            MakeSpace(1);
            ssHelper.orientation = (SSHOrientation)EditorGUILayout.EnumPopup(
                "Orientation", ssHelper.orientation);

            if (EditorGUI.EndChangeCheck())
            {
                ssHelper.UpdateDimensions();
            }

            //sizes header
            MakeSpace(1);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Screen Shot Sizes", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();

            ssHelper.fileNamePrefix =
                EditorGUILayout.TextField("Filename prefix", ssHelper.fileNamePrefix);
            MakeSpace(1);

            SetSizesSubs(ssHelper);

            //add a size
            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(ssHelper.IsTakingShots);
            if (GUILayout.Button(new GUIContent(" Add a size", AddIcon), ButtonHeight))
            {
                ssHelper.shotInfo.Add(new ShotSize(0, 0));
            }

            //ssHelper.didPressEditorScreenshotButton = false; didStartTaking = false;

            if (GUILayout.Button(new GUIContent("Take Shots!", ShutterIcon)))
            {
                EditorApplication.isPlaying             = true;
                ssHelper.didPressEditorScreenshotButton = true;
            }

            //Debug.LogFormat("didPress: {0}  isPlay: {1}", ssHelper.didPressEditorScreenshotButton, EditorApplication.isPlaying);

            if (ssHelper.didPressEditorScreenshotButton && EditorApplication.isPlaying)
            {
                didStartTaking = true;
                ssHelper.didPressEditorScreenshotButton = false;

                ssHelper.OnComplete += () => {
                    //Debug.Log("OnComplete");
                    EditorApplication.isPlaying = false;
                };
                //Debug.Log("Call runtake");
                ssHelper.GetScreenShots();
            }

            if (didStartTaking && !EditorApplication.isPlaying)
            {
                didStartTaking = false;
                ssHelper.didPressEditorScreenshotButton = false;
            }

            MakeSpace(3);

            ssHelper.openFolderWhenDone = EditorGUILayout.ToggleLeft(
                "Open folder when done?",
                ssHelper.openFolderWhenDone);

            EditorGUILayout.HelpBox(
                "In-editor Save location: " + ssHelper.savePath, MessageType.None);

            if (GUILayout.Button(
                    new GUIContent(" Set in-editor save location", FolderIcon), ButtonHeight))
            {
                ssHelper.savePath = GameViewUtils.SelectFileFolder(
                    Directory.GetCurrentDirectory(), "");
                PathChange(ssHelper.savePath);
            }

            MakeSpace(1);

            EditorGUILayout.HelpBox(
                "Build Save location example: " + ssHelper.BuildSaveLocation(), MessageType.None);


            if (GUILayout.Button(
                    new GUIContent(" Set build save location", FolderIcon), ButtonHeight))
            {
                ScreenshotHelperBuildSaveLocationWindow.ShowWindow(ssHelper);
            }


            MakeSpace(2);

            if (GUILayout.Button(new GUIContent(" Save Presets", SaveIcon), ButtonHeight))
            {
                string newConfig = SavePreset(ssHelper);
                if (!string.IsNullOrEmpty(newConfig))
                {
                    ssHelper.configFile = newConfig;
                }
            }

            LoadPresetsButton(ssHelper);

            MakeSpace(2);

            if (GUILayout.Button(new GUIContent(" Load Defaults", OpenIcon), ButtonHeight))
            {
                ssHelper.SetDefaults();
                ssHelper.configFile = "";
            }

            EditorGUI.EndDisabledGroup();

            MakeSpace(1);
        }