Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多个保存在一起_C#_Unity3d - Fatal编程技术网

C# 多个保存在一起

C# 多个保存在一起,c#,unity3d,C#,Unity3d,我对Unity和编程语言都很陌生,所以请原谅我的noobiness lol 我正在做一个记事本,我一直在试图找出如何获得多个笔记以及笔记的标题。我有一个保存笔记的基本脚本,可以保存一个笔记,但我不知道如何保存多个笔记。我甚至试着做了两次扑救,但都没有成功 这是我的脚本,完全公开,我在一个教程后写了一半,另一半是我尝试进行多次保存 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 使用UnityEngine.UI; 使用UnityEngin

我对Unity和编程语言都很陌生,所以请原谅我的noobiness lol

我正在做一个记事本,我一直在试图找出如何获得多个笔记以及笔记的标题。我有一个保存笔记的基本脚本,可以保存一个笔记,但我不知道如何保存多个笔记。我甚至试着做了两次扑救,但都没有成功

这是我的脚本,完全公开,我在一个教程后写了一半,另一半是我尝试进行多次保存

使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用UnityEngine.SceneManagement;
公共类SaveControl:单行为
{
无效唤醒()
{
DontDestroyOnLoad(游戏对象);
}
公共字符串TEXT1;
公共字符串名称1;
公共字符串文本2;
公共字符串名称2;
公开游戏对象;
公共游戏对象名称占位符;
公共游戏对象占位符;
公共游戏对象自定义名称;
[序列化字段]
public int noteSave=1;
公共无效加载按钮1()
{
{
场景管理器。加载场景(1);
noteSave=1;
theText1=PlayerPrefs.GetString(“NoteContents1”);
theName1=PlayerPrefs.GetString(“theName1”);
占位符.GetComponent().text=theText1;
namePlaceHolder.GetComponent().text=theName1;
字符串customName=theName1;
}
}
公共无效加载按钮2()
{
noteSave=2;
theText2=PlayerPrefs.GetString(“NoteContents2”);
theName2=PlayerPrefs.GetString(“theName2”);
placeHolder.GetComponent().text=文本2;
namePlaceHolder.GetComponent().text=theName2;
字符串customName=theName2;
场景管理器。加载场景(1);
}
公共作废OkayButton()
{
如果(noteSave==1)
{
string key=“NoteContents”+noteNumber;
Log(“键为“'+key+””);
theText1=ourNote.GetComponent().text;
theName1=customName.GetComponent().text;
PlayerPrefs.SetString(“NoteContents1”,theText1);
打印(名称1);
场景管理器。加载场景(0);
}
else if(noteSave==2)
{
TEXT2=ourNote.GetComponent().text;
theName2=customName.GetComponent().text;
PlayerPrefs.SetString(“NoteContents2”,文本2);
印刷品(名称2);
场景管理器。加载场景(0);
}
}

}
您可以使用便笺名称获取便笺,这样您就可以保存多个便笺

这里有一个例子

public void LoadButton() {
   // i assume this is your note's title/name
   string noteName = customName.GetComponent<Text>().text;
   string noteContent = PlayerPrefs.GetString("noteName");

   ourNote.GetComponent<Text>().text = noteContent
}

public void SaveButton() {
   string noteName = customName.GetComponent<Text>().text;
   string noteContent = ourNote.GetComponent<Text>().text;
   PlayerPrefs.SetString(noteName, noteContent);
   PlayerPrefs.Save();
}
public void LoadButton(){
//我想这是你便条的标题/名称
字符串noteName=customName.GetComponent().text;
字符串noteContent=PlayerPrefs.GetString(“noteName”);
ourNote.GetComponent().text=noteContent
}
公共作废保存按钮(){
字符串noteName=customName.GetComponent().text;
字符串noteContent=ourNote.GetComponent().text;
PlayerPrefs.SetString(noteName,noteContent);
PlayerPrefs.Save();
}

正如您在本例中看到的,您需要设置便笺的名称以获取便笺的上下文。

哦,好的,非常感谢!我想我已经解决了大部分问题,只是一个简单的问题,当有一个自定义名称的新保存时,我如何让它创建一个按钮?这将使它变得更难,因为现在你必须保存所有保存的名称并加载它们,然后使用它添加按钮,我决定把这些复杂的事情留给未来的项目,哈哈,但我仍然在尝试使用多个预设按钮来实现多个保存,但它不起作用。这是我目前的代码,对不起,如果我只是哑巴哈哈,我甚至试着让它打印笔记名称和笔记内容,它打印正确,但当我点击加载按钮,它只是空白。