110 lines
3.5 KiB
C#
110 lines
3.5 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public class LogicBattleFieldStateExplore : LogicBattleFieldState
|
|
{
|
|
float changeCamDist = 20;
|
|
bool switchCam = false;
|
|
|
|
public static LogicBattleFieldStateExplore Creator(LogicBattleField field)
|
|
{
|
|
return new LogicBattleFieldStateExplore(field);
|
|
}
|
|
|
|
public LogicBattleFieldStateExplore(LogicBattleField field)
|
|
: base (field, LogicBattleFieldStateType.Explore)
|
|
{
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
mField.RemoveMonsters();
|
|
mField.SetReadyPointForExplore();
|
|
var mainRoleFighter = mField.Battle.FighterMgr.GetMainRole();
|
|
BattleCamera.Instance.SetExploreCameraTarget(mainRoleFighter);
|
|
mField.IsExploreMode = true;
|
|
mField.Battle.GetReadyForTransfer();
|
|
mField.Battle.GoToExploreTransferPoint();
|
|
EnterExploreMode();
|
|
}
|
|
|
|
public override void OnLeave()
|
|
{
|
|
ExitExploreMode();
|
|
}
|
|
|
|
public override void Update(float deltaTime)
|
|
{
|
|
if (mField.Battle.IsExploreMode == false)
|
|
{
|
|
ChangeState(LogicBattleFieldStateType.End);
|
|
return;
|
|
}
|
|
mField.Battle.FighterMgr.FixedUpdate(deltaTime);
|
|
mField.Battle.BattleScene.UpdateSceneTree(mField.TeamFighters[0].Position);
|
|
}
|
|
|
|
public override void OnDataChanged()
|
|
{
|
|
|
|
}
|
|
|
|
private void EnterExploreMode()
|
|
{
|
|
EventMgr.AddEventListener<Vector2>(ECoreEventType.EID_JOYSTICK_DIRECTION, OnJoystickDirection);
|
|
for (int i = 0; i < mField.Battle.FighterMgr.TeamPetFighters.Count; i++)
|
|
{
|
|
var petFighter = mField.Battle.FighterMgr.TeamPetFighters[i];
|
|
petFighter.Ctrl.IsVisible = false;
|
|
}
|
|
}
|
|
|
|
private void ExitExploreMode()
|
|
{
|
|
EventMgr.RemoveEventListener<Vector2>(ECoreEventType.EID_JOYSTICK_DIRECTION, OnJoystickDirection);
|
|
for (int i = 0; i < mField.Battle.FighterMgr.TeamPetFighters.Count; i++)
|
|
{
|
|
var petFighter = mField.Battle.FighterMgr.TeamPetFighters[i];
|
|
petFighter.Ctrl.IsVisible = true;
|
|
}
|
|
|
|
mField.Result = FightingResult.Peace;
|
|
}
|
|
|
|
private Vector2 _lastJoystickDirection = Vector2.zero;
|
|
private void OnJoystickDirection(CoreEvent<Vector2> eventData)
|
|
{
|
|
var joystaticDirection = eventData.Data;
|
|
if (joystaticDirection == Vector2.zero && _lastJoystickDirection == joystaticDirection)
|
|
{
|
|
return;
|
|
}
|
|
_lastJoystickDirection = joystaticDirection;
|
|
var mainRoleFighter = mField.Battle.FighterMgr.GetMainRole();
|
|
Vector3 moveDirection = Vector3.forward * joystaticDirection.y + Vector3.right * joystaticDirection.x;
|
|
mainRoleFighter.MoveInDirection(moveDirection);
|
|
|
|
List<Fighter> followHeros = new();
|
|
List<Fighter> heros = mField.Battle.FighterMgr.TeamHeroFighters;
|
|
for (int idx = 0; idx < heros.Count; idx++)
|
|
{
|
|
var hero = heros[idx];
|
|
if (hero.IsMainRole == false)
|
|
{
|
|
followHeros.Add(hero);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < followHeros.Count; i++)
|
|
{
|
|
var hero = followHeros[i];
|
|
var followDistance = (i + 1) * 1.0f;
|
|
var desiredPosition = mainRoleFighter.Ctrl.transform.position +
|
|
mainRoleFighter.Ctrl.transform.rotation * new Vector3(0, 0, -followDistance);
|
|
var followDirection = desiredPosition - hero.Position;
|
|
hero.FollowInDirection(followDirection);
|
|
}
|
|
}
|
|
}
|