feat: Blob

This commit is contained in:
2026-09-14 15:04:45 +02:00
parent 2b3ff30aeb
commit 60d0a81f3c
9 changed files with 7248 additions and 1 deletions

View File

@@ -0,0 +1,143 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: M_Blob
m_Shader: {fileID: -6465566751694194690, guid: 77257adc6c53e7241a0e3726d961062e, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Amplitude: 0.2
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _EyesSize: 0.06
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Jumping: 1
- _Metallic: 0.6
- _Moving: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueControl: 0
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.6
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _Speed: 10
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.4645335, g: 0.6886792, b: 0.546041, a: 0.9019608}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EyesColor: {r: 27.586525, g: 57.90601, b: 95.8745, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &3651211165860614780
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20a707c72776dfa439c1f75179ef90cd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -24,7 +24,8 @@ Material:
m_Shader: {fileID: -6465566751694194690, guid: 8568d1cbfba747144b370a89c97e5011, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_ValidKeywords:
- _RAINMAPPING_WORLD
m_InvalidKeywords: []
m_LightmapFlags: 2
m_EnableInstancingVariants: 0
@@ -54,6 +55,7 @@ Material:
- _Metallic: 0
- _QueueControl: 0
- _QueueOffset: 0
- _RAINMAPPING: 0
- _RainSize: 4
- _Ripples: 1
- _RipplesSize: 3

BIN
Assets/_Content/Scenes/Blob.unity LFS Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f2733286f7dd782468d8c3b9c564116e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,221 @@
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
public class BlobController : MonoBehaviour
{
private Transform playerCamera;
[Header("Movement Speeds")]
[SerializeField] private float walkSpeed = 5f;
[SerializeField] private float sprintSpeed = 9f;
[SerializeField] private float acceleration = 10f;
[SerializeField] private float deceleration = 15f;
[Header("Jump & Gravity")]
[SerializeField] private float jumpHeight = 1.5f;
[SerializeField] private float gravity = -20f;
[SerializeField] private float groundedGravity = -2f;
[Header("Camera Settings (3rd Person)")]
[SerializeField] private float cameraDistance = 5f;
[SerializeField] private float cameraHeightOffset = 1.5f;
[SerializeField] private float cameraSmoothSpeed = 15f;
[SerializeField] private float lookSensitivity = 0.2f;
[SerializeField] private float minPitch = -20f;
[SerializeField] private float maxPitch = 60f;
[Header("Input Actions")]
[SerializeField] private InputActionReference moveAction;
[SerializeField] private InputActionReference sprintAction;
[SerializeField] private InputActionReference jumpAction;
[SerializeField] private InputActionReference lookAction;
[Header("Shader / Material")]
[Tooltip("Laissez vide pour chercher automatiquement le Renderer sur ce GameObject ou ses enfants.")]
[SerializeField] private Renderer blobRenderer;
[Tooltip("Vitesse d'interpolation des paramètres _Moving et _Jumping.")]
[SerializeField] private float shaderTransitionSpeed = 5f;
private Material blobMaterial;
private readonly int movingPropertyID = Shader.PropertyToID("_Moving");
private readonly int jumpingPropertyID = Shader.PropertyToID("_Jumping");
private CharacterController controller;
private Vector3 currentVelocity;
private float verticalVelocity;
private bool isGrounded;
// Valeurs pour le shader
private float currentMovingValue = 0f;
private float currentJumpingValue = 0f;
// Variables de contrôle de la caméra
private float yaw = 0f;
private float pitch = 15f;
private Vector3 smoothedTargetFocusPoint;
private bool isCameraInitialized = false;
private void Awake()
{
controller = GetComponent<CharacterController>();
if (Camera.main != null)
{
playerCamera = Camera.main.transform;
}
else
{
Debug.LogWarning("Aucune 'Main Camera' n'a été trouvée dans la scène !");
}
if (blobRenderer == null)
{
blobRenderer = GetComponentInChildren<Renderer>();
}
if (blobRenderer != null)
{
blobMaterial = blobRenderer.material;
}
// Verrouillage et masquage du curseur de la souris au démarrage
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void OnEnable()
{
if (moveAction != null) moveAction.action.Enable();
if (sprintAction != null) sprintAction.action.Enable();
if (jumpAction != null) jumpAction.action.Enable();
if (lookAction != null) lookAction.action.Enable();
}
private void OnDisable()
{
if (moveAction != null) moveAction.action.Disable();
if (sprintAction != null) sprintAction.action.Disable();
if (jumpAction != null) jumpAction.action.Disable();
if (lookAction != null) lookAction.action.Disable();
}
private void Update()
{
HandleGroundCheck();
HandleGravity();
HandleMovement();
UpdateShaderParameters();
}
private void LateUpdate()
{
HandleCamera();
}
private void HandleGroundCheck()
{
isGrounded = controller.isGrounded;
if (isGrounded && verticalVelocity < 0.0f)
{
verticalVelocity = groundedGravity;
}
}
private void HandleGravity()
{
if (isGrounded && jumpAction != null && jumpAction.action.triggered)
{
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
verticalVelocity += gravity * Time.deltaTime;
}
private void HandleMovement()
{
Vector2 inputVector = moveAction != null ? moveAction.action.ReadValue<Vector2>() : Vector2.zero;
if (playerCamera == null && Camera.main != null)
{
playerCamera = Camera.main.transform;
}
Vector3 forward = playerCamera ? playerCamera.forward : Vector3.forward;
Vector3 right = playerCamera ? playerCamera.right : Vector3.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
Vector3 targetDirection = (forward * inputVector.y + right * inputVector.x).normalized;
bool isSprinting = sprintAction != null && sprintAction.action.IsPressed();
float targetSpeed = isSprinting ? sprintSpeed : walkSpeed;
if (inputVector.sqrMagnitude == 0f)
{
targetSpeed = 0f;
}
float currentAccel = (inputVector.sqrMagnitude > 0f) ? acceleration : deceleration;
Vector3 targetVelocity3D = targetDirection * targetSpeed;
currentVelocity.x = Mathf.MoveTowards(currentVelocity.x, targetVelocity3D.x, currentAccel * Time.deltaTime);
currentVelocity.z = Mathf.MoveTowards(currentVelocity.z, targetVelocity3D.z, currentAccel * Time.deltaTime);
Vector3 finalMovement = new Vector3(currentVelocity.x, verticalVelocity, currentVelocity.z);
controller.Move(finalMovement * Time.deltaTime);
if (targetDirection != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 15f * Time.deltaTime);
}
}
private void HandleCamera()
{
if (playerCamera == null) return;
Vector2 lookInput = lookAction != null ? lookAction.action.ReadValue<Vector2>() : Vector2.zero;
yaw += lookInput.x * lookSensitivity;
pitch -= lookInput.y * lookSensitivity;
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
Vector3 rawTargetFocusPoint = transform.position + Vector3.up * cameraHeightOffset;
if (!isCameraInitialized)
{
smoothedTargetFocusPoint = rawTargetFocusPoint;
isCameraInitialized = true;
}
else
{
smoothedTargetFocusPoint = Vector3.Lerp(smoothedTargetFocusPoint, rawTargetFocusPoint, cameraSmoothSpeed * Time.deltaTime);
}
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0f);
Vector3 finalCameraPosition = smoothedTargetFocusPoint - (rotation * Vector3.forward * cameraDistance);
playerCamera.position = finalCameraPosition;
playerCamera.rotation = rotation;
}
private void UpdateShaderParameters()
{
if (blobMaterial == null) return;
Vector3 horizontalVelocity = new Vector3(currentVelocity.x, 0f, currentVelocity.z);
float currentSpeed = horizontalVelocity.magnitude;
float targetMovingValue = walkSpeed > 0.001f ? currentSpeed / walkSpeed : 0f;
currentMovingValue = Mathf.MoveTowards(currentMovingValue, targetMovingValue, shaderTransitionSpeed * Time.deltaTime);
blobMaterial.SetFloat(movingPropertyID, currentMovingValue);
float targetJumpingValue = isGrounded ? 0f : 1f;
currentJumpingValue = Mathf.MoveTowards(currentJumpingValue, targetJumpingValue, shaderTransitionSpeed * Time.deltaTime);
blobMaterial.SetFloat(jumpingPropertyID, currentJumpingValue);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d9cb40c225bf71a49b97352d8138791d

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 77257adc6c53e7241a0e3726d961062e
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
useAsTemplate: 0
exposeTemplateAsShader: 0
template:
name:
category:
description:
icon: {instanceID: 0}
thumbnail: {instanceID: 0}