Skip to content

Commit f6cdbf1

Browse files
committed
修复使用AssetDatabase导致不能打包的问题
1 parent d24645f commit f6cdbf1

File tree

14 files changed

+136
-54
lines changed

14 files changed

+136
-54
lines changed

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/BuffManager/BuffManager.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,20 @@ namespace NoSLoofah.BuffSystem.Manager
1212
public class BuffManager : MonoSingleton<BuffManager>, IBuffManager
1313
{
1414
//public static readonly string SO_PATH = "Assets/NoSLoofah_BuffSystem/BuffSystem/Data/BuffData"; //保存Data的路径
15-
public static string SO_PATH
16-
{
17-
get
18-
{
19-
var l = AssetDatabase.FindAssets("BuffMgr t:Prefab");
20-
if (l.Length <= 0) throw new Exception("BuffMgr.prefab丢失,请重新导入BuffSystem");
21-
else if (l.Length > 1) Debug.LogError("请保证项目中只有一个BuffMgr.prefab");
22-
var path = AssetDatabase.GUIDToAssetPath(l[0]).Replace("Base/BuffMgr.prefab", "Data/BuffData");
23-
return path;
24-
}
25-
}//保存Data的路径
26-
private BuffCollection collection;
15+
[HideInInspector][SerializeField] private BuffCollection collection;
2716
private IBuffTagManager tagManager;
2817
public bool IsWorking => collection != null;
2918

3019
public IBuffTagManager TagManager => tagManager;
20+
public void SetData(BuffCollection buffCollection)
21+
{
22+
this.collection = buffCollection;
23+
}
3124

3225
protected override void Awake()
3326
{
3427
base.Awake();
35-
collection = null;
36-
string[] assetPaths = AssetDatabase.FindAssets("t:BuffCollection", new string[] { SO_PATH });
37-
if (assetPaths.Length > 0)
38-
{
39-
string assetPath = AssetDatabase.GUIDToAssetPath(assetPaths[0]);
40-
collection = AssetDatabase.LoadAssetAtPath<BuffCollection>(assetPath);
41-
}
28+
if (collection == null) Debug.LogError("BuffCollection数据丢失");
4229
}
4330
public IBuff GetBuff(int id)
4431
{

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/BuffMgr.prefab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MonoBehaviour:
4545
m_Script: {fileID: 11500000, guid: 7299e19220fb2064f994b058992a2402, type: 3}
4646
m_Name:
4747
m_EditorClassIdentifier:
48-
tagData: {fileID: 11400000, guid: a580eea19d256614aa2a8d1b25766c07, type: 2}
48+
tagData: {fileID: 11400000, guid: 6e45df6cefda0214f9d2df1567e70d95, type: 2}
4949
--- !u!114 &-2016688278804542462
5050
MonoBehaviour:
5151
m_ObjectHideFlags: 0
@@ -58,3 +58,4 @@ MonoBehaviour:
5858
m_Script: {fileID: 11500000, guid: d010badb5bfaafb4aa9cd2292ae11e85, type: 3}
5959
m_Name:
6060
m_EditorClassIdentifier:
61+
collection: {fileID: 11400000, guid: 95507c772b3d96a4fa910ae2ecd62086, type: 2}

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/Editor/BuffEditor.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.IO;
77
using System.Reflection;
8+
using NoSLoofah.BuffSystem.Manager;
89

910
namespace NoSLoofah.BuffSystem.Editor
1011
{
@@ -18,6 +19,18 @@ public static void OpenWindow()
1819
wd.Initialize();
1920
}
2021

22+
public static string SO_PATH
23+
{
24+
get
25+
{
26+
var l = AssetDatabase.FindAssets("BuffMgr t:Prefab");
27+
if (l.Length <= 0) throw new Exception("BuffMgr.prefab丢失,请重新导入BuffSystem");
28+
else if (l.Length > 1) Debug.LogError("请保证项目中只有一个BuffMgr.prefab");
29+
var path = AssetDatabase.GUIDToAssetPath(l[0]).Replace("Base/BuffMgr.prefab", "Data/BuffData");
30+
return path;
31+
}
32+
}//保存Data的路径
33+
2134

2235
//左侧列表
2336
private const float WIDTH_DIVISON = 0.3f; //左栏比例
@@ -29,10 +42,13 @@ public static void OpenWindow()
2942
private SerializedObject currentBuffSO;
3043
private SerializedProperty currentBuffSP;
3144
//文件保存
45+
private static readonly string assetBundleName = "Buff";
3246
public static readonly string defaultSOName = "BuffCollection.asset";
3347
public static readonly string defaultTagSOName = "BuffTagData.asset";
3448
private int maxLengthBuffer;
35-
public static string SO_PATH => Manager.BuffManager.SO_PATH;
49+
private GameObject mgr = null;
50+
private BitBuffTagData tagData = null;
51+
3652
public static string BUFF_PATH => SO_PATH + "/Buffs";
3753

3854
//语言
@@ -67,13 +83,26 @@ private void OnEnable()
6783
Initialize();
6884
}
6985
#region 更新方法
86+
private void UpdateBuffMgr()
87+
{
88+
var l = AssetDatabase.FindAssets("BuffMgr t:Prefab");
89+
if (l.Length <= 0) throw new Exception("BuffMgr.prefab丢失,请重新导入BuffSystem");
90+
else if (l.Length > 1) Debug.LogError("请保证项目中只有一个BuffMgr.prefab");
91+
string assetPath = AssetDatabase.GUIDToAssetPath(l[0]);
92+
mgr = PrefabUtility.LoadPrefabContents(assetPath);
93+
mgr.GetComponent<BitBuffTagManager>().SetData(tagData);
94+
mgr.GetComponent<BuffManager>().SetData(SO);
95+
PrefabUtility.SaveAsPrefabAsset(mgr, assetPath);
96+
PrefabUtility.UnloadPrefabContents(mgr);
97+
}
7098
private void Initialize()
7199
{
72100
assembly = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name.Equals(ASSEMBLY_NAME));
73101
UpdateSubClass();
74102
UpdateLeftList();
75103
GenerateReadme();
76104
CreateBuffTagAsset();
105+
UpdateBuffMgr();
77106
}
78107
private void GenerateReadme()
79108
{
@@ -112,7 +141,9 @@ private void UpdateLeftList()
112141
Debug.Log("没有数据");//待处理,或许可以直接创建一个新的
113142
if (!Directory.Exists(SO_PATH)) Directory.CreateDirectory(SO_PATH);
114143
SO = CreateInstance<BuffCollection>();
115-
AssetDatabase.CreateAsset(SO, Path.Combine(SO_PATH, defaultSOName));
144+
var path = Path.Combine(SO_PATH, defaultSOName);
145+
AssetDatabase.CreateAsset(SO, path);
146+
UpdateBuffMgr();
116147
}
117148
else
118149
{
@@ -149,14 +180,21 @@ private void CreateBuffAsset(int index)
149180

150181
Buff b = SO.buffList[index];
151182
AssetDatabase.CreateAsset(b, dir);
183+
152184
}
153185
private void CreateBuffTagAsset()
154186
{
155187
string dir = Path.Combine(SO_PATH, defaultTagSOName);
156-
if (File.Exists(dir)) return;
188+
if (File.Exists(dir))
189+
{
190+
tagData = AssetDatabase.LoadAssetAtPath<BitBuffTagData>(dir);
191+
return;
192+
}
157193
BitBuffTagData b = CreateInstance<BitBuffTagData>();
158194
b.Initialize();
159195
AssetDatabase.CreateAsset(b, dir);
196+
tagData = b;
197+
UpdateBuffMgr();
160198
}
161199
/// <summary>
162200
/// 绘制分界线

Assets/NoSLoofah_BuffSystem/BuffSystem/Base/Tag/BitType/BitBuffTagManager.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ namespace NoSLoofah.BuffSystem
1111
/// </summary>
1212
public class BitBuffTagManager : BuffTagManager
1313
{
14-
private static string dataPath => Manager.BuffManager.SO_PATH + "/BuffTagData.asset";
14+
//TODO:
15+
//Manager.BuffManager.SO_PATH +
16+
//private static string dataPath => "/BuffTagData.asset";
1517

16-
private BitBuffTagData tagData;
18+
[HideInInspector][SerializeField] private BitBuffTagData tagData;
19+
public void SetData(BitBuffTagData data)
20+
{
21+
tagData = data;
22+
}
1723
private void Awake()
1824
{
19-
tagData = AssetDatabase.LoadAssetAtPath<BitBuffTagData>(dataPath);
20-
if (tagData == null) Debug.LogError(dataPath + ":Tag数据丢失");
25+
if (tagData == null) Debug.LogError("Tag数据丢失");
2126
}
2227
public override bool IsTagRemoveOther(BuffTag tag, BuffTag other)
2328
{
@@ -28,7 +33,7 @@ public override bool IsTagRemoveOther(BuffTag tag, BuffTag other)
2833
}
2934

3035
public override bool IsTagCanAddWhenHaveOther(BuffTag tag, BuffTag other)
31-
{
36+
{
3237
if (tag == 0) return false;
3338
if (tag < 0) throw new System.Exception("使用了负标签");
3439
int index = BitBuffTagData.GetIndex(tag);

Assets/NoSLoofah_BuffSystem/BuffSystem/Data/BuffData/BuffCollection.asset.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/NoSLoofah_BuffSystem/BuffSystem/Data/BuffData/BuffTagData.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ MonoBehaviour:
1313
m_Name: BuffTagData
1414
m_EditorClassIdentifier:
1515
removedTags: 0000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
16-
blockTags: 0000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
16+
blockTags: 0000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Assets/NoSLoofah_BuffSystem/BuffSystem/Data/BuffData/BuffTagData.asset.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/NoSLoofah_BuffSystem/BuffSystem/Data/BuffData/Buffs/Buff000.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ MonoBehaviour:
1919
buffTag: 1
2020
id: 0
2121
isPermanent: 0
22-
duration: 15
23-
bleedDamage: 2
22+
duration: 10
23+
bleedDamage: 5
2424
bleedTimeInterval: 1

Assets/NoSLoofah_BuffSystem/doc.meta renamed to Assets/NoSLoofah_BuffSystem/BuffSystem/LICENSE.txt.meta

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/NoSLoofah_BuffSystem/Example/Font/YanZhenQingDuoBaoTaBei-2 SDF.asset

Lines changed: 39 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"MonoBehaviour": {
3+
"Version": 4,
4+
"EnableBurstCompilation": true,
5+
"EnableOptimisations": true,
6+
"EnableSafetyChecks": false,
7+
"EnableDebugInAllBuilds": false,
8+
"UsePlatformSDKLinker": false,
9+
"CpuMinTargetX32": 0,
10+
"CpuMaxTargetX32": 0,
11+
"CpuMinTargetX64": 0,
12+
"CpuMaxTargetX64": 0,
13+
"CpuTargetsX32": 6,
14+
"CpuTargetsX64": 72,
15+
"OptimizeFor": 0
16+
}
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"MonoBehaviour": {
3+
"Version": 4,
4+
"DisabledWarnings": ""
5+
}
6+
}

ProjectSettings/EditorBuildSettings.asset

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ EditorBuildSettings:
55
m_ObjectHideFlags: 0
66
serializedVersion: 2
77
m_Scenes:
8+
- enabled: 0
9+
path:
10+
guid: 00000000000000000000000000000000
811
- enabled: 1
9-
path: Assets/Scenes/Playground.unity
10-
guid: e9017d5f96b9f09489b4b37e1d6eb914
12+
path: Assets/NoSLoofah_BuffSystem/Example/ExampleScene.unity
13+
guid: 37e3cf2b0ba1ca44dabd89d598137a3a
1114
m_configObjects:
1215
com.unity.input.settings: {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7,
1316
type: 2}

ProjectSettings/UnityConnectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
UnityConnectSettings:
55
m_ObjectHideFlags: 0
66
serializedVersion: 1
7-
m_Enabled: 0
7+
m_Enabled: 1
88
m_TestMode: 0
99
m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
1010
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events

0 commit comments

Comments
 (0)