Fixed a lot of errors:

Obosolet methods, null references
Removed dead code
Clean Code
This commit is contained in:
PC-PAUL\paulf 2025-01-16 11:07:26 +01:00
parent 15a847cbde
commit 5a58064e4d
13 changed files with 195 additions and 1393 deletions

View File

@ -8,7 +8,8 @@ public class laserScript : MonoBehaviour {
// Use this for initialization
void Start () {
laserLine = GetComponentInChildren<LineRenderer> ();
laserLine.SetWidth (.2f, .2f);
laserLine.startWidth = .2f;
laserLine.endWidth = .2f;
}
// Update is called once per frame

View File

@ -240,7 +240,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5827ef60d322c73468e816b5411af65a, type: 3}
m_Name:
m_EditorClassIdentifier:
restartButton: {fileID: 0}
restartButton: {fileID: 344149856}
--- !u!1 &117032977
GameObject:
m_ObjectHideFlags: 0
@ -873,9 +873,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
distanceText: {fileID: 2089165862}
numberCoinsText: {fileID: 142150283}
joueur1Text: {fileID: 0}
joueur2Text: {fileID: 0}
is1v1Mode: 0
--- !u!1 &963194225
GameObject:
m_ObjectHideFlags: 0
@ -1052,7 +1049,10 @@ PrefabInstance:
propertyPath: PlayerHUD
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 7509186232753540492, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
- {fileID: 7896966939631641298, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
- {fileID: 6456075115708800826, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []

View File

@ -711,9 +711,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
distanceText: {fileID: 393375357}
numberCoinsText: {fileID: 403573105}
joueur1Text: {fileID: 0}
joueur2Text: {fileID: 0}
is1v1Mode: 1
--- !u!1 &565350509
GameObject:
m_ObjectHideFlags: 0
@ -1697,7 +1694,10 @@ PrefabInstance:
propertyPath: PlayerHUD
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 7509186232753540492, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
- {fileID: 7896966939631641298, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
- {fileID: 6456075115708800826, guid: 01fa89ab9028c864b8560621b7d51f50, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
@ -2103,7 +2103,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -267, y: -23.000015}
m_SizeDelta: {x: 215.7859, y: 191.7685}
m_SizeDelta: {x: 215.7859, y: 189.79}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2043114202
MonoBehaviour:

View File

@ -1,33 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using Pools;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
public class Obstacle : PoolingObject<Obstacle>, IObstacle,IDamageDealer,IResettable
namespace Obstacles
{
[field: SerializeField] public bool IsOnAllLanes { get; private set; }
[field: SerializeField] public bool IsInevitable { get; private set; }
public BoxCollider Collider { get; private set; }
[RequireComponent(typeof(BoxCollider))]
public class Obstacle : PoolingObject<Obstacle>, IObstacle,IDamageDealer,IResettable
{
[field: SerializeField] public bool IsOnAllLanes { get; private set; }
[field: SerializeField] public bool IsInevitable { get; private set; }
public BoxCollider Collider { get; private set; }
private void Awake()
{
Collider = GetComponent<BoxCollider>();
}
public void ResetToDefault()
{
transform.localPosition = Vector3.zero;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
gameObject.transform.SetParent(OwningPool.transform);
ReturnToPool();
}
public void Impact()
{
ResetToDefault();
}
private void Awake()
{
Collider = GetComponent<BoxCollider>();
OwningPool = FindFirstObjectByType<ObstaclePool>();
}
public void ResetToDefault()
{
transform.localPosition = Vector3.zero;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
gameObject.transform.SetParent(OwningPool.transform);
ReturnToPool();
}
public void Impact()
{
ResetToDefault();
}
public void DealDamage(IDamageable target, int amount)
{
target.TakeDamage(amount);
public void DealDamage(IDamageable target, int amount)
{
target.TakeDamage(amount);
}
}
}

View File

@ -60,7 +60,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
public bool IsInvincible { get; private set; }
public float InvincibilityTime { get; private set; } //PLAYER DATA ScriptableObject
[SerializeField] private Boolean isPlayer2;
[SerializeField] private Boolean isPlaying1VS1;
public bool isDead = false;
private void Awake()
@ -132,20 +131,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
PlayerStateMachine.SetState(PlayerStateMachine.PlayerDeadState);
GameSession.Instance.UpdateScoreboard(new ScoreboardEntry(name, PlayerStatictics.Score));
GameSession.Instance.HandlePlayerDeath(this); // Informe GameSession qu'un joueur est mort
// PlayerStateMachine.SetState(PlayerStateMachine.PlayerDeadState);
// GameSession.Instance.UpdateScoreboard(new ScoreboardEntry(name, PlayerStatictics.Score));
// if (isPlaying1VS1)
// {
// // SceneManager.LoadScene("DeathScreen1v1");
// SceneManager.LoadScene("Death1VS1");
//
// }
// else
// {
// SceneManager.LoadScene("Death1VS1");
// }
//
}
public IEnumerator GrantInvincibility()

View File

@ -1,39 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimator
{
private Animator animator;
private int runningHash = Animator.StringToHash("Run");
private int deadHash = Animator.StringToHash("Dead");
private int jumpHash = Animator.StringToHash("Jump");
private int slideHash = Animator.StringToHash("Slide");
private int idleHash = Animator.StringToHash("Idle");
private readonly Animator _animator;
private readonly int _runningHash = Animator.StringToHash("Run");
private readonly int _deadHash = Animator.StringToHash("Dead");
private readonly int _jumpHash = Animator.StringToHash("Jump");
private readonly int _slideHash = Animator.StringToHash("Slide");
private readonly int _idleHash = Animator.StringToHash("Idle");
public PlayerAnimator(Animator animator)
{
if (animator)
this.animator = animator;
this._animator = animator;
}
public void SetRunState(bool isRunning)
{
animator?.SetBool(runningHash, isRunning);
_animator?.SetBool(_runningHash, isRunning);
}
public void SetJumpState(bool isJumping)
{
animator?.SetBool(jumpHash, isJumping);
_animator?.SetBool(_jumpHash, isJumping);
}
public void SetDeadState(bool isDead)
{
animator?.SetBool(deadHash, isDead);
_animator?.SetBool(_deadHash, isDead);
}
public void SetSlideState(bool isSliding)
{
animator?.SetBool(slideHash, isSliding);
_animator?.SetBool(_slideHash, isSliding);
}
public void SetIdleState(bool isIdle)
{
animator?.SetBool(idleHash, isIdle);
if(_animator){}
_animator?.SetBool(_idleHash, isIdle);
}
}

View File

@ -22,7 +22,6 @@ public abstract class MovingState : PlayerState
public override void Tick()
{
speed = playerData.CurrentSpeed;
//HandleDirection();
playerSM.HorizontalDeltaPosition = playerSM.PlayerTransform.forward * speed * Time.deltaTime ;
playerSM.HorizontalDeltaPosition += playerSM.PlayerTransform.forward * speed * Time.deltaTime;
playerSM.UpdateDistance(playerSM.HorizontalDeltaPosition.z); //вынести в контроллер
@ -38,28 +37,6 @@ public abstract class MovingState : PlayerState
playerSM.VerticalDeltaPosition += gravity * Time.deltaTime;
}
//private void HandleDirection()
//{
// switch (playerSM.InputDirection)
// {
// case EInputDirection.RIGHT:
// playerSM.IncreaseTargetLane();
// break;
// case EInputDirection.LEFT:
// playerSM.DecreaseTargetLane();
// break;
// case EInputDirection.UP:
// playerSM.SetState(playerSM.PlayerJumpState);
// break;
// case EInputDirection.DOWN:
// playerSM.SetState(playerSM.PlayerSlideState);
// break;
// default:
// break;
// }
//}
public void SwitchLane()
{
float sidewaysPos = playerTransform.localPosition.x;
@ -83,9 +60,6 @@ public abstract class MovingState : PlayerState
playerSM.HorizontalDeltaPosition += playerSM.PlayerTransform.right * diffX.x;
}
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class Statistics : MonoBehaviour,IResettable
{
@ -12,7 +13,7 @@ public class Statistics : MonoBehaviour,IResettable
public event Action<int> OnCoinCountChanged = delegate { };
public event Action<float> OnDistanceChanged = delegate { };
public event Action<int> OnScoreCalculated = delegate { };
[SerializeField] private PlayerHUDView PlayerHUD;
[FormerlySerializedAs("PlayerHUD")] [SerializeField] private PlayerHUDView playerHUD;
private void Awake()
{
ResetToDefault();
@ -43,7 +44,7 @@ public class Statistics : MonoBehaviour,IResettable
{
Score = Mathf.FloorToInt(coinCount * coinMultiplier + distance);
OnScoreCalculated?.Invoke(Score);
PlayerHUD.UpdateScore(Score.ToString());
playerHUD.UpdateScore(Score.ToString());
}
public void ResetToDefault()

View File

@ -8,6 +8,8 @@
// </auto-generated>
//------------------------------------------------------------------------------
using Obstacles;
namespace Pools
{

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Obstacles;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]

View File

@ -1,140 +1,143 @@

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;
using System.IO;
using UnityEditor;
using UnityEngine;
public class CubemapTextureBuilder : EditorWindow
namespace Utils
{
[MenuItem("Tools/Cubemap Builder")]
public static void OpenWindow()
public class CubemapTextureBuilder : EditorWindow
{
GetWindow<CubemapTextureBuilder>();
}
Texture2D[] textures = new Texture2D[6];
string[] labels = new string[] {
"Right", "Left",
"Top", "Bottom",
"Front", "Back"
};
TextureFormat[] HDRFormats = new TextureFormat[] {
TextureFormat.ASTC_HDR_10x10 ,
TextureFormat.ASTC_HDR_12x12 ,
TextureFormat.ASTC_HDR_4x4 ,
TextureFormat.ASTC_HDR_5x5 ,
TextureFormat.ASTC_HDR_6x6 ,
TextureFormat.ASTC_HDR_8x8 ,
TextureFormat.BC6H ,
TextureFormat.RGBAFloat ,
TextureFormat.RGBAHalf
};
Vector2Int[] placementRects = new Vector2Int[]
{
new Vector2Int(2, 1),
new Vector2Int(0, 1),
new Vector2Int(1, 2),
new Vector2Int(1, 0),
new Vector2Int(1, 1),
new Vector2Int(3, 1),
};
private void OnGUI()
{
for (int i = 0; i < 6; i++)
[MenuItem("Tools/Cubemap Builder")]
public static void OpenWindow()
{
textures[i] = EditorGUILayout.ObjectField(labels[i], textures[i], typeof(Texture2D), false) as Texture2D;
GetWindow<CubemapTextureBuilder>();
}
if (GUILayout.Button("Build Cubemap"))
private readonly Texture2D[] _textures = new Texture2D[6];
private readonly string[] _labels = new string[] {
"Right", "Left",
"Top", "Bottom",
"Front", "Back"
};
private readonly TextureFormat[] _hdrFormats = new TextureFormat[] {
TextureFormat.ASTC_HDR_10x10 ,
TextureFormat.ASTC_HDR_12x12 ,
TextureFormat.ASTC_HDR_4x4 ,
TextureFormat.ASTC_HDR_5x5 ,
TextureFormat.ASTC_HDR_6x6 ,
TextureFormat.ASTC_HDR_8x8 ,
TextureFormat.BC6H ,
TextureFormat.RGBAFloat ,
TextureFormat.RGBAHalf
};
private readonly Vector2Int[] _placementRects = new Vector2Int[]
{
// Missing Texture
if (textures.Any(t => t == null))
{
EditorUtility.DisplayDialog("Cubemap Builder Error", "One or more texture is missing.", "Ok");
return;
}
new Vector2Int(2, 1),
new Vector2Int(0, 1),
new Vector2Int(1, 2),
new Vector2Int(1, 0),
new Vector2Int(1, 1),
new Vector2Int(3, 1),
};
// Get size
var size = textures[0].width;
// Not all of the same size or square
if (textures.Any(t => (t.width != size) || (t.height != size)))
{
EditorUtility.DisplayDialog("Cubemap Builder Error", "All the textures need to be the same size and square.", "Ok");
return;
}
var isHDR = HDRFormats.Any(f => f == textures[0].format);
var texturePaths = textures.Select(t => AssetDatabase.GetAssetPath(t)).ToArray();
// Should be ok, ask for the file path.
var path = EditorUtility.SaveFilePanel("Save Cubemap", Path.GetDirectoryName(texturePaths[0]), "Cubemap", isHDR ? "exr" : "png");
if (string.IsNullOrEmpty(path)) return;
// Save the readable flag to restore it afterwards
var readableFlags = textures.Select(t => t.isReadable).ToArray();
// Get the importer and mark the textures as readable
var importers = texturePaths.Select(p => TextureImporter.GetAtPath(p) as TextureImporter).ToArray();
foreach (var importer in importers)
{
importer.isReadable = true;
}
AssetDatabase.Refresh();
foreach (var p in texturePaths)
{
AssetDatabase.ImportAsset(p);
}
// Build the cubemap texture
var cubeTexture = new Texture2D(size * 4, size * 3, isHDR ? TextureFormat.RGBAFloat : TextureFormat.RGBA32, false);
private void OnGUI()
{
for (int i = 0; i < 6; i++)
{
cubeTexture.SetPixels(placementRects[i].x * size, placementRects[i].y * size, size, size, textures[i].GetPixels(0));
_textures[i] = EditorGUILayout.ObjectField(_labels[i], _textures[i], typeof(Texture2D), false) as Texture2D;
}
cubeTexture.Apply(false);
// Save the texture to the specified path, and destroy the temporary object
var bytes = isHDR ? cubeTexture.EncodeToEXR() : cubeTexture.EncodeToPNG();
File.WriteAllBytes(path, bytes);
DestroyImmediate(cubeTexture);
// Reset the read flags, and reimport everything
for (var i = 0; i < 6; i++)
if (GUILayout.Button("Build Cubemap"))
{
importers[i].isReadable = readableFlags[i];
// Missing Texture
if (_textures.Any(t => t == null))
{
EditorUtility.DisplayDialog("Cubemap Builder Error", "One or more texture is missing.", "Ok");
return;
}
// Get size
var size = _textures[0].width;
// Not all of the same size or square
if (_textures.Any(t => (t.width != size) || (t.height != size)))
{
EditorUtility.DisplayDialog("Cubemap Builder Error", "All the textures need to be the same size and square.", "Ok");
return;
}
var isHDR = _hdrFormats.Any(f => f == _textures[0].format);
var texturePaths = _textures.Select(AssetDatabase.GetAssetPath).ToArray();
// Should be ok, ask for the file path.
var path = EditorUtility.SaveFilePanel("Save Cubemap", Path.GetDirectoryName(texturePaths[0]), "Cubemap", isHDR ? "exr" : "png");
if (string.IsNullOrEmpty(path)) return;
// Save the readable flag to restore it afterwards
var readableFlags = _textures.Select(t => t.isReadable).ToArray();
// Get the importer and mark the textures as readable
var importers = texturePaths.Select(p => AssetImporter.GetAtPath(p) as TextureImporter).ToArray();
foreach (var importer in importers)
{
importer.isReadable = true;
}
AssetDatabase.Refresh();
foreach (var p in texturePaths)
{
AssetDatabase.ImportAsset(p);
}
// Build the cubemap texture
var cubeTexture = new Texture2D(size * 4, size * 3, isHDR ? TextureFormat.RGBAFloat : TextureFormat.RGBA32, false);
for (int i = 0; i < 6; i++)
{
cubeTexture.SetPixels(_placementRects[i].x * size, _placementRects[i].y * size, size, size, _textures[i].GetPixels(0));
}
cubeTexture.Apply(false);
// Save the texture to the specified path, and destroy the temporary object
var bytes = isHDR ? cubeTexture.EncodeToEXR() : cubeTexture.EncodeToPNG();
File.WriteAllBytes(path, bytes);
DestroyImmediate(cubeTexture);
// Reset the read flags, and reimport everything
for (var i = 0; i < 6; i++)
{
importers[i].isReadable = readableFlags[i];
}
path = path.Remove(0, Application.dataPath.Length - 6);
AssetDatabase.ImportAsset(path);
var cubeImporter = AssetImporter.GetAtPath(path) as TextureImporter;
if (cubeImporter)
{
cubeImporter.textureShape = TextureImporterShape.TextureCube;
cubeImporter.sRGBTexture = false;
cubeImporter.generateCubemap = TextureImporterGenerateCubemap.FullCubemap;
}
foreach (var p in texturePaths)
{
AssetDatabase.ImportAsset(p);
}
AssetDatabase.ImportAsset(path);
AssetDatabase.Refresh();
}
path = path.Remove(0, Application.dataPath.Length - 6);
AssetDatabase.ImportAsset(path);
var cubeImporter = AssetImporter.GetAtPath(path) as TextureImporter;
cubeImporter.textureShape = TextureImporterShape.TextureCube;
cubeImporter.sRGBTexture = false;
cubeImporter.generateCubemap = TextureImporterGenerateCubemap.FullCubemap;
foreach (var p in texturePaths)
{
AssetDatabase.ImportAsset(p);
}
AssetDatabase.ImportAsset(path);
AssetDatabase.Refresh();
}
}
}

View File

@ -1,3 +1,4 @@
using Assets.Scripts.GameSession;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
@ -20,6 +21,6 @@ public class RestartButton : MonoBehaviour
public void RestartGame()
{
SceneManager.LoadScene("GameScene");
GoToScene.GoToSoloMode();
}
}

File diff suppressed because one or more lines are too long