OldBlueWater/BlueWater/Assets/02.Scripts/Ai/Human/Combat/Pirate/PirateAi.cs

164 lines
5.5 KiB
C#
Raw Normal View History

2023-09-12 14:46:57 +00:00
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
2023-09-12 07:41:11 +00:00
using UnityEngine;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
2023-09-13 03:23:27 +00:00
public class PirateAi : CombatAi
2023-09-12 07:41:11 +00:00
{
2023-09-12 14:46:57 +00:00
#region Properties and variables
2023-09-12 07:41:11 +00:00
2023-09-12 14:46:57 +00:00
[Title("Skin")]
[Tooltip("SkinnedMeshRenderer, MeshRenderer의 Material을 모두 담고 있는 리스트")]
[SerializeField] protected List<Material> skinMaterialList = new(10);
[Tooltip("캐릭터 외곽선의 기본 색상")]
[SerializeField] protected Color defaultSkinColor = Color.black;
[Tooltip("캐릭터에 마우스 커서가 올라가 있을 때 색상")]
[SerializeField] protected Color mouseEnterHighlightSkinColor = Color.white;
[Tooltip("캐릭터가 선택되었을 때 색상")]
[SerializeField] protected Color selectedSkinColor = Color.red;
[DisableIf("@true")]
[SerializeField] private IslandInfo islandInfo;
2023-09-13 07:05:21 +00:00
[field: SerializeField] public PirateStat PirateStat { get; set; }
private PirateUnit mouseEnterPirateUnit;
private UnitSelection unitSelection;
2023-09-12 14:46:57 +00:00
#endregion
#region Unit Built-in methods
2023-09-13 07:05:21 +00:00
private void OnMouseEnter()
{
if (!unitSelection || !unitSelection.IsSelectable) return;
mouseEnterPirateUnit = gameObject.GetComponentInParent<PirateUnit>();
if (mouseEnterPirateUnit == unitSelection.SelectedPirateUnit) return;
foreach (var pirateAi in mouseEnterPirateUnit.pirateUnitStat.PirateAiList)
{
pirateAi.MouseEnterHighlight();
}
}
private void OnMouseExit()
{
if (!unitSelection || !unitSelection.IsSelectable ||
!mouseEnterPirateUnit || mouseEnterPirateUnit == unitSelection.SelectedPirateUnit) return;
foreach (var pirateAi in mouseEnterPirateUnit.pirateUnitStat.PirateAiList)
{
pirateAi.ResetHighlight();
}
mouseEnterPirateUnit = null;
}
2023-09-12 14:46:57 +00:00
private void Start()
{
InitStart();
}
#endregion
#region Custom methods
2023-09-13 07:05:21 +00:00
protected override void InitComponent()
{
base.InitComponent();
unitSelection = Utils.GetComponentAndAssert<UnitSelection>(GameObject.Find("UnitManager").transform);
}
2023-09-12 14:46:57 +00:00
protected override void SetLayer()
{
gameObject.layer = LayerMask.NameToLayer("Pirate");
var hitBoxObj = hitBoxCollider.gameObject;
hitBoxObj.layer = LayerMask.NameToLayer("HitBox");
hitBoxObj.tag = "Pirate";
targetLayer = LayerMask.GetMask("Enemy");
2023-09-13 07:05:21 +00:00
if (PirateStat.AttackerType == EAttackerType.OFFENSE)
2023-09-12 14:46:57 +00:00
{
targetLayer |= LayerMask.GetMask("Props");
}
}
protected virtual void InitStart()
{
2023-09-13 07:05:21 +00:00
var pirateViewData = DataManager.Inst.GetPirateViewDictionaryFromKey(PirateStat.ViewIdx);
2023-09-12 14:46:57 +00:00
InitViewModel(pirateViewData);
FindMaterial();
2023-09-13 07:05:21 +00:00
SetCurrentHp(PirateStat.MaxHp);
SetMoveSpeed(PirateStat.MoveSpd);
2023-09-12 14:46:57 +00:00
2023-09-13 07:05:21 +00:00
if (PirateStat.AttackerType == EAttackerType.DEFENSE)
2023-09-12 14:46:57 +00:00
{
defensePos = transform.position;
}
}
private void InitViewModel(PirateView pirateView)
{
SetActiveViewModel(backpackContainer, pirateView.Backpack);
SetActiveViewModel(leftWeaponContainer, pirateView.LeftWeapon);
SetActiveViewModel(leftShieldContainer, pirateView.LeftShield);
SetActiveViewModel(headContainer, pirateView.Head);
SetActiveViewModel(rightWeaponContainer, pirateView.RightWeapon);
SetActiveViewModel(bodyContainer, pirateView.Body);
SetActiveViewModel(flagContainer, pirateView.Flag);
}
private void FindMaterial()
{
var skinnedMeshRenderers = GetComponentsInChildren<SkinnedMeshRenderer>();
var meshRenderers = GetComponentsInChildren<MeshRenderer>();
foreach (var skin in skinnedMeshRenderers)
{
if (!skin.gameObject.activeSelf) continue;
skinMaterialList.Add(skin.material);
}
foreach (var skin in meshRenderers)
{
if (!skin.gameObject.activeSelf) continue;
skinMaterialList.Add(skin.material);
}
}
2023-09-13 07:05:21 +00:00
public void CommandMove(Vector3 movePos)
{
}
2023-09-12 14:46:57 +00:00
2023-09-13 07:05:21 +00:00
private void SetOutlineColor(Color color)
{
foreach (var skin in skinMaterialList)
{
skin.SetColor(OutlineColorHash, color);
}
}
2023-09-12 14:46:57 +00:00
2023-09-13 07:05:21 +00:00
protected override void SetCurrentHp(float value) => PirateStat.CurrentHp = value;
public void SetAttackerType(EAttackerType type) => PirateStat.AttackerType = type;
public void SetOffenseType(EOffenseType type) => PirateStat.OffenseType = type;
public void SetDefenseType(EDefenseType type) => PirateStat.DefenseType = type;
public void ResetHighlight() => SetOutlineColor(defaultSkinColor);
public void MouseEnterHighlight() => SetOutlineColor(mouseEnterHighlightSkinColor);
public void SelectedHighlight() => SetOutlineColor(selectedSkinColor);
2023-09-12 14:46:57 +00:00
#endregion
2023-09-12 07:41:11 +00:00
}
}