I’m using TextMeshPro 3.0.6
using UnityEngine;
using System.Collections;
using System.IO;
using TMPro;
public class SavingGame : MonoBehaviour
{
public int resWidth = 1920;
public int resHeight = 1080;
public SaveLoad saveLoad;
public Description description;
public TextMeshProUGUI savedGameDescriptionText;
private static int countName;
private void Start()
{
countName = 0;
string[] dirs = Directory.GetDirectories(Application.persistentDataPath + "\\" + "Saved Screenshots",
"*.*", SearchOption.TopDirectoryOnly);
if(dirs.Length > 0)
{
countName = dirs.Length;
}
}
public static string ScreenShotName(int width, int height)
{
return string.Format("{0}/Saved Screenshots/SaveSlot{1} SavedGameSlot_{2}x{3}_{4}/SavedGameSlot_{1}x{2}_{3}.png",
Application.persistentDataPath,
countName,
width, height, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
}
void Update()
{
if (Input.GetKeyDown("k"))
{
description.StartFading(true);
}
}
public void Save()
{
var time = description.StartFading(false);
StartCoroutine(StartSaving(time));
}
IEnumerator StartSaving(float time)
{
yield return new WaitForSeconds(time);
string filename = ScreenShotName(resWidth, resHeight);
string directory = Path.GetDirectoryName(filename);
Directory.CreateDirectory(directory);
ScreenCapture.CaptureScreenshot(filename);
string descriptionContent = savedGameDescriptionText.text;
if (savedGameDescriptionText.text.Length != 0)
{
string descriptionFileFolder = directory + "\\" + "Description.txt";
File.WriteAllText(descriptionFileFolder, descriptionContent);
}
StartCoroutine(saveLoad.SaveWithTime(directory, Path.GetFileNameWithoutExtension(filename) + ".savegame.txt"));
countName++;
}
}
No matter how i’m checking if the variable savedGameDescriptionText is empty it’s never empty.
I tried to check first only if savedGameDescriptionText is not != “” but even if it’s “” it’s entering.
Then i tired with the text.Length != 0 but using a break point i see that the Length value is 1.
In the editor i see that the text i s empty :
Text Input is empty and i see with a breakpoint that savedGameDescirptionText is “” but the Length value is still 1 so the checking if is not empty always true :
I can check if the Length is 1 like Length == 1 but that’s not a solution.
I’m pressing the K key to bring up the canvas changing the cnavas alpha from 0 to 1 then enable true the input field so i can type inside some text then when pressing the Save button it’s changing back the canvas alpha from 1 to 0 and then it’s calling the Save method. then i see that the Length value is 1.
The Placeholder have text inside Enter description…
but i’m not using the Placeholder in the script but the Saved Game Description Text.