-
-
Save sada913/79ba2682ff18778d33e8862166182d12 to your computer and use it in GitHub Desktop.
ID検索
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class test : MonoBehaviour { | |
[SerializeField] Enemy ene; | |
[SerializeField] Enemy.Param[] e = new Enemy.Param[100]; | |
//Enemyは最初に設定したClass名 | |
void Start () { | |
int i; | |
Debug.Log("id " + ene.param[0].id); | |
Debug.Log("name " + ene.param[0].name); | |
Debug.Log("ATK " + ene.param[0].ATK); | |
Debug.Log("DEF " + ene.param[0].DEF); | |
Debug.Log("id " + ene.param[1].id); | |
Debug.Log("name " + ene.param[1].name); | |
Debug.Log("ATK " + ene.param[1].ATK); | |
Debug.Log("DEF " + ene.param[1].DEF); | |
//配列の添字はエクセルの2行目以降から何列目か | |
for(i = 0; i < ene.param.Count;i++) | |
{ | |
e[i] = ene.param[i]; | |
} | |
//Enemy.Param[]型のeにene.parm[]をそれぞれ代入 | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
/// <summary> | |
/// IDで検索する関数 | |
/// 検索アルゴリズムはテキトー | |
/// </summary> | |
/// <param name="id"></param> | |
/// <returns></returns> | |
Enemy.Param GetEnemy(int id) | |
{ | |
int i = 0; | |
int tmp_id = 0; | |
for(i = 0;i < ene.param.Count; i++) | |
{ | |
if(ene.param[i].id == id) | |
{ | |
tmp_id = i; | |
break; | |
} | |
} | |
return e[tmp_id]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment