Skip to content

Commit

Permalink
リファクタリング作業
Browse files Browse the repository at this point in the history
  • Loading branch information
mudai0910 committed Mar 25, 2024
1 parent 28ef117 commit 34c5831
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 239 deletions.
75 changes: 17 additions & 58 deletions Assets/Attack/Scripts/attackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,44 @@
using UnityEngine;
using UnityEngine.InputSystem;

public class attackHandler : MonoBehaviour
public class AttackHandler : MonoBehaviour
{
//InputAction
private InputAction attack;


[Header("attackParameter")]
[SerializeField] private LayerMask attackable;
[SerializeField] private LayerMask CityMaterials;
[SerializeField] private LayerMask cityMaterials;
[SerializeField] private Material lineColor;
[SerializeField] private Transform tipPosition;
[SerializeField] private float distance = 50f;
private bool isAttack;
private Vector3 attackPosition;

private GameObject player;

//敵のコントローラー取得
private EnemyController enemyController;

//電撃
private LineRenderer lr;
[SerializeField] private Texture[] ElectricTexture;
private int ElectricAnimationStep;
private LineRenderer lineRenderer;
[SerializeField] private float fps = 30f;
private float fpsCounter;
private float electroRelease = 0.1f;

//経過時間管理
private float elapsedTime = 0f;

//se
//SE
[SerializeField] private AudioClip spark;
private AudioSource sparkSound;

private void Awake()
{
var playerInput = GetComponent<PlayerInput>();
attack = playerInput.actions["attack"];
lr = this.GetComponent<LineRenderer>();
lr.enabled = false;
lineRenderer = this.GetComponent<LineRenderer>();
lineRenderer.enabled = false;
sparkSound = this.AddComponent<AudioSource>();
sparkSound.clip = spark;
sparkSound.loop = false;

player = GameObject.Find("PlayerArmature");

}

private void Update()
Expand All @@ -59,10 +50,6 @@ private void Update()
{
elapsedTime += Time.deltaTime;
fpsCounter += Time.deltaTime;
if(fpsCounter >= 1/fps)
{
ElectricAnimationStep++;
}
if(elapsedTime >electroRelease)
{
RemoveElectro();
Expand All @@ -71,18 +58,7 @@ private void Update()
}
attack.performed += OnAttackAction;
DrawElectro();
//CheckClickLeftMouseButton();
}

//public void CheckClickLeftMouseButton()
//{
// if(Input.GetMouseButtonDown(0))
// {
// isAttack = true;
// }
// Attack();
//}

private void OnAttackAction(InputAction.CallbackContext context)
{
isAttack = true;
Expand All @@ -93,8 +69,7 @@ public void Attack()
{
if (isAttack)
{
lr.enabled = true;
// if (Physics.Raycast(player.transform.position, player.transform.forward, out RaycastHit hitAttack, 50f, attackable))
lineRenderer.enabled = true;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hitAttack, distance, attackable))
{

Expand All @@ -104,71 +79,55 @@ public void Attack()
Transform mesh = geometry.Find("Armature_Mesh");
attackPosition = new Vector3(mesh.position.x, mesh.position.y, mesh.position.z);
enemyController = hitAttack.collider.GetComponent<EnemyController>();
if (enemyController != null)
{
//enemyController.SetState(EnemyController.EnemyState.hit);
//enemyController.EnemyColorYellow(hitAttack);
}
else
if (enemyController == null)
{
Transform parent = hitAttack.transform.parent;
enemyController = parent.GetComponent<EnemyController>();
//enemyController.SetState(EnemyController.EnemyState.hit);
//enemyController.EnemyColorYellow(hitAttack);
}

if (!enemyController.getIsBiribiri())
if (!enemyController.GetIsBiribiri())
{
enemyController.SetState(EnemyController.EnemyState.hit);
enemyController.SetState(EnemyController.EnemyState.Hit);
enemyController.EnemyColorYellow(hitAttack);
enemyController.ChangeBIribiri();
enemyController.ChangeBiribiri();
}
//enemyController.ChangeBIribiri();

}
// else if (Physics.Raycast(player.transform.position, player.transform.forward + new Vector3(0f,0.1f,0f), out RaycastHit hit, 50f, CityMaterials))
else if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit, 50f,CityMaterials))
else if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit, 50f,cityMaterials))
{

attackPosition = hit.point;

}
else
{

// Vector3 forwardDirectiion = player.transform.forward + new Vector3(0f,0.1f,0f);
// Vector3 targetPosition = player.transform.position + forwardDirectiion * distance;
Vector3 forwardDirectiion = Camera.main.transform.forward;
Vector3 targetPosition = Camera.main.transform.position + forwardDirectiion * distance;
attackPosition = targetPosition;

}

//se再生
sparkSound.Play();
}
}

public bool checkAttack()
public bool CheckAttack()
{
return isAttack;
}

public void DrawElectro()
{
lr.SetPosition(0, tipPosition.position);
lr.SetPosition(1, attackPosition);
lineRenderer.SetPosition(0, tipPosition.position);
lineRenderer.SetPosition(1, attackPosition);
}

public void RemoveElectro()
{
isAttack = false;
if(lr != null)
if(lineRenderer != null)
{
lr.enabled = false;
lineRenderer.enabled = false;
}
}

private void OnDestroy()
{
attack.performed -= OnAttackAction;
Expand Down
33 changes: 5 additions & 28 deletions Assets/Cursor/Scripts/CursorManager.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,45 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;

public class CursorManager : MonoBehaviour
{
// public Image cursorImage; // UI Image
//public Sprite defaultCursorSprite;
//public Sprite highlightCursorSprite;
private AudioSource clickSound;
private Vector2 mousePosition;
public bool cursorState;
//カーソルが表示されているか
public bool isVisible;

public void OnEnable()
{
InputSystem.EnableDevice(Mouse.current);
}

public void OnDisable()
{
InputSystem.DisableDevice(Mouse.current);
}

public void OnVisible()
{
Cursor.visible = true;
cursorState = true;
isVisible = true;
}
public void OnInvisible()
{
Cursor.visible = false;
cursorState = false;
isVisible = false;
}

private void Awake()
{
clickSound = GetComponent<AudioSource>();
cursorState = false;
isVisible = false;
}
public void Update()
{
//mousePosition = Mouse.current.position.ReadValue();
Vector2 mousePosition = Mouse.current.position.ReadValue();
// cursorImage.rectTransform.position = mousePosition;
Cursor.lockState = CursorLockMode.Confined;
//if(Input.GetMouseButtonDown(0))
//{
// clickSound.Play();
//}
}

bool ShouldHighlightCursor()
{
return false;
}

public void CursorSoundPlay()
{
clickSound.Play();
}
public bool CheckClickSound()
{
return clickSound.isPlaying;
}

public float GetSoundLength()
{
return clickSound.clip.length;
Expand Down
Loading

0 comments on commit 34c5831

Please sign in to comment.