blob: 150776770e6a98b5ddbbed1a6e9d91924b1460f1 (
plain) (
blame)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
using UnityEngine;
using System.IO;
using System.Collections.Generic;
namespace Lean.Localization
{
[System.Serializable]
public class LeanPrefab
{
public Object Root;
[SerializeField]
private List<LeanSource> sources;
[System.NonSerialized]
private int buildingCount;
[System.NonSerialized]
private bool buildingModified;
private static List<LeanSource> tempSources = new List<LeanSource>();
public List<LeanSource> Sources
{
get
{
if (sources == null)
{
sources = new List<LeanSource>();
}
return sources;
}
}
public bool RebuildSources()
{
if (sources == null)
{
sources = new List<LeanSource>();
}
if (Root != null)
{
if (Root is LeanSource)
{
buildingCount = 0;
buildingModified = false;
AddSource((LeanSource)Root);
return FinalizeBuild();
}
else if (Root is GameObject)
{
buildingCount = 0;
buildingModified = false;
FindFromGameObject(((GameObject)Root).transform);
return FinalizeBuild();
}
#if UNITY_EDITOR
else // Folder
{
var rootPath = UnityEditor.AssetDatabase.GetAssetPath(Root);
if (string.IsNullOrEmpty(rootPath) == false)
{
buildingCount = 0;
buildingModified = false;
var basePath = Application.dataPath;
var baseTail = "Assets";
if (basePath.EndsWith(baseTail) == true)
{
basePath = basePath.Substring(0, basePath.Length - baseTail.Length);
}
FindFromFolder(basePath, rootPath);
return FinalizeBuild();
}
}
#endif
}
return false;
}
private bool FinalizeBuild()
{
for (var i = sources.Count - 1; i >= buildingCount; i--)
{
sources.RemoveAt(i); buildingModified = true;
}
return buildingModified;
}
private void AddSource(LeanSource source)
{
if (buildingCount < sources.Count)
{
if (sources[buildingCount] != source)
{
sources[buildingCount] = source;
buildingModified = true;
}
}
else
{
sources.Add(source);
buildingModified = true;
}
buildingCount++;
}
private void FindFromGameObject(Transform prefab)
{
prefab.GetComponents(tempSources);
if (tempSources.Count > 0)
{
for (var i = 0; i < tempSources.Count; i++)
{
AddSource(tempSources[i]);
}
}
else
{
for (var i = 0; i < prefab.childCount; i++)
{
FindFromGameObject(prefab.GetChild(i));
}
}
}
#if UNITY_EDITOR
private void FindFromFolder(string basePath, string rootPath)
{
var fullPath = basePath + rootPath;
if (Directory.Exists(fullPath) == true)
{
var subFolders = Directory.GetDirectories(fullPath);
for (var i = 0; i < subFolders.Length; i++)
{
FindFromFolder(basePath, subFolders[i].Substring(basePath.Length));
}
var subAssets = Directory.GetFiles(fullPath, "*.prefab");
for (var i = 0; i < subAssets.Length; i++)
{
FindFromFolder(basePath, subAssets[i].Substring(basePath.Length));
}
}
// File
else
{
var subGameObject = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(rootPath);
if (subGameObject != null)
{
FindFromGameObject(subGameObject.transform);
}
}
}
#endif
}
}
|