PlayerVisual Customization
This commit is contained in:
@@ -302,6 +302,9 @@ public class Player : MonoBehaviour
|
||||
_state.Ground = currentGround;
|
||||
_lastPlatformPosition = _state.Ground.position;
|
||||
_lastPlatformRotation = _state.Ground.rotation;
|
||||
|
||||
_impulseForce.y = _platformVelocity.y = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -342,9 +345,32 @@ public class Player : MonoBehaviour
|
||||
private void SetGravity(float deltaTime)
|
||||
{
|
||||
if (_state.IsGrounded && _state.Velocity.y < 0)
|
||||
{
|
||||
_state.Velocity.y = STICK_FORCE;
|
||||
}
|
||||
else if (_persistentForce.y <= 0)
|
||||
_state.Velocity.y = Mathf.Max(_state.Velocity.y + GRAVITY * deltaTime, MAX_GRAVITY);
|
||||
{
|
||||
if (_platformVelocity.y > 0)
|
||||
{
|
||||
_platformVelocity.y += GRAVITY * deltaTime;
|
||||
|
||||
if (_platformVelocity.y < 0)
|
||||
_state.Velocity.y += _platformVelocity.y;
|
||||
}
|
||||
else if (_impulseForce.y > 0)
|
||||
{
|
||||
_impulseForce.y += GRAVITY * deltaTime;
|
||||
|
||||
if (_impulseForce.y < 0)
|
||||
_state.Velocity.y += _impulseForce.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state.Velocity.y += GRAVITY * deltaTime;
|
||||
}
|
||||
|
||||
_state.Velocity.y = Mathf.Max(_state.Velocity.y, MAX_GRAVITY);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetVelocity(float deltaTime)
|
||||
@@ -398,19 +424,25 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void SetMovement(float deltaTime)
|
||||
{
|
||||
Vector3 totalVelocity = _state.Velocity + _impulseForce + _persistentForce + _platformVelocity;
|
||||
_references.Controller.Move(totalVelocity * deltaTime);
|
||||
Vector3 velocity = _state.Velocity + _impulseForce + _persistentForce + _platformVelocity;
|
||||
_references.Controller.Move(velocity * deltaTime);
|
||||
|
||||
// Decay impulse force
|
||||
_impulseForce = Vector3.MoveTowards(_impulseForce, Vector3.zero,
|
||||
_settings.ExtraForcesDrag * deltaTime);
|
||||
Vector3 impulseForce = Vector3.MoveTowards(_impulseForce, Vector3.zero, _settings.ExtraForcesDrag * deltaTime);
|
||||
impulseForce.y = _impulseForce.y;
|
||||
_impulseForce = impulseForce;
|
||||
|
||||
// Decay inherited platform velocity — reset when back on ground
|
||||
if (_state.IsGrounded)
|
||||
{
|
||||
_platformVelocity = Vector3.zero;
|
||||
}
|
||||
else
|
||||
_platformVelocity = Vector3.MoveTowards(_platformVelocity, Vector3.zero,
|
||||
_settings.ExtraForcesDrag * deltaTime);
|
||||
{
|
||||
Vector3 platformVelocity = Vector3.MoveTowards(_platformVelocity, Vector3.zero, _settings.ExtraForcesDrag * deltaTime);
|
||||
platformVelocity.y = _platformVelocity.y;
|
||||
_platformVelocity = platformVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetState()
|
||||
|
||||
@@ -3,11 +3,19 @@ using UnityEngine;
|
||||
|
||||
public class PlayerVisual : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
private class Customization
|
||||
{
|
||||
[ColorUsage(false, true)] public Color[] Colors;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class References
|
||||
{
|
||||
public Player Player;
|
||||
public Animator Anim;
|
||||
public Renderer[] Renderers;
|
||||
public Material[] Materials;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -19,15 +27,20 @@ public class PlayerVisual : MonoBehaviour
|
||||
public string Trigger;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Customization _customization;
|
||||
|
||||
[SerializeField]
|
||||
private References _references;
|
||||
|
||||
[SerializeField]
|
||||
private PlayerAnimationStateMapper[] _playerAnimationStateMapper;
|
||||
|
||||
private const string PP_CUSTOM = "CustomPlayer";
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
LoadCustom();
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -35,8 +48,54 @@ public class PlayerVisual : MonoBehaviour
|
||||
UpdateAnimation();
|
||||
}
|
||||
|
||||
public void RandomizeCustom()
|
||||
{
|
||||
Debug.Log("randomize");
|
||||
}
|
||||
|
||||
private void SetCustom()
|
||||
{
|
||||
foreach (Renderer rend in _references.Renderers)
|
||||
{
|
||||
foreach (Material mat in rend.materials)
|
||||
{
|
||||
Material sourceMat = _references.Materials.FirstOrDefault(m => mat.name.StartsWith(m.name));
|
||||
|
||||
if (sourceMat)
|
||||
{
|
||||
Color col = _customization.Colors[System.Array.IndexOf(_references.Materials, sourceMat)];
|
||||
|
||||
if (!mat.IsKeywordEnabled("_EMISSION"))
|
||||
mat.color = col;
|
||||
else
|
||||
mat.SetColor("_EmissionColor", col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadCustom()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(PP_CUSTOM))
|
||||
return;
|
||||
|
||||
string json = PlayerPrefs.GetString(PP_CUSTOM);
|
||||
_customization = JsonUtility.FromJson<Customization>(json);
|
||||
|
||||
SetCustom();
|
||||
}
|
||||
|
||||
private void SaveCustom()
|
||||
{
|
||||
string json = JsonUtility.ToJson(_customization);
|
||||
PlayerPrefs.SetString(PP_CUSTOM, json);
|
||||
}
|
||||
|
||||
private void UpdateAnimation()
|
||||
{
|
||||
if (!_references.Player)
|
||||
return;
|
||||
|
||||
if (_references.Anim.IsInTransition(0))
|
||||
return;
|
||||
|
||||
@@ -61,4 +120,17 @@ public class PlayerVisual : MonoBehaviour
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color ShiftHue(Color color, float hueShift)
|
||||
{
|
||||
Color.RGBToHSV(color, out float h, out float s, out float v);
|
||||
|
||||
h += hueShift / 360f;
|
||||
h = Mathf.Repeat(h, 1f);
|
||||
|
||||
Color result = Color.HSVToRGB(h, s, v);
|
||||
result.a = color.a;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ using UnityEngine.Events;
|
||||
|
||||
public class Springboard : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float _force = 60;
|
||||
[SerializeField] private float _duration = .4f;
|
||||
[SerializeField] private AnimationCurve _curve = AnimationCurve.EaseInOut(0, 1, 1, 0);
|
||||
[SerializeField] private float _force = 20;
|
||||
[SerializeField] private UnityEvent _onJump;
|
||||
|
||||
void OnTriggerEnter(Collider col)
|
||||
@@ -13,7 +11,7 @@ public class Springboard : MonoBehaviour
|
||||
if (Player.Instance && col.gameObject == Player.Instance.gameObject)
|
||||
{
|
||||
Debug.Log("Player triggered springboard");
|
||||
//Player.Instance.AddExtraForce(transform.up * _force, true, _duration, _curve);
|
||||
Player.Instance.AddForce(transform.up * _force);
|
||||
_onJump?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user