Skip to content

Commit fb8b9b4

Browse files
committed
Merge branch 'beta'
2 parents 0078e4c + 8dce15d commit fb8b9b4

File tree

19 files changed

+242
-63
lines changed

19 files changed

+242
-63
lines changed

Assets/MapEditor/Editor/API/Functions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,14 @@ public static void SnapToGround(PrefabDataHolder target)
743743
target.SnapToGround();
744744
Elements.EndToolbarHorizontal();
745745
}
746+
747+
public static void ToggleLights(PrefabDataHolder target)
748+
{
749+
Elements.BeginToolbarHorizontal();
750+
if (Elements.ToolbarButton(ToolTips.toggleLights))
751+
target.ToggleLights();
752+
Elements.EndToolbarHorizontal();
753+
}
746754
#endregion
747755

748756
#region Functions

Assets/MapEditor/Editor/PrefabDataHolderEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public override void OnInspectorGUI()
1313
Functions.PrefabCategory(script);
1414
Functions.PrefabID(script);
1515
Functions.SnapToGround(script);
16+
Functions.ToggleLights(script);
1617
}
1718
}

Assets/MapEditor/Editor/TreeView/PrefabsList/PrefabsListTreeView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static List<PrefabsListElement> GetPrefabsListElements(bool showAll = fal
112112
}
113113
else
114114
{
115-
var treeviewItem = new PrefabsListElement(prefabName, i, prefabID++, manifestString);
115+
var treeviewItem = new PrefabsListElement(prefabName.Replace('_', ' '), i, prefabID++, manifestString);
116116
if (treeviewItem.rustID == 0)
117117
continue;
118118
prefabsListElements.Add(treeviewItem);

Assets/MapEditor/Extensions/GameObjectExt.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ public static class GameObjectExt
55
public static void SetLayerRecursively(this GameObject go, int layer)
66
{
77
foreach (var transform in go.GetComponentsInChildren<Transform>())
8-
{
98
transform.gameObject.layer = layer;
10-
}
119
}
1210

1311
public static void SetTagRecursively(this GameObject go, string tag)
1412
{
1513
foreach (var transform in go.GetComponentsInChildren<Transform>())
16-
{
1714
transform.gameObject.tag = tag;
18-
}
15+
}
16+
17+
public static void RemoveNameUnderscore(this GameObject go)
18+
{
19+
go.name = go.name.Replace('_', ' ');
1920
}
2021
}

Assets/MapEditor/Managers/AssetManager.cs

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ public static class AssetManager
77
public static string BundlePath { get; private set; }
88

99
public static GameManifest Manifest { get; private set; }
10-
private const string ManifestPath = "assets/manifest.asset";
10+
11+
public const string ManifestPath = "assets/manifest.asset";
12+
public const string AssetDumpPath = "AssetDump.txt";
13+
public const string MaterialsListPath = "MaterialsList.txt";
1114

1215
public static AssetBundleManifest AssetManifest { get; private set; }
1316

@@ -18,6 +21,8 @@ public static class AssetManager
1821
public static Dictionary<string, AssetBundle> AssetPaths { get; private set; } = new Dictionary<string, AssetBundle>(System.StringComparer.OrdinalIgnoreCase);
1922
public static Dictionary<string, Object> Cache { get; private set; } = new Dictionary<string, Object>();
2023

24+
public static List<string> ManifestStrings { get => IsInitialised ? GetManifestStrings() : new List<string>(); private set => ManifestStrings = value; }
25+
2126
public static bool IsInitialised { get; private set; }
2227

2328
/// <summary>Loads the prefabs from the Rust prefab bundle.</summary>
@@ -32,7 +37,7 @@ public static void Initialise(string bundlesRoot)
3237
return;
3338
}
3439

35-
if (!SettingsManager.RustDirectory.EndsWith("Rust"))
40+
if (!SettingsManager.RustDirectory.EndsWith("Rust") && !SettingsManager.RustDirectory.EndsWith("RustStaging"))
3641
{
3742
Debug.LogError("Not a valid Rust install directory: " + SettingsManager.RustDirectory);
3843
return;
@@ -70,6 +75,8 @@ public static void Initialise(string bundlesRoot)
7075
Bundles.Add(bundles[i], asset);
7176
foreach (var filename in asset.GetAllAssetNames())
7277
AssetPaths.Add(filename, asset);
78+
foreach (var filename in asset.GetAllScenePaths())
79+
AssetPaths.Add(filename, asset);
7380
}
7481

7582
Manifest = GetAsset<GameManifest>(ManifestPath);
@@ -88,9 +95,10 @@ public static void Initialise(string bundlesRoot)
8895

8996
AssetDump();
9097
rootBundle.Unload(true);
98+
FixMaterials();
9199
IsInitialised = true;
100+
92101
ProgressBarManager.Clear();
93-
94102
PrefabManager.ReplaceWithLoaded(PrefabManager.PrefabParent.GetComponentsInChildren<PrefabDataHolder>());
95103
}
96104
else
@@ -99,9 +107,7 @@ public static void Initialise(string bundlesRoot)
99107

100108
private static T GetAsset<T>(string filePath) where T : Object
101109
{
102-
AssetBundle bundle = null;
103-
104-
if (!AssetPaths.TryGetValue(filePath, out bundle))
110+
if (!AssetPaths.TryGetValue(filePath, out AssetBundle bundle))
105111
return null;
106112

107113
return bundle.LoadAsset<T>(filePath);
@@ -170,7 +176,7 @@ public static List<string> GetManifestStrings()
170176
/// <summary>Dumps every asset found in the Rust content bundle to a text file.</summary>
171177
public static void AssetDump()
172178
{
173-
using (StreamWriter streamWriter = new StreamWriter("AssetDump.txt", false))
179+
using (StreamWriter streamWriter = new StreamWriter(AssetDumpPath, false))
174180
foreach (var item in AssetPaths.Keys)
175181
streamWriter.WriteLine(item + " : " + ToID(item));
176182
}
@@ -179,8 +185,7 @@ public static string ToPath(uint i)
179185
{
180186
if ((int)i == 0)
181187
return i.ToString();
182-
string str;
183-
if (IDLookup.TryGetValue(i, out str))
188+
if (IDLookup.TryGetValue(i, out string str))
184189
return str;
185190
return i.ToString();
186191
}
@@ -189,9 +194,85 @@ public static uint ToID(string str)
189194
{
190195
if (string.IsNullOrEmpty(str))
191196
return 0;
192-
uint num;
193-
if (PathLookup.TryGetValue(str, out num))
197+
if (PathLookup.TryGetValue(str, out uint num))
194198
return num;
195199
return 0;
196200
}
201+
202+
/// <summary>Sets materials set in the MaterialsList.txt to the shader supplied. Used for certain prefabs which appear black due to the Rust shaders not having
203+
/// all of the dependencies needed to function properly in the project.</summary>
204+
public static void FixMaterials()
205+
{
206+
Shader std = Shader.Find("Standard");
207+
Shader spc = Shader.Find("Standard (Specular setup)");
208+
209+
if (File.Exists(MaterialsListPath))
210+
{
211+
foreach (var item in File.ReadAllLines(MaterialsListPath))
212+
{
213+
var lineSplit = item.Split(':');
214+
lineSplit[0] = lineSplit[0].Trim(' '); // Shader Name
215+
lineSplit[1] = lineSplit[1].Trim(' '); // Material Path
216+
switch (lineSplit[0])
217+
{
218+
case "Standard":
219+
UpdateShader(LoadAsset<Material>(lineSplit[1]), std);
220+
break;
221+
case "Specular":
222+
UpdateShader(LoadAsset<Material>(lineSplit[1]), spc);
223+
break;
224+
}
225+
}
226+
}
227+
LoadAsset<Material>(@"assets/content/nature/overgrowth/models/materials/overgrowth.mat").DisableKeyword("_TINTENABLED_ON"); // Fix for overgrowth materials.
228+
}
229+
230+
/// <summary>Updates the material with the new shaders properties.</summary>
231+
private static void UpdateShader(Material mat, Shader shader)
232+
{
233+
mat.shader = shader;
234+
switch (mat.GetFloat("_Mode"))
235+
{
236+
case 0f:
237+
mat.SetOverrideTag("RenderType", "");
238+
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
239+
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
240+
mat.SetInt("_ZWrite", 1);
241+
mat.DisableKeyword("_ALPHATEST_ON");
242+
mat.DisableKeyword("_ALPHABLEND_ON");
243+
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
244+
mat.renderQueue = -1;
245+
break;
246+
case 1f:
247+
mat.SetOverrideTag("RenderType", "TransparentCutout");
248+
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
249+
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
250+
mat.SetInt("_ZWrite", 1);
251+
mat.EnableKeyword("_ALPHATEST_ON");
252+
mat.DisableKeyword("_ALPHABLEND_ON");
253+
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
254+
mat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
255+
break;
256+
case 2f:
257+
mat.SetOverrideTag("RenderType", "Transparent");
258+
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
259+
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
260+
mat.SetInt("_ZWrite", 0);
261+
mat.DisableKeyword("_ALPHATEST_ON");
262+
mat.EnableKeyword("_ALPHABLEND_ON");
263+
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
264+
mat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
265+
break;
266+
case 3f:
267+
mat.SetOverrideTag("RenderType", "Transparent");
268+
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
269+
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
270+
mat.SetInt("_ZWrite", 0);
271+
mat.DisableKeyword("_ALPHATEST_ON");
272+
mat.DisableKeyword("_ALPHABLEND_ON");
273+
mat.EnableKeyword("_ALPHAPREMULTIPLY_ON");
274+
mat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
275+
break;
276+
}
277+
}
197278
}

Assets/MapEditor/Managers/MapManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using static RustMapEditor.Data.TerrainManager;
1111
using static RustMapEditor.Maths.Array;
1212
using static WorldConverter;
13-
using RustMapEditor.Data;
1413

1514
public static class MapManager
1615
{
@@ -1021,7 +1020,7 @@ public static void LoadTerrains(MapInfo terrains)
10211020
/// <summary>Loads and sets up the map Prefabs.</summary>
10221021
static void LoadPrefabs(MapInfo terrains)
10231022
{
1024-
PrefabManager.Spawn(terrains.prefabData);
1023+
PrefabManager.SpawnPrefabs(terrains.prefabData);
10251024
}
10261025

10271026
/// <summary>Loads and sets up the map Paths.</summary>
@@ -1073,7 +1072,7 @@ static void LoadMapInfo(MapInfo terrains, string loadPath = "")
10731072
LoadAlphaMaps(terrains);
10741073
LoadPrefabs(terrains);
10751074
LoadPaths(terrains, loadPath);
1076-
SetLayer(TerrainManager.LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); // Sets the alphamaps to Ground.
1075+
SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); // Sets the alphamaps to Ground.
10771076
splatMapTask.Wait();
10781077
ProgressBarManager.Clear();
10791078
}

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ private static void OnProjectLoad()
2121
{
2222
DefaultPrefab = Resources.Load<GameObject>("Prefabs/DefaultPrefab");
2323
PrefabParent = GameObject.FindGameObjectWithTag("Prefabs").transform;
24-
EditorApplication.update -= OnProjectLoad;
24+
if (DefaultPrefab != null && PrefabParent != null)
25+
EditorApplication.update -= OnProjectLoad;
2526
}
2627

2728
/// <summary>Loads, sets up and returns the prefab at the asset path.</summary>
28-
/// <param name="path">The Prefab path in the bundle file.</param>
29+
/// <param name="path">The prefab path in the bundle file.</param>
2930
public static GameObject Load(string path)
3031
{
3132
if (AssetManager.IsInitialised)
@@ -47,19 +48,29 @@ public static GameObject Process(GameObject go, string filePath)
4748
{
4849
go.SetLayerRecursively(8);
4950
go.SetTagRecursively("Untagged");
51+
go.RemoveNameUnderscore();
5052
foreach (var item in go.GetComponentsInChildren<MeshCollider>())
5153
{
5254
item.cookingOptions = MeshColliderCookingOptions.None;
5355
item.enabled = false;
5456
item.isTrigger = false;
5557
item.convex = false;
5658
}
59+
foreach (var item in go.GetComponentsInChildren<Animator>())
60+
{
61+
item.enabled = false;
62+
item.runtimeAnimatorController = null;
63+
}
64+
foreach (var item in go.GetComponentsInChildren<Light>())
65+
item.enabled = false;
66+
5767
PrefabDataHolder prefabDataHolder = go.AddComponent<PrefabDataHolder>();
5868
prefabDataHolder.prefabData = new PrefabData() { id = AssetManager.ToID(filePath) };
5969
prefabDataHolder.Setup();
6070
return go;
6171
}
6272

73+
/// <summary>Spawns a prefab, updates the PrefabData and parents to the selected transform.</summary>
6374
public static void Spawn(GameObject go, PrefabData prefabData, Transform parent)
6475
{
6576
GameObject newObj = GameObject.Instantiate(go, parent);
@@ -76,13 +87,15 @@ public static void Spawn(Vector3 spawnPos)
7687
{
7788
if (PrefabToSpawn != null)
7889
{
79-
GameObject.Instantiate(PrefabToSpawn, spawnPos, Quaternion.Euler(0, 0, 0), PrefabParent).SetActive(true);
90+
GameObject newObj = GameObject.Instantiate(PrefabToSpawn, spawnPos, Quaternion.Euler(0, 0, 0), PrefabParent);
91+
newObj.name = PrefabToSpawn.name;
92+
newObj.SetActive(true);
8093
PrefabToSpawn = null;
8194
}
8295
}
8396

8497
/// <summary>Spawns prefabs for map load.</summary>
85-
public static void Spawn(PrefabData[] prefabs)
98+
public static void SpawnPrefabs(PrefabData[] prefabs)
8699
{
87100
if (!Coroutines.IsBusy)
88101
EditorCoroutineUtility.StartCoroutineOwnerless(Coroutines.SpawnPrefabs(prefabs));
@@ -132,18 +145,14 @@ private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
132145
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
133146
sw.Start();
134147

135-
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
136148
for (int i = 0; i < prefabs.Length; i++)
137149
{
138150
if (sw.Elapsed.TotalSeconds > 1.5f)
139151
{
140-
sw.Restart();
141-
ProgressBarManager.DisplayIncremental("Spawning Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
142152
yield return null;
153+
ProgressBarManager.Display("Spawning Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length, (float)i / prefabs.Length);
154+
sw.Restart();
143155
}
144-
else
145-
ProgressBarManager.AddIncrement();
146-
147156
Spawn(Load(prefabs[i].id), prefabs[i], PrefabParent);
148157
}
149158
ProgressBarManager.Clear();
@@ -154,18 +163,14 @@ private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs
154163
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
155164
sw.Start();
156165

157-
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
158166
for (int i = 0; i < prefabs.Length; i++)
159167
{
160168
if (sw.Elapsed.TotalSeconds > 1.5f)
161169
{
162-
ProgressBarManager.DisplayIncremental("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
163170
yield return null;
171+
ProgressBarManager.Display("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length, (float)i / prefabs.Length);
164172
sw.Restart();
165173
}
166-
else
167-
ProgressBarManager.AddIncrement();
168-
169174
Spawn(Load(prefabs[i].prefabData.id), prefabs[i].prefabData, PrefabParent);
170175
GameObject.DestroyImmediate(prefabs[i].gameObject);
171176
}
@@ -177,18 +182,14 @@ private static IEnumerator ReplaceWithDefaultCoroutine(PrefabDataHolder[] prefab
177182
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
178183
sw.Start();
179184

180-
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
181185
for (int i = 0; i < prefabs.Length; i++)
182186
{
183187
if (sw.Elapsed.TotalSeconds > 0.05f)
184188
{
185-
sw.Restart();
186-
ProgressBarManager.DisplayIncremental("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
187189
yield return null;
190+
ProgressBarManager.Display("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length, (float)i / prefabs.Length);
191+
sw.Restart();
188192
}
189-
else
190-
ProgressBarManager.AddIncrement();
191-
192193
Spawn(DefaultPrefab, prefabs[i].prefabData, PrefabParent);
193194
GameObject.DestroyImmediate(prefabs[i].gameObject);
194195
}

0 commit comments

Comments
 (0)