91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using ET;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
|
|
public class TransPointComponentAwakeSystem : AwakeSystem<TransPointComponent>
|
|
{
|
|
public override void Awake(TransPointComponent self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
|
|
|
|
public class TransPointComponentDestroySystem : DestroySystem<TransPointComponent>
|
|
{
|
|
public override void Destroy(TransPointComponent self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
|
|
public class TransPointComponent : Entity
|
|
{
|
|
public HashSet<Unit> hash;
|
|
public void Awake()
|
|
{
|
|
hash = new HashSet<Unit>();
|
|
}
|
|
public async ETTask Create(Scene zoneScene, int transIndex, int currSceneId, Vector2 pos)
|
|
{
|
|
long id = IdGenerater.Instance.GenerateId();
|
|
Unit unit = await UnitFactory.CreateTransPoint(zoneScene, id);
|
|
unit.Position = new Vector3(pos.x, pos.y, 99);
|
|
unit.AddComponent<TransPoint, int, int>(transIndex, currSceneId);
|
|
hash.Add(unit);
|
|
}
|
|
public async ETTask OnEnterTransPoint(Scene zoneScene, Collider2D collider, long Id)
|
|
{
|
|
if (collider.CompareTag("Player"))
|
|
{
|
|
if (!(collider.gameObject.GetComponent<ComponentView>().Component is UnitView unitView) ||
|
|
!(unitView.Parent is Unit unit) ||
|
|
unit.Id != zoneScene.GetComponent<GlobalVariable>().MyId ||
|
|
!unit.IsLeader)
|
|
return;
|
|
unit = zoneScene.GetComponent<UnitComponent>().MyUnit;
|
|
switch (unit.state)
|
|
{
|
|
case Unit.State.Idle:
|
|
break;
|
|
case Unit.State.Move:
|
|
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
|
moveComponent.Stop();
|
|
unit.state = Unit.State.Trans;
|
|
break;
|
|
case Unit.State.Battle:
|
|
return;
|
|
case Unit.State.Trans:
|
|
return;
|
|
}
|
|
foreach (Unit item in hash)
|
|
{
|
|
if (item.GetComponent<UnitView>().Id == Id)
|
|
{
|
|
await item.GetComponent<TransPoint>().OnEnter(zoneScene, collider);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void RemoveAll()
|
|
{
|
|
var zoneScene = this.ZoneScene();
|
|
foreach (Unit unit in hash)
|
|
{
|
|
zoneScene.GetComponent<UnitComponent>().Remove(unit);
|
|
}
|
|
hash.Clear();
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
RemoveAll();
|
|
hash = null;
|
|
}
|
|
}
|
|
} |