152 lines
5.6 KiB
C#
152 lines
5.6 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class SpecialWallController2 : MonoBehaviour
|
|||
|
{
|
|||
|
private Animator _animator;
|
|||
|
private EnemyController _guard1;
|
|||
|
private EnemyController _guard2;
|
|||
|
private EnemyController _guard3;
|
|||
|
private EnemyController _guard4;
|
|||
|
private EnemyController _guard5;
|
|||
|
private EnemyController _guard6;
|
|||
|
private EnemyController _guard7;
|
|||
|
private EnemyController _guard8;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_animator = GetComponent<Animator>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
GameManager.Instance.EventManager.OnResourceLoaded += GetGuardEvent;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
GameManager.Instance.EventManager.OnResourceLoaded -= GetGuardEvent;
|
|||
|
}
|
|||
|
|
|||
|
public void RecycleSelf()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|||
|
GameManager.Instance.PoolManager.RecycleResource(gameObject);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void GetGuardEvent()
|
|||
|
{
|
|||
|
_guard1 = null;
|
|||
|
_guard2 = null;
|
|||
|
_guard3 = null;
|
|||
|
_guard4 = null;
|
|||
|
_guard5 = null;
|
|||
|
_guard6 = null;
|
|||
|
_guard7 = null;
|
|||
|
_guard8 = null;
|
|||
|
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1>а<EFBFBD>λ<EFBFBD>û<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
Vector2[] points = new Vector2[] {
|
|||
|
new Vector2(-1, 2),
|
|||
|
new Vector2(1,2),
|
|||
|
new Vector2(3,2),
|
|||
|
new Vector2(5,2),
|
|||
|
new Vector2(-1,-2),
|
|||
|
new Vector2(1,-2),
|
|||
|
new Vector2(3,-2),
|
|||
|
new Vector2(5,-2),
|
|||
|
};
|
|||
|
GameManager.Instance.PoolManager.UseList.ForEach(obj =>
|
|||
|
{
|
|||
|
if ((Vector2)obj.transform.position == new Vector2(-1,2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard1 = obj.GetComponent<EnemyController>();
|
|||
|
_guard1.OnDeath += () => { _guard1 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(1, 2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard2 = obj.GetComponent<EnemyController>();
|
|||
|
_guard2.OnDeath += () => { _guard2 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(3, 2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard3 = obj.GetComponent<EnemyController>();
|
|||
|
_guard3.OnDeath += () => { _guard3 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(5, 2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard4 = obj.GetComponent<EnemyController>();
|
|||
|
_guard4.OnDeath += () => { _guard4 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(-1, -2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard5 = obj.GetComponent<EnemyController>();
|
|||
|
_guard5.OnDeath += () => { _guard5 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(1, -2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard6 = obj.GetComponent<EnemyController>();
|
|||
|
_guard6.OnDeath += () => { _guard6 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(3, -2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard7 = obj.GetComponent<EnemyController>();
|
|||
|
_guard7.OnDeath += () => { _guard7 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
else if ((Vector2)obj.transform.position == new Vector2(5, -2))
|
|||
|
{
|
|||
|
if (obj.GetComponent<EnemyController>() != null)
|
|||
|
{
|
|||
|
_guard8 = obj.GetComponent<EnemyController>();
|
|||
|
_guard8.OnDeath += () => { _guard8 = null; DetectionOpen(); };
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ܴ<EFBFBD><DCB4><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void DetectionOpen()
|
|||
|
{
|
|||
|
if (_guard1 == null && _guard2 == null && _guard3 == null && _guard4 == null && _guard5 == null && _guard6 == null && _guard7 == null && _guard8 == null)
|
|||
|
{
|
|||
|
_animator.SetTrigger("open");
|
|||
|
// <20><><EFBFBD>ɻ<EFBFBD>Կ<EFBFBD><D4BF>
|
|||
|
GameManager.Instance.PoolManager.GetResourceInFreePool(EResourceType.Item, 1).transform.position = (Vector2)transform.position + Vector2.up + Vector2.left;
|
|||
|
GameManager.Instance.PoolManager.GetResourceInFreePool(EResourceType.Item, 1).transform.position = (Vector2)transform.position + Vector2.up + Vector2.right;
|
|||
|
GameManager.Instance.PoolManager.GetResourceInFreePool(EResourceType.Item, 1).transform.position = (Vector2)transform.position + Vector2.down + Vector2.left;
|
|||
|
GameManager.Instance.PoolManager.GetResourceInFreePool(EResourceType.Item, 1).transform.position = (Vector2)transform.position + Vector2.down + Vector2.right;
|
|||
|
// <20><><EFBFBD>ɺ<EFBFBD>Կ<EFBFBD><D4BF>
|
|||
|
GameManager.Instance.PoolManager.GetResourceInFreePool(EResourceType.Item, 3).transform.position = transform.position;
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GameManager.Instance.PoolManager.RecycleResource(gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|