备份CatanBuilding瘦身独立工程
This commit is contained in:
50
Assets/Scripts/EventPinball/PinballSpring.cs
Normal file
50
Assets/Scripts/EventPinball/PinballSpring.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace game
|
||||
{
|
||||
public class PinballSpring : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform m_BottomPosition;
|
||||
[SerializeField] private SpriteRenderer m_SpriteRenderer;
|
||||
[SerializeField] private float m_MaxRatio = 0.5f;
|
||||
|
||||
#region 事件相关
|
||||
public void InitEvent()
|
||||
{
|
||||
FishingPinballAct.Subscribe<EventPinballSpringUpdateData>(UpdateSpring);
|
||||
}
|
||||
public void UpdateSpring(EventPinballSpringUpdateData data)
|
||||
{
|
||||
var spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
|
||||
float boundX = spriteRenderer.bounds.size.x;
|
||||
|
||||
float reservedRatio = 1.0f - m_MaxRatio;
|
||||
float validRatio = m_MaxRatio * data.Ratio;
|
||||
float scaleY = reservedRatio + validRatio;
|
||||
|
||||
m_SpriteRenderer.transform.localScale = new Vector3(m_SpriteRenderer.transform.localScale.x, scaleY, m_SpriteRenderer.transform.localScale.z);
|
||||
|
||||
float height = m_SpriteRenderer.bounds.size.y;
|
||||
|
||||
float y = m_BottomPosition.position.y + height / 2;
|
||||
transform.position = new Vector3(transform.position.x, y, transform.position.z);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
InitEvent();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user