1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use super::*;
mod der;
mod ser;
#[derive(Clone, Debug, Serialize)]
pub struct UnityCodegen {
pub enable: bool,
pub project: String,
pub output: String,
pub namespace: String,
pub instance_name: String,
pub manager_name: String,
pub suffix_table: String,
pub support_clone: bool,
pub legacy_using: bool,
pub legacy_null_null: bool,
pub binary: UnityBinaryConfig,
pub xml: UnityXmlConfig,
}
#[derive(Clone, Debug, Serialize)]
pub struct UnityBinaryConfig {
pub enable: bool,
pub output: String,
}
#[derive(Clone, Debug, Serialize)]
pub struct UnityXmlConfig {
pub enable: bool,
pub output: String,
}
impl UnityCodegen {
pub fn unity_path(&self, root: &Path) -> XResult<PathBuf> {
let project = PathBuf::from(&self.project);
let project = match project.is_absolute() {
true => project,
false => root.join(project),
};
Ok(project.canonicalize()?)
}
pub fn unity_binary_path(&self, root: &Path, file_name: &str) -> XResult<PathBuf> {
let dir = self.unity_path(root)?.join(&self.binary.output);
let path = dir.join(file_name).with_extension("binary");
Ok(path)
}
pub fn unity_xml_path(&self, root: &Path, file_name: &str) -> XResult<PathBuf> {
let dir = self.unity_path(root)?.join(&self.binary.output);
let path = dir.join(file_name).with_extension("xml");
Ok(path)
}
pub fn unity_csharp_path(&self, root: &Path, file_name: &str) -> XResult<PathBuf> {
let dir = self.unity_path(root)?.join(&self.output);
let path = dir.join(file_name).with_extension("cs");
Ok(path)
}
pub fn unity_manager_path(&self, root: &Path) -> XResult<PathBuf> {
self.unity_csharp_path(root, &self.manager_name)
}
pub fn unity_cs_relative(&self, file_name: &str) -> String {
format!("{}/{}.cs", self.output, file_name)
}
pub fn unity_bin_relative(&self, file_name: &str) -> String {
format!("{}/{}.binary", self.binary.output, file_name)
}
pub fn unity_xml_relative(&self, file_name: &str) -> String {
format!("{}/{}.xml", self.xml.output, file_name)
}
}