This commit is contained in:
taosuqi 2025-10-14 17:14:59 +08:00
parent 08df50f0cf
commit 451e9b0435
3 changed files with 2266 additions and 122 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.1825844, g: 0.22546011, b: 0.29071727, a: 1}
m_IndirectSpecularColor: {r: 0.18258438, g: 0.22546011, b: 0.29071727, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -140,7 +140,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!81 &562157362
AudioListener:
m_ObjectHideFlags: 0
@ -299,8 +299,65 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 20.712, y: 91.21, z: 35.743}
--- !u!1001 &876751123
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2399593117452945565, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.y
value: 1.01
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.z
value: 7.79
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.y
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 90
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
--- !u!1 &1677042732
GameObject:
m_ObjectHideFlags: 0
@ -320,7 +377,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!81 &1677042733
AudioListener:
m_ObjectHideFlags: 0
@ -385,7 +442,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!114 &1677042736
MonoBehaviour:
@ -527,7 +584,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2135612827
PrefabInstance:

View File

@ -1,111 +1,111 @@
using UnityEngine;
public class CraneController : MonoBehaviour
{
public static CraneController Instance;
[Header("物体")]
public Transform bridge; // 横杆
public Transform hook; // 滑轮
public SkinnedMeshRenderer hookRenderer;//吊钩
[Header("移动速度")]
[Range(1, 10)]
public float bridgeSpeed = 5f; // 横杆移动速度
[Range(1, 10)]
public float hookSpeed = 5f; // 滑轮移动速度
public float blendShapeSpeed = 30f;
[Header("移动范围限制 (Z轴)")]
[Range(-1, -20)]
public float bridgeMinZ = -5f;
[Range(1, 20)]
public float bridgeMaxZ = 5f;
[Range(-1, 5)]
public float hookMinZ = -3f;
[Range(1, 5)]
public float hookMaxZ = 3f;
[Header("BlendShape设置")]
public int hookBlendShapeIndex = 0; // BlendShape索引通常是0
public float minBlendShapeValue = 0f; // 吊钩收起
public float maxBlendShapeValue = 100f; // 吊钩放下
private float currentBlendValue = 0f;
private float baseColliderZ;
private float Max = 0f;
private float Min = 0f;
public BoxCollider hookCollider; //钩子的碰撞
private void Awake()
{
Instance = this;
}
public void Start()
{
Max = -(2.49513f - 0.5113189f) / 100;
Min = (6.295807f - 0.3099952f) / 100;
}
// Update is called once per frame
void Update()
{
HandleBridgeMovement();
HandleHookMovement();
HandleHookLift();
hookSize();
}
void HandleBridgeMovement()
{
// I/K 控制横杆前后
float input = 0;
if (Input.GetKey(KeyCode.I))
input = 1;
else if (Input.GetKey(KeyCode.K))
input = -1;
Vector3 newPos = bridge.position + Vector3.forward * input * bridgeSpeed * Time.deltaTime;
newPos.z = Mathf.Clamp(newPos.z, bridgeMinZ, bridgeMaxZ);
bridge.position = newPos;
}
void HandleHookMovement()
{
// J/L 控制滑轮前后
float input = 0;
if (Input.GetKey(KeyCode.J))
input = 1;
else if (Input.GetKey(KeyCode.L))
input = -1;
Vector3 newPos = hook.position + Vector3.left * input * hookSpeed * Time.deltaTime;
newPos.x = Mathf.Clamp(newPos.x, hookMinZ, hookMaxZ);
hook.position = newPos;
}
void HandleHookLift()
{
if (hookRenderer == null)
return;
float input = 0;
if (Input.GetKey(KeyCode.U))
input = 1; // 上升
else if (Input.GetKey(KeyCode.O))
input = -1; // 下降
currentBlendValue += input * blendShapeSpeed * Time.deltaTime;
currentBlendValue = Mathf.Clamp(currentBlendValue, minBlendShapeValue, maxBlendShapeValue);
hookRenderer.SetBlendShapeWeight(hookBlendShapeIndex, currentBlendValue);
}
public void hookSize()
{
if (hookCollider != null)
{
hookCollider.center = new Vector3(-0.1262663f, -0.01883008f, -0.5113189f + currentBlendValue * Max);
hookCollider.size = new Vector3(0.1096101f, 0.2627291f, 0.3099952f + currentBlendValue *Min);
}
}
}
using UnityEngine;
public class CraneController : MonoBehaviour
{
public static CraneController Instance;
[Header("物体")]
public Transform bridge; // 横杆
public Transform hook; // 滑轮
public SkinnedMeshRenderer hookRenderer;//吊钩
[Header("移动速度")]
[Range(1, 10)]
public float bridgeSpeed = 5f; // 横杆移动速度
[Range(1, 10)]
public float hookSpeed = 5f; // 滑轮移动速度
public float blendShapeSpeed = 30f;
[Header("移动范围限制 (Z轴)")]
[Range(-1, -20)]
public float bridgeMinZ = -5f;
[Range(1, 20)]
public float bridgeMaxZ = 5f;
[Range(-1, 5)]
public float hookMinZ = -3f;
[Range(1, 5)]
public float hookMaxZ = 3f;
[Header("BlendShape设置")]
public int hookBlendShapeIndex = 0; // BlendShape索引通常是0
public float minBlendShapeValue = 0f; // 吊钩收起
public float maxBlendShapeValue = 100f; // 吊钩放下
private float currentBlendValue = 0f;
private float baseColliderZ;
private float Max = 0f;
private float Min = 0f;
public BoxCollider hookCollider; //钩子的碰撞
private void Awake()
{
Instance = this;
}
public void Start()
{
Max = -(2.49513f - 0.5113189f) / 100;
Min = (6.295807f - 0.3099952f) / 100;
}
// Update is called once per frame
void Update()
{
HandleBridgeMovement();
HandleHookMovement();
HandleHookLift();
hookSize();
}
void HandleBridgeMovement()
{
// I/K 控制横杆前后
float input = 0;
if (Input.GetKey(KeyCode.I))
input = 1;
else if (Input.GetKey(KeyCode.K))
input = -1;
Vector3 newPos = bridge.position + Vector3.forward * input * bridgeSpeed * Time.deltaTime;
newPos.z = Mathf.Clamp(newPos.z, bridgeMinZ, bridgeMaxZ);
bridge.position = newPos;
}
void HandleHookMovement()
{
// J/L 控制滑轮前后
float input = 0;
if (Input.GetKey(KeyCode.J))
input = 1;
else if (Input.GetKey(KeyCode.L))
input = -1;
Vector3 newPos = hook.position + Vector3.left * input * hookSpeed * Time.deltaTime;
newPos.x = Mathf.Clamp(newPos.x, hookMinZ, hookMaxZ);
hook.position = newPos;
}
void HandleHookLift()
{
if (hookRenderer == null)
return;
float input = 0;
if (Input.GetKey(KeyCode.U))
input = 1; // 上升
else if (Input.GetKey(KeyCode.O))
input = -1; // 下降
currentBlendValue += input * blendShapeSpeed * Time.deltaTime;
currentBlendValue = Mathf.Clamp(currentBlendValue, minBlendShapeValue, maxBlendShapeValue);
hookRenderer.SetBlendShapeWeight(hookBlendShapeIndex, currentBlendValue);
}
public void hookSize()
{
if (hookCollider != null)
{
hookCollider.center = new Vector3(-0.1262663f, -0.01883008f, -0.5113189f + currentBlendValue * Max);
hookCollider.size = new Vector3(0.1096101f, 0.2627291f, 0.3099952f + currentBlendValue * Min);
}
}
}