using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.StyleSheets;
using UnityEngine;
public class GameEnums
{
public enum eZergUnitType
{
NONE = -1,
DRONE,
}
}
public class App : MonoBehaviour
{
private Cocoon cocoon;
private Hatchery hatchery;
private List<IZerg> zergUnits = new List<IZerg>();
public static App Instance;
void Awake()
{
App.Instance = this;
EventDispatcher.GetInstance().AddEventListener("CreateDroneEvent", EventDispatcher.GetInstance().TestEventHandler, (sender, e) =>
{
Debug.Log("<color=red>1</color>");
var args = e as Cocoon.CocoonEventArgs;
this.zergUnits.Add(args.drone);
Debug.LogFormat("{0} / 200", this.zergUnits.Count);
});
EventDispatcher.GetInstance().AddEventListener("DroneDieEvent", EventDispatcher.GetInstance().TestEventHandler, (sender, e) =>
{
Debug.Log("<color=red>APP: DroneDieEvent</color>");
});
}
void Start()
{
//해처리 생성
var hatcheryPrefab = Resources.Load<GameObject>("hatchery");
var hatcheryGo = Instantiate(hatcheryPrefab);
hatchery = hatcheryGo.GetComponent<Hatchery>();
hatchery.Init();
}
void OnGUI()
{
if (GUILayout.Button("킬 드론", GUILayout.Width(100), GUILayout.Height(60)))
{
var dron = zergUnits[0] as Drone;
dron.Die();
}
}
void Update()
{
//마우스클릭 했을때 Ray발사
if (Input.GetMouseButtonUp(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 10);
//충돌검사
//var hit = Physics2D.Raycast(ray.origin, ray.direction, 1000);
//var arrHit = Physics2D.GetRayIntersectionAll(ray, 100);
//var hit = Physics2D.GetRayIntersection(ray, 1000);
var hit = Physics2D.Raycast(ray.origin, ray.direction, 1000);
//foreach (var hit in arrHit)
//{
// Debug.Log(hit.collider.tag);
//}
if (hit)
{
//충돌 되었다면
if (hit.collider.tag == "Larva")
{
Debug.LogFormat("{0}, {1}", hit.collider.tag, hit.collider.gameObject.GetHashCode());
this.cocoon = hatchery.GetCocoon(hit.collider.gameObject.GetHashCode());
Debug.LogFormat("cocoon: {0}", this.cocoon);
}
}
}
if (Input.GetKeyUp(KeyCode.D))
{
if (this.cocoon != null)
{
var dron = this.cocoon.CreateUnit(GameEnums.eZergUnitType.DRONE);
dron.Move(new Vector3(1,1,1));
}
}
}
}