Skip to content

Commit a6f4fcb

Browse files
committed
Added Mod Tool Physics Layers and Object Tags Synchronization
1 parent c126869 commit a6f4fcb

File tree

8 files changed

+96
-14
lines changed

8 files changed

+96
-14
lines changed
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.

Mod Demo for Game/ProjectSettings/TagManager.asset

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
%YAML 1.1
22
%TAG !u! tag:unity3d.com,2011:
3-
--- !u!78 &1
4-
TagManager:
3+
--- !u!78 &1\nTagManager:
54
serializedVersion: 2
6-
tags: []
5+
tags:
6+
- Vehicle
77
layers:
88
- Default
99
- TransparentFX
1010
- Ignore Raycast
11-
- Test
11+
- _UNUSED
1212
- Water
1313
- UI
14-
-
14+
- SelfPlayer
1515
-
1616
-
1717
-
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEngine.Assertions;
4+
5+
namespace ModSDK.editor
6+
{
7+
/// <summary>
8+
/// Mod Settings is a class that handle any type of settings that unity doesn't normally give access to.
9+
/// </summary>
10+
public static class ModSettings
11+
{
12+
public static void SetupProjectSettings()
13+
{
14+
// Thank you for pointing this out! https://bladecast.pro/unity-tutorial/create-tags-by-script
15+
var asset = AssetDatabase.LoadMainAssetAtPath("ProjectSettings/TagManager.asset");
16+
Assert.IsNotNull(asset, "TagManager is not initialized, possible Unity3d Corruption!");
17+
18+
if (asset == null)
19+
return;
20+
21+
var sObj = new SerializedObject(asset);
22+
var tagsProperty = sObj.FindProperty("tags");
23+
var layersProperty = sObj.FindProperty("layers");
24+
25+
// Handle Tags
26+
tagsProperty.ClearArray();
27+
foreach (var tag in Enum.GetNames(typeof(ModObjectTags)))
28+
{
29+
tagsProperty.InsertArrayElementAtIndex(0);
30+
tagsProperty.GetArrayElementAtIndex(0).stringValue = tag;
31+
}
32+
33+
// Handle Layers
34+
string[] layers = new string[32];
35+
string[] unityLayers = new string[]
36+
{
37+
"Default",
38+
"TransparentFX",
39+
"Ignore Raycast",
40+
"_UNUSED",
41+
"Water",
42+
"UI"
43+
};
44+
string[] userLayers = Enum.GetNames(typeof(ModPhysicLayers));
45+
46+
layersProperty.ClearArray();
47+
for (int i = 0; i < layers.Length; i++)
48+
{
49+
if (i < unityLayers.Length)
50+
layers[i] = unityLayers[i];
51+
else if (i - unityLayers.Length < userLayers.Length)
52+
layers[i] = userLayers[i - unityLayers.Length];
53+
54+
layersProperty.InsertArrayElementAtIndex(i);
55+
layersProperty.GetArrayElementAtIndex(i).stringValue = layers[i];
56+
}
57+
58+
sObj.ApplyModifiedPropertiesWithoutUndo();
59+
sObj.Update();
60+
}
61+
}
62+
}

SDK/ModSDK-Editor/Scripts/ModTool.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ private static Version SDKVersion
3333
return _sdkVersion;
3434
}
3535
}
36-
public readonly static List<string> global_asset_labels = new List<string> { "Scene" };
3736

3837
private const string modToolProfile = "modtools";
3938
private const string build_script = "Assets/AddressableAssetsData/DataBuilders/BuildScriptPackedMode.asset";
@@ -55,6 +54,7 @@ static void ShowWindow()
5554
var window = GetWindow<ModTool>();
5655

5756
// Initialize Mod Editor Settings.
57+
ModSettings.SetupProjectSettings();
5858
GetSettingsObject(settings_asset);
5959
GetModEditorSettings(modsdksettings_asset);
6060

@@ -254,21 +254,14 @@ static bool GetModEditorSettings(string _settingsAsset)
254254
// Apply globals everytime we load it successfully.
255255
if (m_data != null)
256256
{
257-
global_asset_labels.AddRange(m_data.m_asset_labels);
258-
259257
var labels = m_settings.GetLabels();
260-
foreach (var label in global_asset_labels)
258+
foreach (var label in Enum.GetNames(typeof(ModAssetLabels)))
261259
{
262260
// Add user-labels that aren't in the global-list.
263261
if (!labels.Contains(label))
264262
{
265263
m_settings.AddLabel(label);
266264
}
267-
// Remove labels that aren't in the users-list.
268-
if (!label.Equals("Scene") && !m_data.m_asset_labels.Contains(label))
269-
{
270-
m_settings.RemoveLabel(label);
271-
}
272265
}
273266
}
274267

SDK/ModSDK/ModUserSettings.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
namespace ModSDK
4+
{
5+
/*
6+
* In the Mod User Settings file, you can freely modify the enums to ensure that both projects will share the same physics layers, asset labels and game object tags.
7+
*
8+
* Note: that you can no longer use the Tags & Layers Management tools provided via Unity,
9+
* in results of using Unity's toolset may cause corruption, which is easily fixed via opening the mod tool sdk ui.
10+
*/
11+
12+
[Flags]
13+
public enum ModPhysicLayers
14+
{
15+
SelfPlayer
16+
}
17+
[Flags]
18+
public enum ModAssetLabels
19+
{
20+
Scene
21+
}
22+
[Flags]
23+
public enum ModObjectTags
24+
{
25+
Vehicle
26+
}
27+
}

0 commit comments

Comments
 (0)