added inventory and stamina system
This commit is contained in:
92
Assets/Scripts/Editor/WeaponManagerEditor.cs
Normal file
92
Assets/Scripts/Editor/WeaponManagerEditor.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(WeaponManager))]
|
||||
public class WeaponManagerEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
WeaponManager wm = (WeaponManager)target;
|
||||
|
||||
if (!Application.isPlaying) return;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("── Live Positioning ──", EditorStyles.boldLabel);
|
||||
|
||||
// Show what's active
|
||||
string activeName = wm.ActiveWeaponName;
|
||||
if (string.IsNullOrEmpty(activeName))
|
||||
{
|
||||
EditorGUILayout.HelpBox("No weapon currently equipped.", MessageType.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox($"Active: {activeName}", MessageType.None);
|
||||
|
||||
// Select the live GO so you can drag gizmos in Scene view
|
||||
if (GUILayout.Button("🎯 Select Active Weapon in Scene"))
|
||||
{
|
||||
var slot = wm.slots.Find(s => s.itemName == activeName);
|
||||
if (slot != null)
|
||||
{
|
||||
Selection.activeGameObject = slot.instance;
|
||||
SceneView.lastActiveSceneView?.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
// Sync the current transform back into the WeaponViewmodel (or fallback global offset)
|
||||
if (GUILayout.Button("⬆ Sync Transform → Offset Fields"))
|
||||
{
|
||||
var slot = wm.slots.Find(s => s.itemName == activeName);
|
||||
if (slot != null)
|
||||
{
|
||||
var vm = slot.instance.GetComponent<WeaponViewmodel>();
|
||||
if (vm != null)
|
||||
{
|
||||
Undo.RecordObject(vm, "Sync Weapon Viewmodel");
|
||||
vm.SyncFromTransform();
|
||||
EditorUtility.SetDirty(vm);
|
||||
|
||||
// Also save back to the source prefab asset
|
||||
var prefabAsset = PrefabUtility.GetCorrespondingObjectFromSource(slot.instance);
|
||||
if (prefabAsset != null)
|
||||
{
|
||||
var prefabVm = prefabAsset.GetComponent<WeaponViewmodel>();
|
||||
if (prefabVm != null)
|
||||
{
|
||||
Undo.RecordObject(prefabVm, "Sync Weapon Viewmodel Prefab");
|
||||
prefabVm.positionOffset = vm.positionOffset;
|
||||
prefabVm.rotationOffset = vm.rotationOffset;
|
||||
prefabVm.scale = vm.scale;
|
||||
EditorUtility.SetDirty(prefabVm);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
Debug.Log($"[WeaponManager] Synced to WeaponViewmodel: pos={vm.positionOffset} rot={vm.rotationOffset} scale={vm.scale}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: no viewmodel, write to global offsets
|
||||
Undo.RecordObject(wm, "Sync Weapon Offset");
|
||||
wm.weaponPositionOffset = slot.instance.transform.localPosition;
|
||||
wm.weaponRotationOffset = slot.instance.transform.localRotation.eulerAngles;
|
||||
wm.weaponScale = slot.instance.transform.localScale;
|
||||
EditorUtility.SetDirty(wm);
|
||||
Debug.Log($"[WeaponManager] Synced to global offset: pos={wm.weaponPositionOffset}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"1. Hit Play & equip the gun\n" +
|
||||
"2. Click 'Select Active Weapon'\n" +
|
||||
"3. Use Move/Rotate gizmos in Scene view\n" +
|
||||
"4. Click 'Sync Transform → Offset Fields'\n" +
|
||||
"5. Stop Play — values are saved",
|
||||
MessageType.Info);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user