119 lines
4.3 KiB
C#
119 lines
4.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
public class load_enemyBall_light : MonoBehaviour
|
|
{
|
|
[Header("prefabs")]
|
|
public GameObject enemyBallLightPrefab;
|
|
public Transform obj_to_put; // Changed to Transform for easier parenting
|
|
|
|
[Header("colors")]
|
|
public Color symbol_default_color = Color.white;
|
|
|
|
public Color symbol_dead_color = Color.gray;
|
|
public Color symbol_simple_color = Color.green;
|
|
public Color symbol_elite_color = Color.blue;
|
|
public Color symbol_boss_color = Color.red;
|
|
public Color symbol_legendary_color = Color.yellow;
|
|
|
|
private List<global::enemyBallLightPrefab> instantiatedBalls = new List<global::enemyBallLightPrefab>();
|
|
private int currentEnemyIndex = 0;
|
|
|
|
public void InitializeEnemyBalls(List<EnemyData_SO.EnemyType> enemyList)
|
|
{
|
|
// Clear existing balls list references
|
|
instantiatedBalls.Clear();
|
|
currentEnemyIndex = 0;
|
|
|
|
// Clean up all children in obj_to_put to ensure a fresh start
|
|
if (obj_to_put != null)
|
|
{
|
|
for (int i = obj_to_put.childCount - 1; i >= 0; i--)
|
|
{
|
|
Destroy(obj_to_put.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
|
|
if (enemyList == null || enemyList.Count == 0) return;
|
|
|
|
// Instantiate balls based on enemy count
|
|
foreach (var enemyType in enemyList)
|
|
{
|
|
if (enemyBallLightPrefab == null || obj_to_put == null) continue;
|
|
|
|
GameObject ballObj = Instantiate(enemyBallLightPrefab, obj_to_put);
|
|
global::enemyBallLightPrefab ballScript = ballObj.GetComponent<global::enemyBallLightPrefab>();
|
|
|
|
if (ballScript != null)
|
|
{
|
|
// Set color based on enemy type
|
|
if (ballScript.ballImage_img != null)
|
|
{
|
|
ballScript.ballImage_img.color = GetColorForEnemyType(enemyType);
|
|
}
|
|
|
|
// Initial cursor state: only first one active
|
|
if (ballScript.cursor_img != null)
|
|
{
|
|
ballScript.cursor_img.gameObject.SetActive(instantiatedBalls.Count == 0);
|
|
}
|
|
|
|
instantiatedBalls.Add(ballScript);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnEnemyDefeated()
|
|
{
|
|
// Check if we have valid balls list
|
|
if (instantiatedBalls.Count == 0) return;
|
|
|
|
// Ensure index is within bounds
|
|
if (currentEnemyIndex >= instantiatedBalls.Count) return;
|
|
|
|
// Change the current enemy's ball color to dead color
|
|
if (instantiatedBalls[currentEnemyIndex].ballImage_img != null)
|
|
{
|
|
instantiatedBalls[currentEnemyIndex].ballImage_img.color = symbol_dead_color;
|
|
}
|
|
|
|
// Turn off cursor for current (defeated) enemy
|
|
// UNLESS it's the last enemy, per requirements: "若最后一个敌人死亡,则最后一个敌人的cursor不消失"
|
|
if (currentEnemyIndex < instantiatedBalls.Count - 1)
|
|
{
|
|
if (instantiatedBalls[currentEnemyIndex].cursor_img != null)
|
|
{
|
|
instantiatedBalls[currentEnemyIndex].cursor_img.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
// Move to next enemy
|
|
currentEnemyIndex++;
|
|
|
|
// Turn on cursor for next enemy (if exists)
|
|
if (currentEnemyIndex < instantiatedBalls.Count)
|
|
{
|
|
if (instantiatedBalls[currentEnemyIndex].cursor_img != null)
|
|
{
|
|
instantiatedBalls[currentEnemyIndex].cursor_img.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Color GetColorForEnemyType(EnemyData_SO.EnemyType enemyType)
|
|
{
|
|
// Assuming enemy types map to standard conventions or simple integer mapping
|
|
// Adjust these mappings based on actual EnemyInfo.enemyType values if known
|
|
// For now using a switch based on common patterns or provided requirements
|
|
switch (enemyType)
|
|
{
|
|
case EnemyData_SO.EnemyType.Simple: return symbol_simple_color;
|
|
case EnemyData_SO.EnemyType.Elite: return symbol_elite_color;
|
|
case EnemyData_SO.EnemyType.Boss: return symbol_boss_color;
|
|
case EnemyData_SO.EnemyType.Legend: return symbol_legendary_color;
|
|
default: return symbol_default_color;
|
|
}
|
|
}
|
|
}
|