Skip to content

Commit

Permalink
warning mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Vomeee committed Oct 3, 2024
1 parent 41576bc commit 4747349
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class EnemyAI : MonoBehaviour

[SerializeField] Transform player; // 플레이어의 Transform
[SerializeField] TargettingSystem targetingSystem;
[SerializeField] WarningController warningController;
float distanceToTarget;

[Header("movingAI instances")]
Expand Down Expand Up @@ -209,7 +210,7 @@ private void OnTriggerEnter(Collider other)
EnemySTDM missileScript = enemyMsl.GetComponent<EnemySTDM>(); //나중에 미사일 이름 바꿔서 따로 만들기.

Debug.Log("missile launch");
missileScript.Launch(player, 30);
missileScript.Launch(player, 30, warningController);

canShoot = false;
}
Expand Down Expand Up @@ -383,14 +384,16 @@ void Start()
Move();
}

public void initializeInstance(Transform playerTransform, TargettingSystem targettingSystem, TagController tagController, GameManagement gm, GameObject waypointObj, GameObject enemyMissile)
public void initializeInstance(Transform playerTransform, TargettingSystem targettingSystem,
TagController tagController, GameManagement gm, GameObject waypointObj, GameObject enemyMissile, WarningController warningController)
{
player = playerTransform; //필수, 만약 동료 추가시 initalize 다원화 필요,
this.targetingSystem = targettingSystem; //반드시 필요함.
this.tagController = tagController;
this.gameManagement = gm;
waypointObject = waypointObj;
enemyMissilePrefab = enemyMissile;
this.warningController = warningController;
}

#region target, lock controls
Expand Down
22 changes: 10 additions & 12 deletions Assets/Enemy Aircrafts/Wapons/Script/EnemySTDM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class EnemySTDM : MonoBehaviour
{

public WarningController wc;
public TagController tagController;
public Transform target; // 추적할 타겟

Expand All @@ -29,13 +29,16 @@ public class EnemySTDM : MonoBehaviour
[SerializeField] CapsuleCollider mslCollider;



public void Launch(Transform target, float launchSpeed)
public void Launch(Transform target, float launchSpeed, WarningController warningController)
{
wc = warningController;

// 타겟이 존재할 때만 할당
if (target != null)
{
this.target = target;

wc.TrackingMissileCount(1);
}

Debug.Log("Missile instantiated");
Expand All @@ -56,9 +59,10 @@ void LookAtTarget()
{
Debug.Log("evaded");
target = null;
return;


//경보 해제
wc.TrackingMissileCount(-1);
return;
}

Quaternion lookRotation = Quaternion.LookRotation(targetDir);
Expand Down Expand Up @@ -100,7 +104,7 @@ void Update()
Debug.Log(collision.gameObject.name);
if (collision.gameObject.CompareTag("Player"))
{

wc.TrackingMissileCount(-1);
// 적기에 부딪혔을 때 효과 생성
Instantiate(enemyHitEffect, transform.position, Quaternion.identity);

Expand Down Expand Up @@ -128,10 +132,4 @@ void Update()
// 총알 파괴

}

//private void OnTriggerExit(Collider other) //플레이어가 감지범위에서 탈출 -> Target lost. 지금 상황에서 가장 적합한 해법 같음.
//{
// Debug.Log("Target (player) escaped!");
// target = null;
//}
}
4 changes: 2 additions & 2 deletions Assets/PlayScript/Plot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Plot : MonoBehaviour
[SerializeField] GameManagement gameManagement;
[SerializeField] GameObject waypointObject;
[SerializeField] GameObject enemyMissilePrefab;

[SerializeField] WarningController warningController;
#endregion


Expand Down Expand Up @@ -55,7 +55,7 @@ void Update()

if (enemyAI1 != null )
{
enemyAI1.initializeInstance(playerTransform, targettingSystem, tagController, gameManagement, waypointObject, enemyMissilePrefab);
enemyAI1.initializeInstance(playerTransform, targettingSystem, tagController, gameManagement, waypointObject, enemyMissilePrefab, warningController);
}
else
{
Expand Down
132 changes: 128 additions & 4 deletions Assets/Scenes/MissionZero.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 0.971
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.12177536, g: 0.14450268, b: 0.17819491, a: 0.971}
m_IndirectSpecularColor: {r: 0.12177514, g: 0.14450201, b: 0.17819476, a: 0.971}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -15570,13 +15570,13 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1180232555}
m_LocalRotation: {x: 0.25000006, y: -0.06698733, z: 0.25000006, w: 0.9330127}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -3.4722238}
m_LocalScale: {x: 0.2, y: 5, z: 1}
m_LocalScale: {x: 0.2, y: 1.5, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8046267458772044279}
m_LocalEulerAnglesHint: {x: 30, y: 0, z: 30}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -0.66986084, y: 35.19998}
Expand Down Expand Up @@ -15638,6 +15638,7 @@ MonoBehaviour:
transparentColor: {r: 0, g: 0, b: 0, a: 0}
originalColor: {r: 0, g: 1, b: 0.627451, a: 0.627451}
isBeingShown: 0
radius: 50
--- !u!1 &1197247590
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -24463,6 +24464,7 @@ MonoBehaviour:
gameManagement: {fileID: 468138451}
waypointObject: {fileID: 6206487450123874273, guid: 82d9c450415cd0849a601e9a3a956998, type: 3}
enemyMissilePrefab: {fileID: 1765958663548051430, guid: 7cf8732bbef4a504b9e424390bf57538, type: 3}
warningController: {fileID: 8046267458772044280}
fa26Prefab: {fileID: 6749074832340177947, guid: 504e44d1d3428df47b96d5c7b4df2aa8, type: 3}
--- !u!1 &1956822339
GameObject:
Expand Down Expand Up @@ -47104,6 +47106,10 @@ PrefabInstance:
propertyPath: targetingSystem
value:
objectReference: {fileID: 1693827035}
- target: {fileID: 3032640693232928596, guid: 504e44d1d3428df47b96d5c7b4df2aa8, type: 3}
propertyPath: warningController
value:
objectReference: {fileID: 8046267458772044280}
- target: {fileID: 3032640693232928596, guid: 504e44d1d3428df47b96d5c7b4df2aa8, type: 3}
propertyPath: enemyMissilePrefab
value:
Expand Down Expand Up @@ -52770,6 +52776,8 @@ GameObject:
m_Component:
- component: {fileID: 8046267458772044279}
- component: {fileID: 7799833088894396460}
- component: {fileID: 8046267458772044280}
- component: {fileID: 8046267458772044281}
m_Layer: 8
m_Name: AircraftHUD_Panel
m_TagString: Untagged
Expand Down Expand Up @@ -63163,6 +63171,122 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &8046267458772044280
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5336649975840249360}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9f258b5e78e25d4438d3a76ddb2284f7, type: 3}
m_Name:
m_EditorClassIdentifier:
imageWarningColor: {r: 1, g: 0, b: 0, a: 0.72156864}
imageNormalColor: {r: 0, g: 1, b: 0, a: 0.5882353}
textWarningColor: {r: 1, g: 0, b: 0, a: 1}
textNormalColor: {r: 0, g: 0.7490196, b: 0, a: 1}
isWarningState: 0
currentEnemyMissile: 0
textMaterial: {fileID: 4726163729585724971, guid: 5edb44b9d8af0664e9aabe1bd38bbbe8, type: 2}
warningAudioSource: {fileID: 8046267458772044281}
--- !u!82 &8046267458772044281
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5336649975840249360}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: f493784ce365b9043955df8ccf9a01c2, type: 3}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!23 &8050562013355561990
MeshRenderer:
m_ObjectHideFlags: 0
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Sources/UI/Font/ACES07_Regular SDF.asset
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ Material:
- _GlowInner: 0.539
- _GlowOffset: 0
- _GlowOuter: 0.333
- _GlowPower: 0.211
- _GlowPower: 2.2
- _GradientScale: 10
- _LightAngle: 3.1416
- _MaskSoftnessX: 0
Expand Down Expand Up @@ -1737,8 +1737,8 @@ Material:
m_Colors:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0}
- _FaceColor: {r: 0.39150947, g: 1.0000001, b: 0.72551787, a: 1}
- _GlowColor: {r: 0, g: 1.8880861, b: 0, a: 1}
- _FaceColor: {r: 0, g: 0, b: 0, a: 0.6745098}
- _GlowColor: {r: 1, g: 0, b: 0, a: 1}
- _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767}
- _OutlineColor: {r: 0, g: 0, b: 0, a: 1}
- _ReflectFaceColor: {r: 0, g: 0, b: 0, a: 1}
Expand Down
18 changes: 15 additions & 3 deletions Assets/Sources/UI/Script/EnemyPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class EnemyPointer : MonoBehaviour
[SerializeField] Color originalColor; // 화살표가 보일 때의 색상

[SerializeField] bool isBeingShown; // 화살표가 활성화 상태인지
[SerializeField] float radius = 150f; // 화살표가 움직일 반지름

void Start()
{
Expand All @@ -38,10 +39,21 @@ void Update()
arrowImage.color = originalColor;
}

// 타겟이 카메라로부터 어느 방향에 있는지 계산
Vector3 targetDirFromCamera = targettingSystem.currentTargetTransform.position - targettingSystem.playerTransform.position;
// 타겟 방향을 카메라의 로컬 좌표계로 변환하여 계산
Vector3 targetDirFromCamera = (targettingSystem.currentTargetTransform.position - Camera.main.transform.position).normalized;

arrowRectTransform.up = targetDirFromCamera;
// 카메라의 로컬 좌표에서 타겟 방향을 계산 (카메라의 로컬 방향을 고려)
Vector3 arrowDirection = Camera.main.transform.InverseTransformDirection(targetDirFromCamera);

// 화살표의 transform.rotation을 카메라 회전을 반영하여 설정
float angle = Mathf.Atan2(arrowDirection.x, arrowDirection.y) * Mathf.Rad2Deg;
arrowImage.transform.rotation = Quaternion.Euler(0, 0, -angle);

// 화면 중앙을 기준으로 화살표 위치 계산
Vector2 arrowPosition = new Vector2(Mathf.Sin(angle * Mathf.Deg2Rad), Mathf.Cos(angle * Mathf.Deg2Rad)) * radius;

// 화살표의 RectTransform 위치 설정
arrowRectTransform.anchoredPosition = arrowPosition;
}
else
{
Expand Down
Loading

0 comments on commit 4747349

Please sign in to comment.