This commit is contained in:
bob
2025-06-25 11:52:30 +08:00
parent 879117e874
commit 29d7836b66
19 changed files with 323 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 64b3d51f8cb04af485e1a07f8a6e15a5
timeCreated: 1750822352

View File

@@ -0,0 +1,204 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace NBF
{
public class PreviewableAssetEditor : EditorWindow
{
private List<GameObject> previewablePrefabs = new List<GameObject>();
private Vector2 scrollPosition;
private int selectedIndex = -1;
private GameObject selectedPrefab;
private Editor prefabEditor;
private SerializedObject serializedObject;
[MenuItem("Tools/Previewable Asset Editor")]
public static void ShowWindow()
{
GetWindow<PreviewableAssetEditor>("Previewable Assets");
}
private void OnEnable()
{
RefreshPrefabList();
}
private void RefreshPrefabList()
{
previewablePrefabs.Clear();
// 查找项目中所有预制体
string[] guids = AssetDatabase.FindAssets("t:Prefab");
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
// 检查预制体是否有 PreviewableAsset 组件
if (prefab.GetComponent<PreviewableAsset>() != null)
{
previewablePrefabs.Add(prefab);
}
}
// 按名称排序
previewablePrefabs = previewablePrefabs.OrderBy(p => p.name).ToList();
}
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
// 左侧列表
DrawPrefabList();
// 右侧操作区域
DrawOperationArea();
EditorGUILayout.EndHorizontal();
}
private void DrawPrefabList()
{
EditorGUILayout.BeginVertical(GUILayout.Width(250));
EditorGUILayout.LabelField("Previewable Assets", EditorStyles.boldLabel);
EditorGUILayout.Space();
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, "box");
for (int i = 0; i < previewablePrefabs.Count; i++)
{
var prefab = previewablePrefabs[i];
bool isSelected = i == selectedIndex;
EditorGUILayout.BeginHorizontal();
// 使用 toggle 样式按钮来模拟选择
if (GUILayout.Toggle(isSelected, prefab.name, "Button", GUILayout.Height(20)))
{
if (!isSelected)
{
selectedIndex = i;
selectedPrefab = prefab;
CreatePrefabEditor();
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
// 刷新按钮
if (GUILayout.Button("Refresh List"))
{
RefreshPrefabList();
selectedIndex = -1;
selectedPrefab = null;
prefabEditor = null;
}
EditorGUILayout.EndVertical();
}
private void DrawOperationArea()
{
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
if (selectedPrefab == null)
{
EditorGUILayout.HelpBox("Select a prefab from the list to edit its PreviewableAsset properties.",
MessageType.Info);
}
else
{
EditorGUILayout.LabelField("Editing: " + selectedPrefab.name, EditorStyles.boldLabel);
EditorGUILayout.Space();
// 显示预制体预览
if (prefabEditor != null)
{
prefabEditor.OnPreviewGUI(GUILayoutUtility.GetRect(100, 100), EditorStyles.helpBox);
}
EditorGUILayout.Space();
// 显示 PreviewableAsset 属性
var previewableAsset = selectedPrefab.GetComponent<PreviewableAsset>();
if (previewableAsset != null)
{
if (serializedObject == null || serializedObject.targetObject != previewableAsset)
{
serializedObject = new SerializedObject(previewableAsset);
}
serializedObject.Update();
// 自动绘制所有序列化字段
SerializedProperty prop = serializedObject.GetIterator();
bool enterChildren = true;
while (prop.NextVisible(enterChildren))
{
enterChildren = false;
if (prop.name == "m_Script") continue; // 跳过脚本引用
EditorGUILayout.PropertyField(prop, true);
}
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space();
// 保存按钮
if (GUILayout.Button("Save Changes", GUILayout.Height(30)))
{
SaveChanges();
}
}
else
{
EditorGUILayout.HelpBox("Selected prefab no longer has a PreviewableAsset component.",
MessageType.Warning);
}
}
EditorGUILayout.EndVertical();
}
private void CreatePrefabEditor()
{
if (prefabEditor != null)
{
DestroyImmediate(prefabEditor);
}
prefabEditor = Editor.CreateEditor(selectedPrefab);
}
private void SaveChanges()
{
if (selectedPrefab != null)
{
// 标记预制体为脏以便保存
EditorUtility.SetDirty(selectedPrefab);
// 保存预制体
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log("Prefab " + selectedPrefab.name + " saved successfully.");
}
}
private void OnDisable()
{
if (prefabEditor != null)
{
DestroyImmediate(prefabEditor);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9fe1f9c26314412880e299b87d998083
timeCreated: 1750822614

View File

@@ -140,8 +140,8 @@ namespace NBF
// UI.Inst.OpenUI<FishingShopPanel>();
LoadData();
UI.Inst.OpenUI<CommonTopPanel>();
// UI.Inst.OpenUI<FishingPanel>();
Fishing.Inst.Go(1);
UI.Inst.OpenUI<FishingPanel>();
// Fishing.Inst.Go(1);
// UI.Inst.OpenUI<SettingPanel>();
// UI.Inst.OpenUI<HomePanel>();
}

View File

@@ -9,6 +9,7 @@
FishingBinder.BindAll();
MainBinder.BindAll();
ShopBinder.BindAll();
}
}
}

View File

@@ -4,6 +4,7 @@ using System;
using UnityEngine;
using FairyGUI;
using NBC;
using RootMotion.FinalIK;
using Object = UnityEngine.Object;
namespace NBF
@@ -43,14 +44,33 @@ namespace NBF
{
_renderImage = new ModelRenderImage(ModelHolder.asGraph);
}
//Assets/Resources/gfx/hooks/berserk_hooks/clas_20421_20446/clas_20423.prefab
//Assets/Resources/gfx/rods/syberia/bolo_10021/bolo_10021_LB400.prefab
//"Role/test"
var prefab = Resources.Load("gfx/hooks/berserk_hooks/clas_20421_20446/clas_20423");
var model = ((GameObject)Object.Instantiate(prefab));
var ccdIk = model.GetComponent<CCDIK>();
if (ccdIk != null)
{
Object.Destroy(ccdIk);
}
var lineRenderer = model.GetComponent<LineRenderer>();
if (lineRenderer != null)
{
Object.Destroy(lineRenderer);
}
var rigidbody = model.GetComponent<Rigidbody>();
if (rigidbody != null)
{
rigidbody.isKinematic = true;
}
_renderImage.modelRoot.localScale = new Vector3(200, 200, 200);
_renderImage.SetModel(model);
_renderImage.modelRoot.localScale = Vector3.one;
var previewableAsset = model.GetComponent<PreviewableAsset>();
if (previewableAsset != null)

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7cf28ec025c64ce0944299f6d30ba3c3
timeCreated: 1750821997

View File

@@ -0,0 +1,20 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class PreviewPanel
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
[AutoFind(Name = "Model")]
public ModelTexture Model;
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c5cbbfd0335a46e45aabd3e1479c8abf

View File

@@ -0,0 +1,14 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using UnityEngine;
using NBC;
namespace NBF
{
public partial class PreviewPanel : UIPanel
{
public override string UIPackName => "Tools";
public override string UIResName => "PreviewPanel";
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 536be5135584e52489e3c5b71dc719e1

View File

@@ -0,0 +1,13 @@
/**注册组件绑定关系。本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
namespace NBF
{
public class ToolsBinder
{
public static void BindAll()
{
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2d6aa632a0961684b9f1c720d2ff496d