public void TestSetPos(Transform pos = null) { foreach (var item in enemyState) { GameObject player = RoleInterface.GetPlayer(); GameObject enemy = item.GetGameObject(); if (pos) { enemy.transform.position = new Vector3(pos.position.x, pos.position.y, 0); } Vector3 offset = new Vector3(enemy.GetComponent <BoxCollider2D>().offset.x, enemy.GetComponent <BoxCollider2D>().offset.y, 0f); List <Vector3> path = MapInterface.FindPath(enemy.transform.position + offset, player.transform.position + offset); if (path != null) { if (item.curState._state != States.autoMove) { item.SetState(States.autoMove); } ; path.RemoveAt(0); item.curState.OnAutoMove(player.GetComponent <Animator>(), path, 0.01f); } } }
// Update is called once per frame void Update() { if (GameInput.GetMouseBtn(1)) { player = RoleInterface.GetPlayer(); offset = new Vector3(player.GetComponent <BoxCollider2D>().offset.x, player.GetComponent <BoxCollider2D>().offset.y, 0f); target.transform.position = Camera.main.ScreenToWorldPoint(GameInput.GetMousePos()); List <Vector3> path = MapInterface.FindPath(player.transform.position + offset, target.transform.position); if (path != null) { if (RoleInterface.GetPlayerState() != States.autoMove) { RoleInterface.SetPlayerState(States.autoMove); } path.RemoveAt(0); RoleInterface.OnAutoMove(player.GetComponent <Animator>(), path, 0.01f); } } /*if (GameInput.GetKeyDown(KeyCode.R)) * { * GameManager.instance.roleManager.GetEnemyManager().TestSetPos(target.transform); * } * * if (GameInput.GetKeyDown(KeyCode.F)) * { * GameManager.instance.roleManager.GetEnemyManager().TestSetPos(); * } * * if (GameInput.GetKeyDown(KeyCode.C)) * { * GameManager.instance.roleManager.GetEnemyManager().CreatEnemy("player"); * }*/ }
public bool HandleMessage(int id, string mapName, GameObject param2) { if (mapName != null) { if (LoadMap(mapName)) { if (id == MassageList.loadMap) { Transform transform = RoleInterface.GetPlayer().transform; SetPos(transform, param2); CameraInterface.SetCameraPos(transform.position); } return(false); } } return(false); }
public override void Update(Animator ani) { //curSpeed = float h = GameInput.GetAxis("Horizontal"); float v = GameInput.GetAxis("Vertical"); if (h != 0 || v != 0) { RoleInterface.SetPlayerState(States.move); } if (path.Count > 0) { ani.SetBool("IsMove", true); Vector3 dir = path[0] - (ani.gameObject.transform.position + posOffset); if (Mathf.Abs(dir.x) < offset && Mathf.Abs(dir.y) < offset) { path.RemoveAt(0); return; } speedX += dir.x; speedY += dir.y; if (Mathf.Abs(dir.x) < offset) { speedX = 0f; } else { ani.SetFloat("ValX", (dir.x < 0 ? -1 : 1) * (Mathf.Abs(speedX) > .6f ? .6f : Mathf.Abs(speedX))); } if (Mathf.Abs(dir.y) < offset) { speedY = 0f; } else { ani.SetFloat("ValY", (dir.y < 0 ? -1 : 1) * (Mathf.Abs(speedY) > .6f ? .6f : Mathf.Abs(speedY))); } if (GameInput.GetKey(KeyCode.LeftShift) && canRun) { Run(ani); } else { if (!canRun || runTime < maxRunTime) { rest(); } MovePos(new Vector3(ani.GetFloat("ValX"), ani.GetFloat("ValY"), 0), ani.gameObject); } } else { speedX = speedY = 0f; ani.SetBool("IsMove", false); RoleInterface.SetPlayerState(States.move); } }
public void Start() { camera = Camera.main; target = RoleInterface.GetPlayer().transform; light = target.transform.Find("light"); }
public RBAC_RoleController(RoleInterface roleInterface) { _roleInterface = roleInterface; }