完成预览相关内容
This commit is contained in:
@@ -1,204 +1,372 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using NBC;
|
||||
using NBF;
|
||||
|
||||
namespace NBF
|
||||
public class RuntimePreviewEditor : EditorWindow
|
||||
{
|
||||
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;
|
||||
// 运行时实例引用
|
||||
private GameObject runtimeInstance;
|
||||
private PreviewableAsset runtimePreviewableAsset;
|
||||
|
||||
[MenuItem("Tools/Previewable Asset Editor")]
|
||||
public static void ShowWindow()
|
||||
// 预制体列表
|
||||
private List<GameObject> prefabList = new List<GameObject>();
|
||||
private int selectedPrefabIndex = -1;
|
||||
private Vector2 scrollPosition;
|
||||
|
||||
// 预览控制
|
||||
private bool isPreviewing = false;
|
||||
|
||||
private PreviewPanel _previewPanel;
|
||||
|
||||
[MenuItem("Tools/Runtime Preview Editor")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<RuntimePreviewEditor>("Runtime Preview");
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
||||
ClearRuntimeInstance();
|
||||
}
|
||||
|
||||
private void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingPlayMode)
|
||||
{
|
||||
GetWindow<PreviewableAssetEditor>("Previewable Assets");
|
||||
ClearRuntimeInstance();
|
||||
isPreviewing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshPrefabList()
|
||||
{
|
||||
Debug.LogError("重新加载所有预制体==");
|
||||
prefabList.Clear();
|
||||
|
||||
string[] guids = AssetDatabase.FindAssets("t:Prefab");
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
||||
|
||||
if (prefab.GetComponent<PreviewableAsset>() != null)
|
||||
{
|
||||
prefabList.Add(prefab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
// 左侧预制体列表
|
||||
DrawPrefabList();
|
||||
|
||||
// 右侧预览和操作区域
|
||||
DrawPreviewArea();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawPrefabList()
|
||||
{
|
||||
EditorGUILayout.BeginVertical(GUILayout.Width(250));
|
||||
|
||||
EditorGUILayout.LabelField("Available Prefabs", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
|
||||
|
||||
for (int i = 0; i < prefabList.Count; i++)
|
||||
{
|
||||
bool isSelected = i == selectedPrefabIndex;
|
||||
if (GUILayout.Toggle(isSelected, prefabList[i].name, "Button"))
|
||||
{
|
||||
if (!isSelected)
|
||||
{
|
||||
selectedPrefabIndex = i;
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
LoadRuntimeInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
if (GUILayout.Button("Refresh List"))
|
||||
{
|
||||
RefreshPrefabList();
|
||||
}
|
||||
|
||||
private void RefreshPrefabList()
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void DrawPreviewArea()
|
||||
{
|
||||
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
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.HelpBox("运行模式才可以编辑.", MessageType.Info);
|
||||
EditorGUILayout.EndVertical();
|
||||
return;
|
||||
}
|
||||
|
||||
private void DrawOperationArea()
|
||||
if (selectedPrefabIndex == -1)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.HelpBox("未选中预制体", MessageType.Info);
|
||||
EditorGUILayout.EndVertical();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedPrefab == null)
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("上一个"))
|
||||
{
|
||||
if (selectedPrefabIndex > 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Select a prefab from the list to edit its PreviewableAsset properties.",
|
||||
MessageType.Info);
|
||||
selectedPrefabIndex--;
|
||||
RefreshRuntimeInstance();
|
||||
// EnsureSelectionVisible();
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
GUILayout.Space(20);
|
||||
if (GUILayout.Button("下一个"))
|
||||
{
|
||||
if (selectedPrefabIndex < prefabList.Count - 1)
|
||||
{
|
||||
EditorGUILayout.LabelField("Editing: " + selectedPrefab.name, EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
selectedPrefabIndex++;
|
||||
RefreshRuntimeInstance();
|
||||
// EnsureSelectionVisible();
|
||||
}
|
||||
}
|
||||
|
||||
// 显示预制体预览
|
||||
if (prefabEditor != null)
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
var selectedPrefab = prefabList[selectedPrefabIndex];
|
||||
EditorGUILayout.LabelField("当前预览: " + selectedPrefab.name, EditorStyles.boldLabel);
|
||||
|
||||
// 预览控制按钮
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(isPreviewing ? "停止预览" : "开始预览"))
|
||||
{
|
||||
TogglePreview();
|
||||
}
|
||||
|
||||
if (isPreviewing && GUILayout.Button("刷新实例"))
|
||||
{
|
||||
RefreshRuntimeInstance();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
// 运行时实例预览和编辑
|
||||
if (isPreviewing && runtimeInstance != null && runtimePreviewableAsset)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Transform Properties", EditorStyles.boldLabel);
|
||||
|
||||
// 记录变化开始
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// 编辑Transform
|
||||
var newPosition = EditorGUILayout.Vector3Field("位置", runtimeInstance.transform.localPosition);
|
||||
var newRotation = EditorGUILayout.Vector3Field("旋转", runtimeInstance.transform.localEulerAngles);
|
||||
var newScale = EditorGUILayout.Vector3Field("形变", runtimeInstance.transform.localScale);
|
||||
|
||||
|
||||
var canZoom = EditorGUILayout.Toggle("允许缩放", runtimePreviewableAsset.canZoom);
|
||||
if (canZoom)
|
||||
{
|
||||
runtimePreviewableAsset.zoom = EditorGUILayout.Vector3Field("放大缩小配置", runtimePreviewableAsset.zoom);
|
||||
}
|
||||
|
||||
var canPan = EditorGUILayout.Toggle("允许拖动", runtimePreviewableAsset.canPan);
|
||||
if (canPan)
|
||||
{
|
||||
runtimePreviewableAsset.pan = EditorGUILayout.RectField("拖动配置", runtimePreviewableAsset.pan);
|
||||
}
|
||||
|
||||
// 应用Transform修改
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
runtimeInstance.transform.localPosition = newPosition;
|
||||
runtimeInstance.transform.localEulerAngles = newRotation;
|
||||
runtimeInstance.transform.localScale = newScale;
|
||||
|
||||
runtimePreviewableAsset.position = newPosition;
|
||||
runtimePreviewableAsset.rotation = newRotation;
|
||||
runtimePreviewableAsset.scale = newScale;
|
||||
runtimePreviewableAsset.canZoom = canZoom;
|
||||
runtimePreviewableAsset.canPan = canPan;
|
||||
if (canZoom)
|
||||
{
|
||||
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)
|
||||
if (!Mathf.Approximately(runtimeInstance.transform.localPosition.z,
|
||||
runtimePreviewableAsset.zoom.z))
|
||||
{
|
||||
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();
|
||||
var pos = runtimeInstance.transform.localPosition;
|
||||
runtimeInstance.transform.localPosition = new Vector3(pos.x, pos.y, runtimePreviewableAsset.zoom.z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("Selected prefab no longer has a PreviewableAsset component.",
|
||||
MessageType.Warning);
|
||||
runtimeInstance.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
|
||||
private void CreatePrefabEditor()
|
||||
{
|
||||
if (prefabEditor != null)
|
||||
// 保存到预制体按钮
|
||||
if (GUILayout.Button("保存到预制体", GUILayout.Height(30)))
|
||||
{
|
||||
DestroyImmediate(prefabEditor);
|
||||
SaveChangesToPrefab();
|
||||
}
|
||||
|
||||
prefabEditor = Editor.CreateEditor(selectedPrefab);
|
||||
}
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
if (selectedPrefab != null)
|
||||
if (GUILayout.Button("生成ICON", GUILayout.Height(30)))
|
||||
{
|
||||
// 标记预制体为脏以便保存
|
||||
EditorUtility.SetDirty(selectedPrefab);
|
||||
|
||||
// 保存预制体
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log("Prefab " + selectedPrefab.name + " saved successfully.");
|
||||
// SaveChangesToPrefab();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void TogglePreview()
|
||||
{
|
||||
isPreviewing = !isPreviewing;
|
||||
|
||||
if (isPreviewing)
|
||||
{
|
||||
if (prefabEditor != null)
|
||||
_previewPanel = UI.Inst.GetUI<PreviewPanel>();
|
||||
if (_previewPanel == null)
|
||||
{
|
||||
DestroyImmediate(prefabEditor);
|
||||
isPreviewing = false;
|
||||
Debug.LogError("显示UI面包未打开");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isPreviewing)
|
||||
{
|
||||
LoadRuntimeInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearRuntimeInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadRuntimeInstance()
|
||||
{
|
||||
ClearRuntimeInstance();
|
||||
|
||||
if (selectedPrefabIndex == -1 || !Application.isPlaying) return;
|
||||
|
||||
var prefab = prefabList[selectedPrefabIndex];
|
||||
|
||||
// 调用自定义实例化方法
|
||||
// runtimeInstance = Instantiate(prefab);
|
||||
// runtimeInstance.hideFlags = HideFlags.DontSave;
|
||||
|
||||
if (_previewPanel == null) return;
|
||||
|
||||
runtimeInstance = _previewPanel.LoadModel(prefab);
|
||||
runtimeInstance.hideFlags = HideFlags.DontSave;
|
||||
|
||||
if (runtimeInstance != null)
|
||||
{
|
||||
runtimePreviewableAsset = runtimeInstance.GetComponent<PreviewableAsset>();
|
||||
Selection.activeGameObject = runtimeInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshRuntimeInstance()
|
||||
{
|
||||
if (selectedPrefabIndex == -1 || !Application.isPlaying) return;
|
||||
|
||||
ClearRuntimeInstance();
|
||||
LoadRuntimeInstance();
|
||||
}
|
||||
|
||||
private void SaveChangesToPrefab()
|
||||
{
|
||||
if (selectedPrefabIndex == -1 || runtimeInstance == null) return;
|
||||
|
||||
var prefab = prefabList[selectedPrefabIndex];
|
||||
|
||||
var previewableAsset = prefab.GetComponent<PreviewableAsset>();
|
||||
if (previewableAsset && runtimePreviewableAsset)
|
||||
{
|
||||
previewableAsset.position = runtimeInstance.transform.localPosition;
|
||||
previewableAsset.rotation = runtimeInstance.transform.localEulerAngles;
|
||||
previewableAsset.scale = runtimeInstance.transform.localScale;
|
||||
previewableAsset.canPan = runtimePreviewableAsset.canPan;
|
||||
previewableAsset.canZoom = runtimePreviewableAsset.canZoom;
|
||||
previewableAsset.zoom = runtimePreviewableAsset.zoom;
|
||||
previewableAsset.pan = runtimePreviewableAsset.pan;
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(prefab);
|
||||
AssetDatabase.Refresh();
|
||||
// // 默认实现 - 直接修改预制体
|
||||
// PrefabUtility.SaveAsPrefabAsset(runtimeInstance, AssetDatabase.GetAssetPath(prefab));
|
||||
// AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log("Changes saved to prefab: " + prefab.name);
|
||||
}
|
||||
|
||||
private void ClearRuntimeInstance()
|
||||
{
|
||||
if (runtimeInstance != null)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Destroy(runtimeInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyImmediate(runtimeInstance);
|
||||
}
|
||||
}
|
||||
|
||||
runtimeInstance = null;
|
||||
runtimePreviewableAsset = null;
|
||||
}
|
||||
|
||||
// // 确保选中项在可视区域内
|
||||
// private void EnsureSelectionVisible()
|
||||
// {
|
||||
// // 计算选中项的大概位置
|
||||
// float itemHeight = 24; // 每个列表项的大约高度
|
||||
// float visibleHeight = position.height - 100; // 可视区域的大约高度
|
||||
//
|
||||
// // 计算选中项应该在的滚动位置范围
|
||||
// float targetMin = selectedPrefabIndex * itemHeight;
|
||||
// float targetMax = targetMin + itemHeight;
|
||||
//
|
||||
// // 调整滚动位置
|
||||
// if (scrollPosition.y > targetMin)
|
||||
// {
|
||||
// scrollPosition.y = targetMin;
|
||||
// }
|
||||
// else if (scrollPosition.y + visibleHeight < targetMax)
|
||||
// {
|
||||
// scrollPosition.y = targetMax - visibleHeight;
|
||||
// }
|
||||
//
|
||||
// // 重绘界面
|
||||
// Repaint();
|
||||
// }
|
||||
}
|
||||
@@ -3,37 +3,17 @@ using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型拉近拉远配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ModelZoomConfig
|
||||
{
|
||||
[Tooltip("是否可以放大缩小")] public bool canZoom;
|
||||
[Tooltip("默认值")] public float zoom;
|
||||
[Tooltip("最小值")] public float zoomMin;
|
||||
[Tooltip("最大值")] public float zoomMax;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模型平移配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ModelPanConfig
|
||||
{
|
||||
[Tooltip("是否可以平移")] public bool canPan;
|
||||
[Tooltip("水平可移动值")] public float x = 0;
|
||||
[Tooltip("垂直可移动值")] public float y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可以3D预览的资产
|
||||
/// </summary>
|
||||
public class PreviewableAsset : MonoBehaviour
|
||||
{
|
||||
[Tooltip("放大缩小配置")] public ModelZoomConfig zoom;
|
||||
[Tooltip("平移配置")] public ModelPanConfig pan;
|
||||
[Tooltip("默认位置")] public Vector3 position;
|
||||
[Tooltip("默认旋转")] public Vector3 rotation;
|
||||
[Tooltip("默认形变")] public Vector3 scale;
|
||||
[Tooltip("是否可以放大缩小")] public bool canZoom;
|
||||
[Tooltip("放大缩小配置")] public Vector3 zoom;
|
||||
[Tooltip("是否可以平移")] public bool canPan;
|
||||
[Tooltip("平移配置")] public Rect pan;
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,8 @@ namespace NBF
|
||||
// UI.Inst.OpenUI<FishingShopPanel>();
|
||||
LoadData();
|
||||
UI.Inst.OpenUI<CommonTopPanel>();
|
||||
UI.Inst.OpenUI<FishingPanel>();
|
||||
// UI.Inst.OpenUI<FishingPanel>();
|
||||
UI.Inst.OpenUI<PreviewPanel>();
|
||||
// Fishing.Inst.Go(1);
|
||||
// UI.Inst.OpenUI<SettingPanel>();
|
||||
// UI.Inst.OpenUI<HomePanel>();
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace NBF
|
||||
private SwipeGesture _swipeGesture;
|
||||
private bool _focus;
|
||||
|
||||
private Vector3 _zoomLimit;
|
||||
private Rect _panLimit;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
@@ -39,17 +41,21 @@ namespace NBF
|
||||
/// </summary>
|
||||
/// <param name="configId"></param>
|
||||
public void LoadAsset(int configId)
|
||||
{
|
||||
//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");
|
||||
SetModel((GameObject)Object.Instantiate(prefab));
|
||||
}
|
||||
|
||||
public void SetModel(GameObject model)
|
||||
{
|
||||
if (_renderImage == null)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
@@ -69,19 +75,25 @@ namespace NBF
|
||||
}
|
||||
|
||||
|
||||
_renderImage.modelRoot.localScale = new Vector3(200, 200, 200);
|
||||
_renderImage.SetModel(model);
|
||||
_renderImage.modelRoot.localScale = Vector3.one;
|
||||
|
||||
var previewableAsset = model.GetComponent<PreviewableAsset>();
|
||||
if (previewableAsset != null)
|
||||
{
|
||||
_renderImage.modelRoot.localPosition = new Vector3(0, 0, previewableAsset.zoom.zoom);
|
||||
_renderImage.modelRoot.localRotation = Quaternion.Euler(previewableAsset.rotation);
|
||||
_zoomLimit = previewableAsset.zoom;
|
||||
_panLimit = previewableAsset.pan;
|
||||
model.transform.localPosition = previewableAsset.position;
|
||||
model.transform.localScale = previewableAsset.scale;
|
||||
model.transform.localRotation = Quaternion.Euler(previewableAsset.rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
_renderImage.modelRoot.localPosition = new Vector3(0, 0, 3);
|
||||
_renderImage.modelRoot.localRotation = Quaternion.Euler(Vector3.zero);
|
||||
_zoomLimit = Vector3.zero;
|
||||
_panLimit = Rect.zero;
|
||||
model.transform.localPosition = previewableAsset.position;
|
||||
model.transform.localScale = Vector3.one;
|
||||
model.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +178,17 @@ namespace NBF
|
||||
private void SetZoom(float delta)
|
||||
{
|
||||
var pos = _renderImage.modelRoot.localPosition;
|
||||
_renderImage.modelRoot.localPosition = new Vector3(pos.x, pos.y, pos.z + delta);
|
||||
var targetZ = pos.z + delta;
|
||||
if (targetZ < _zoomLimit.x)
|
||||
{
|
||||
targetZ = _zoomLimit.x;
|
||||
}
|
||||
else if (targetZ > _zoomLimit.y)
|
||||
{
|
||||
targetZ = _zoomLimit.y;
|
||||
}
|
||||
|
||||
_renderImage.modelRoot.localPosition = new Vector3(pos.x, pos.y, targetZ);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -9,6 +9,15 @@ namespace NBF
|
||||
{
|
||||
public override string UIPackName => "Tools";
|
||||
public override string UIResName => "PreviewPanel";
|
||||
|
||||
|
||||
public GameObject Instance { get; private set; }
|
||||
|
||||
public GameObject LoadModel(GameObject prefab)
|
||||
{
|
||||
Instance = Object.Instantiate(prefab);
|
||||
Debug.LogError($"预制体:{prefab.name} 实例={Instance}");
|
||||
Model.SetModel(Instance);
|
||||
return Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user