装备系统完结,修复并加入很多
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Bansonic;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
@@ -60,6 +61,20 @@ public class equipmentRandomTestButton : MonoBehaviour
|
||||
{
|
||||
targetEquipBag.Rebuild();
|
||||
}
|
||||
|
||||
equipBag[] bags = FindObjectsOfType<equipBag>(true);
|
||||
if (bags == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < bags.Length; i++)
|
||||
{
|
||||
if (bags[i] != null && bags[i] != targetEquipBag)
|
||||
{
|
||||
bags[i].Rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Generate Equipment SO")]
|
||||
@@ -91,7 +106,7 @@ public class equipmentRandomTestButton : MonoBehaviour
|
||||
#endif
|
||||
|
||||
equipmentSO generated = Instantiate(sourceEquipment);
|
||||
generated.name = BuildGeneratedName(sourceEquipment);
|
||||
generated.name = equipmentGenerator.GenerateUniqueEquipmentName(sourceEquipment != null ? sourceEquipment.skillType : 0);
|
||||
generated.hideFlags = HideFlags.None;
|
||||
generated.level = 0;
|
||||
generated.sa_skillID = 0;
|
||||
@@ -617,7 +632,7 @@ public class equipmentRandomTestButton : MonoBehaviour
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (saveGeneratedAssetInEditor)
|
||||
if (!Application.isPlaying && saveGeneratedAssetInEditor)
|
||||
{
|
||||
EnsureEditorOutputFolderExists();
|
||||
string assetPath = AssetDatabase.GenerateUniqueAssetPath($"{EditorOutputFolder}/{generated.name}.asset");
|
||||
@@ -629,52 +644,7 @@ public class equipmentRandomTestButton : MonoBehaviour
|
||||
}
|
||||
#endif
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
private static string BuildGeneratedName(equipmentSO source)
|
||||
{
|
||||
int typeIndex = source != null ? (int)source.skillType : 0;
|
||||
int nextId = GetNextGeneratedId();
|
||||
return $"type{typeIndex}_{DateTime.Now:yyyyMMdd}_{nextId:00000000}";
|
||||
}
|
||||
|
||||
private static int GetNextGeneratedId()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string absoluteFolder = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "Resources", "so", "uEquip");
|
||||
if (!Directory.Exists(absoluteFolder))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int maxId = 0;
|
||||
string[] files = Directory.GetFiles(absoluteFolder, "*.asset", SearchOption.TopDirectoryOnly);
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(files[i]);
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int lastUnderscore = fileName.LastIndexOf('_');
|
||||
if (lastUnderscore < 0 || lastUnderscore >= fileName.Length - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string idPart = fileName.Substring(lastUnderscore + 1);
|
||||
if (int.TryParse(idPart, out int parsedId) && parsedId > maxId)
|
||||
{
|
||||
maxId = parsedId;
|
||||
}
|
||||
}
|
||||
|
||||
return maxId + 1;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
return equipmentGenerator.RegisterGeneratedEquipment(generated);
|
||||
}
|
||||
|
||||
private static void WriteGeneratedEffectsBack(
|
||||
|
||||
Reference in New Issue
Block a user