Commit af48caf8 authored by 15김민규's avatar 15김민규

몬스터 지정 위치 소환 구현. 오브젝트 풀로 동작.

parent 32786ad2
......@@ -186,7 +186,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2d73d07fdab522c4aa045e1cb6a92e8c, type: 3}
m_Name:
m_EditorClassIdentifier:
playerMaxHealth: 0
monsterID: 42
maxHealth: 0
weight: 0
--- !u!212 &212906216626823524
SpriteRenderer:
m_ObjectHideFlags: 1
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_SourcePrefab: {fileID: 0}
m_RootGameObject: {fileID: 1840123207372878}
m_IsPrefabAsset: 1
--- !u!1 &1840123207372878
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 6
m_Component:
- component: {fileID: 4193857223660800}
- component: {fileID: 114770369240601290}
m_Layer: 0
m_Name: Enemy
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4193857223660800
Transform:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1840123207372878}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &114770369240601290
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1840123207372878}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2d73d07fdab522c4aa045e1cb6a92e8c, type: 3}
m_Name:
m_EditorClassIdentifier:
......@@ -56,8 +56,9 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4563828945259690}
- component: {fileID: 114027967998875402}
m_Layer: 0
m_Name: scorpion -1
m_Name: scorpion
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -107,7 +108,7 @@ GameObject:
m_Component:
- component: {fileID: 4282728791369600}
m_Layer: 0
m_Name: enemy location
m_Name: enemy spot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -1016,6 +1017,19 @@ MonoBehaviour:
leftDoorInfo: 010101
rightDoorInfo: 010101
concept: 01010101
--- !u!114 &114027967998875402
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1295684641764716}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2d27745292051704a87740def5391766, type: 3}
m_Name:
m_EditorClassIdentifier:
enemyPrefab: {fileID: 1346522711063220, guid: e4298313f9e94c44fb057542ec7ad273,
type: 2}
--- !u!251 &251975355083752976
PlatformEffector2D:
m_ObjectHideFlags: 1
......
......@@ -767,6 +767,16 @@ Prefab:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 114768470604838176, guid: 54c1a7b414e41724197333a9e17dd49b,
type: 2}
propertyPath: enemyPrefab.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114768470604838176, guid: 54c1a7b414e41724197333a9e17dd49b,
type: 2}
propertyPath: dropItemList.Array.size
value: 16
objectReference: {fileID: 0}
- target: {fileID: 4613509870180406, guid: 54c1a7b414e41724197333a9e17dd49b, type: 2}
propertyPath: m_LocalPosition.x
value: 0
......@@ -804,6 +814,12 @@ Prefab:
propertyPath: dropTableData
value:
objectReference: {fileID: 4900000, guid: 6216895c658a2af40890a4446cc10a8c, type: 3}
- target: {fileID: 114768470604838176, guid: 54c1a7b414e41724197333a9e17dd49b,
type: 2}
propertyPath: enemyPrefab.Array.data[0]
value:
objectReference: {fileID: 1346522711063220, guid: e4298313f9e94c44fb057542ec7ad273,
type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 54c1a7b414e41724197333a9e17dd49b, type: 2}
m_IsPrefabAsset: 0
......@@ -961,11 +977,11 @@ Prefab:
m_Modifications:
- target: {fileID: 4884929250924374, guid: e6794ab8e2e4c6340a23b382e9497cbb, type: 2}
propertyPath: m_LocalPosition.x
value: -955.5
value: -398
objectReference: {fileID: 0}
- target: {fileID: 4884929250924374, guid: e6794ab8e2e4c6340a23b382e9497cbb, type: 2}
propertyPath: m_LocalPosition.y
value: -530
value: -568
objectReference: {fileID: 0}
- target: {fileID: 4884929250924374, guid: e6794ab8e2e4c6340a23b382e9497cbb, type: 2}
propertyPath: m_LocalPosition.z
......
fileFormatVersion: 2
guid: 9b5ddc79f9c10db4791cfabc9f744a67
NativeFormatImporter:
guid: 8c086f6d5e8a93542b5b6d3d56d87609
folderAsset: yes
DefaultImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,20 +5,10 @@ using Random = UnityEngine.Random;
public class Enemy : MonoBehaviour {
// data
// health
private readonly float maxHealth;
private readonly float weight;
public float playerMaxHealth; //다른 스크립트에 있는 플레이어 최대체력 가져와야함
private float currHealth;
// unit distance when get damaged
// data
// static
static readonly float unitDist = 3;
// debuff
float[] immunity_time = new float[5] { 0.0f, 3.0f, 6.0f, 6.0f, 6.0f };//면역 시간
bool[] immunity = new bool[] { false, }; //현재 에너미가 디버프 상태에 대해서 면역인지를 체크하는 변수
enum debuffCase { fire, ice, stun, blind, charm };
struct EnemyDebuffed
{
......@@ -26,11 +16,21 @@ public class Enemy : MonoBehaviour {
public float debuffTime;
}
// stat
public int monsterID;
public float maxHealth;
public float weight;
private float playerMaxHealth; //다른 스크립트에 있는 플레이어 최대체력 가져와야함
private float currHealth;
// debuff
float[] immunity_time = new float[5] { 0.0f, 3.0f, 6.0f, 6.0f, 6.0f };//면역 시간
bool[] immunity = new bool[] { false, }; //현재 에너미가 디버프 상태에 대해서 면역인지를 체크하는 변수
// enemy manager
private readonly EnemyManager enemyManager = EnemyManager.Instance;
// drop item
// private readonly EnemyManager.DropItemInfo dropItem; // [item ID, probability]
// data for ignoring collision
Vector2 lastPosition;
......@@ -44,10 +44,6 @@ public class Enemy : MonoBehaviour {
this.maxHealth = maxHealth;
this.weight = weight;
this.currHealth = maxHealth;
// EnemyManager.DropItemInfo dropItem_temp;
// this.dropItem = (enemyManager.dropTableByID.TryGetValue(id, out dropItem_temp)) ?
// dropItem_temp : new EnemyManager.DropItemInfo(-1, -1);
}
// ignore collision with player
......@@ -73,17 +69,6 @@ public class Enemy : MonoBehaviour {
public void GetDamaged(float damage) {
currHealth -= damage;
if(currHealth <= 0) {
/*
if (dropItem.id != -1)
{
float dropProb = Random.Range(0.0f, 1.0f);
if (dropProb < dropItem.prob)
{
// spawn a item that has ID
}
}
*/
Destroy(gameObject);
return;
}
......
......@@ -8,6 +8,9 @@ using UnityEngine.Assertions;
public class EnemyManager : Singleton<EnemyManager>
{
// data
// static
private static readonly int poolSize = 10;
// data of drop item
public TextAsset dropTableData;
public Dictionary<int, int[]> dropTableByID = new Dictionary<int, int[]>();
......@@ -15,6 +18,7 @@ public class EnemyManager : Singleton<EnemyManager>
// enemy prefab
public GameObject[] enemyPrefab;
public Dictionary<GameObject, GameObject[]> enemyPool = new Dictionary<GameObject, GameObject[]>();
// method
// Constructor - protect calling raw constructor
......@@ -24,12 +28,62 @@ public class EnemyManager : Singleton<EnemyManager>
private void Awake()
{
LoadDropTable(dropTableData);
createEnemyPool();
}
// Spawn Enemy to Map
public void SpawnEnemy()
{
GameObject spawnLocation = MapManager.currentRoom.roomInGame.transform.Find("enemy location").gameObject;
Transform enemySpots = MapManager.currentRoom.roomInGame.transform.Find("enemy spot");
foreach(Transform enemySpot in enemySpots)
{
GameObject enemy = enemySpot.gameObject.GetComponent<enemySpot>().enemyPrefab;
foreach(Transform location in enemySpot)
{
GameObject clone = pickFromPool(enemy);
clone.transform.position = location.position;
}
}
}
// Object Pool
private void createEnemyPool()
{
foreach(GameObject eachEnemy in enemyPrefab)
{
GameObject[] pool = new GameObject[poolSize];
for(int i = 0; i < pool.Length; i++)
{
pool[i] = Instantiate(eachEnemy);
pool[i].SetActive(false);
}
enemyPool.Add(eachEnemy, pool);
}
}
private GameObject pickFromPool(GameObject enemy)
{
GameObject[] pool = enemyPool[enemy];
foreach(GameObject obj in pool)
{
if (!obj.activeSelf)
{
obj.SetActive(true);
return obj;
}
}
int beforeExtend = pool.Length;
Array.Resize(ref pool, pool.Length + poolSize);
for(int i = beforeExtend; i < pool.Length; i++)
{
pool[i] = Instantiate(enemy);
pool[i].SetActive(false);
}
enemyPool[enemy] = pool;
pool[beforeExtend].SetActive(true);
return pool[beforeExtend];
}
// Load Dictionary
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemySpot : MonoBehaviour {
public GameObject enemyPrefab;
}
fileFormatVersion: 2
guid: 2d27745292051704a87740def5391766
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment