添加对话框事件以及对话持久化文件
This commit is contained in:
4
.idea/.idea.Dontback/.idea/vcs.xml
generated
4
.idea/.idea.Dontback/.idea/vcs.xml
generated
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
3
Assets/Scripts/Data.meta
Normal file
3
Assets/Scripts/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3157b26b247048edabb8d3813d750ae5
|
||||||
|
timeCreated: 1726032247
|
||||||
5
Assets/Scripts/Data/DialogData.cs
Normal file
5
Assets/Scripts/Data/DialogData.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
public struct DialogData
|
||||||
|
{
|
||||||
|
public int index;
|
||||||
|
public string content;
|
||||||
|
}
|
||||||
3
Assets/Scripts/Data/DialogData.cs.meta
Normal file
3
Assets/Scripts/Data/DialogData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7db3fb11d36041c5adeba19179fb8f80
|
||||||
|
timeCreated: 1726032238
|
||||||
12
Assets/Scripts/Event/EventArgs/DialogPopArgs.cs
Normal file
12
Assets/Scripts/Event/EventArgs/DialogPopArgs.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Event.EventArgs
|
||||||
|
{
|
||||||
|
public class DialogPopArgs : System.EventArgs
|
||||||
|
{
|
||||||
|
public int Index { get; private set; }
|
||||||
|
|
||||||
|
public DialogPopArgs(int index)
|
||||||
|
{
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/Event/EventArgs/DialogPopArgs.cs.meta
Normal file
3
Assets/Scripts/Event/EventArgs/DialogPopArgs.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 29958321a8bd415ab793cc37deb6a859
|
||||||
|
timeCreated: 1726033413
|
||||||
6
Assets/Scripts/Event/EventHandler/DialogPopHandler.cs
Normal file
6
Assets/Scripts/Event/EventHandler/DialogPopHandler.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
using Event.EventArgs;
|
||||||
|
|
||||||
|
namespace Event.EventHandler
|
||||||
|
{
|
||||||
|
public delegate void DialogPopHandler(DialogPopArgs e);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4803bc41d6fa4ae884b015a21124459e
|
||||||
|
timeCreated: 1726033554
|
||||||
@@ -33,10 +33,16 @@ namespace Event
|
|||||||
}
|
}
|
||||||
|
|
||||||
public event CameraInterActHandler CameraInterAct;
|
public event CameraInterActHandler CameraInterAct;
|
||||||
|
public event DialogPopHandler DialogPop;
|
||||||
|
|
||||||
public void OnCameraInterAct(GameObject item)
|
public void OnCameraInterAct(GameObject item)
|
||||||
{
|
{
|
||||||
CameraInterAct?.Invoke(new CameraInterActArgs(item));
|
CameraInterAct?.Invoke(new CameraInterActArgs(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnDialogPop(int index)
|
||||||
|
{
|
||||||
|
DialogPop?.Invoke(new DialogPopArgs(index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
42
Assets/Scripts/UI/Dialog.cs
Normal file
42
Assets/Scripts/UI/Dialog.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Event;
|
||||||
|
using Event.EventArgs;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace UI
|
||||||
|
{
|
||||||
|
public class Dialog : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private string dialogsPath;
|
||||||
|
[SerializeField] private string dialogJson;
|
||||||
|
private Dictionary<int,string> _dialogsMap = new();
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
dialogsPath = Application.persistentDataPath + "/" + "Dialogs.json";
|
||||||
|
|
||||||
|
if (File.Exists(dialogsPath))
|
||||||
|
{
|
||||||
|
dialogJson = File.ReadAllText(dialogsPath);
|
||||||
|
_dialogsMap = JsonConvert.DeserializeObject<Dictionary<int,string>>(dialogJson);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dialogsMap.Add(0, "New Dialog");
|
||||||
|
dialogJson = JsonConvert.SerializeObject(_dialogsMap, Formatting.Indented);
|
||||||
|
File.WriteAllText(dialogsPath, dialogJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
EventManager.Instance.DialogPop += OpenDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenDialog(DialogPopArgs e)
|
||||||
|
{
|
||||||
|
Debug.Log(_dialogsMap[e.Index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/UI/Dialog.cs.meta
Normal file
3
Assets/Scripts/UI/Dialog.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 166525e51f1d41a2addfb1df626096fc
|
||||||
|
timeCreated: 1726032143
|
||||||
@@ -12,7 +12,7 @@ PlayerSettings:
|
|||||||
targetDevice: 2
|
targetDevice: 2
|
||||||
useOnDemandResources: 0
|
useOnDemandResources: 0
|
||||||
accelerometerFrequency: 60
|
accelerometerFrequency: 60
|
||||||
companyName: DefaultCompany
|
companyName: CrashWork
|
||||||
productName: Dontback
|
productName: Dontback
|
||||||
defaultCursor: {fileID: 0}
|
defaultCursor: {fileID: 0}
|
||||||
cursorHotspot: {x: 0, y: 0}
|
cursorHotspot: {x: 0, y: 0}
|
||||||
@@ -160,7 +160,8 @@ PlayerSettings:
|
|||||||
resetResolutionOnWindowResize: 0
|
resetResolutionOnWindowResize: 0
|
||||||
androidSupportedAspectRatio: 1
|
androidSupportedAspectRatio: 1
|
||||||
androidMaxAspectRatio: 2.1
|
androidMaxAspectRatio: 2.1
|
||||||
applicationIdentifier: {}
|
applicationIdentifier:
|
||||||
|
Standalone: com.DefaultCompany.Dontback
|
||||||
buildNumber:
|
buildNumber:
|
||||||
Standalone: 0
|
Standalone: 0
|
||||||
VisionOS: 0
|
VisionOS: 0
|
||||||
@@ -647,7 +648,8 @@ PlayerSettings:
|
|||||||
scriptingDefineSymbols: {}
|
scriptingDefineSymbols: {}
|
||||||
additionalCompilerArguments: {}
|
additionalCompilerArguments: {}
|
||||||
platformArchitecture: {}
|
platformArchitecture: {}
|
||||||
scriptingBackend: {}
|
scriptingBackend:
|
||||||
|
Standalone: 1
|
||||||
il2cppCompilerConfiguration: {}
|
il2cppCompilerConfiguration: {}
|
||||||
il2cppCodeGeneration: {}
|
il2cppCodeGeneration: {}
|
||||||
managedStrippingLevel:
|
managedStrippingLevel:
|
||||||
|
|||||||
Reference in New Issue
Block a user