public void SetPlayerSquad(BarracksLocation.RenderSystem system, bool shouldHide, Entity squadTarget, Entity entity) { currentType = ECurrentType.Player; squadViewSwitch.Active = false; playerViewSwitch.Active = true; if (tryGetBackend(system, entity, out var backend)) { if (shouldHide) { viewPlayerSquad.hideTime += Time.deltaTime; var prevPosition = backend.transform.position; var prevScale = backend.transform.localScale; backend.transform.position = Vector3.Lerp(prevPosition, transform.position + new Vector3 { z = 1 + prevPosition.z }, viewPlayerSquad.hideTime * 4.5f); backend.transform.localScale = Vector3.Lerp(prevScale, Vector3.zero, viewPlayerSquad.hideTime * 4.5f); return; } backend.transform.position = transform.position; backend.transform.localScale = Vector3.one; if (backend.TryGetComponent(out SortingGroup sortingGroup)) { sortingGroup.sortingOrder = 10; } } viewPlayerSquad.hideTime = 0; if (isIn) { system.EntityManager.AddComponentData(system.FollowEntity, new CurrentUnitOverview(entity)); system.FocusUnitSwitch.Active = true; system.FocusUnitSwitch.target.transform.position = transform.position + new Vector3(0, 0, 10); if (system.EntityManager.HasComponent <CurrentUnitOverview.RequestToQuit>(system.FollowEntity)) { isIn = false; WantToQuit = true; } } }
public void SetLeaderSquad(BarracksLocation.RenderSystem system, bool shouldHide, Entity squadTarget, Entity leaderSquadLeader, NativeArray <Entity> entities) { currentType = ECurrentType.LeaderSquad; squadViewSwitch.Active = true; playerViewSwitch.Active = false; if (shouldHide) { viewLeaderSquad.hideTime += Time.deltaTime; foreach (var ent in entities) { if (!tryGetBackend(system, ent, out var backend)) { continue; } var prevPosition = backend.transform.position; var prevScale = backend.transform.localScale; backend.transform.position = Vector3.Lerp(prevPosition, transform.position + new Vector3 { z = 1 + prevPosition.z }, viewLeaderSquad.hideTime * 4.5f); backend.transform.localScale = Vector3.Lerp(prevScale, Vector3.zero, viewLeaderSquad.hideTime * 4.5f); } return; } viewLeaderSquad.hideTime = 0; if (tryGetBackend(system, leaderSquadLeader, out var leaderBackend)) { leaderBackend.transform.position = transform.position; leaderBackend.transform.localScale = Vector3.one; } using var list = new NativeList <(int idx, Entity ent)>(Allocator.Temp); if (!isIn) { viewLeaderSquad.isInTime = 0; foreach (var ent in entities) { if (ent == leaderSquadLeader) { continue; } if (!tryGetBackend(system, ent, out var backend)) { continue; } var prevPosition = backend.transform.position; var prevScale = backend.transform.localScale; backend.transform.position = Vector3.Lerp(prevPosition, transform.position + new Vector3 { z = 1 + prevPosition.z }, Time.deltaTime * 10); backend.transform.localScale = Vector3.Lerp(prevScale, Vector3.zero, Time.deltaTime * 10); } } if (isIn) { viewLeaderSquad.isInTime += Time.deltaTime; foreach (var ent in entities) { if (!system.EntityManager.TryGetComponentData(ent, out UnitIndexInSquad indexInSquad)) { continue; } list.Add((indexInSquad.Value, ent)); if (!tryGetBackend(system, ent, out var backend)) { continue; } if (backend.TryGetComponent(out SortingGroup sortingGroup)) { sortingGroup.sortingOrder = 0; } if (ent == leaderSquadLeader) { continue; } backend.transform.position = transform.position + new Vector3(Mathf.Lerp(0, -(indexInSquad.Value * 1.25f) - 0.5f, viewLeaderSquad.isInTime * 5f), 0, 1 + indexInSquad.Value * 5); backend.transform.localScale = Vector3.one * Mathf.Lerp(0.1f, 1, viewLeaderSquad.isInTime * 5f); } } list.Sort(new SortTuple()); if (isIn) { var inputSystem = EventSystem.current.GetComponent <StandaloneInputModule>(); if (!viewLeaderSquad.IsViewingUnitDetails) { if (system.inputUpdate.x) { viewLeaderSquad.FocusIndex -= system.movInput.x; } if (system.enterDown) { viewLeaderSquad.IsViewingUnitDetails = true; } } if (viewLeaderSquad.FocusIndex < 0) { viewLeaderSquad.FocusIndex = list.Length - 1; } else if (viewLeaderSquad.FocusIndex >= list.Length) { viewLeaderSquad.FocusIndex = 0; } if (tryGetBackend(system, list[viewLeaderSquad.FocusIndex].ent, out var backend)) { var position = backend.transform.position; backend.transform.position = new Vector3(position.x, position.y, -2); system.FocusUnitSwitch.Active = true; system.FocusUnitSwitch.target.transform.position = backend.transform.position + new Vector3(0, 0, 1); if (backend.TryGetComponent(out SortingGroup sortingGroup)) { sortingGroup.sortingOrder = 10; } backend.transform.SetAsFirstSibling(); viewLeaderSquad.Position = backend.transform.position; } if (viewLeaderSquad.IsViewingUnitDetails && list.Length > 0) { system.EntityManager.AddComponentData(system.FollowEntity, new CurrentUnitOverview(list[viewLeaderSquad.FocusIndex].ent)); if (system.EntityManager.HasComponent <CurrentUnitOverview.RequestToQuit>(system.FollowEntity)) { viewLeaderSquad.IsViewingUnitDetails = false; system.EntityManager.RemoveComponent <CurrentUnitOverview>(system.FollowEntity); system.EntityManager.RemoveComponent <CurrentUnitOverview.RequestToQuit>(system.FollowEntity); } } else { if (Input.GetButtonDown(inputSystem.cancelButton)) { isIn = false; WantToQuit = true; } system.FocusArmySwitch.Active = true; system.FocusArmySwitch.target.transform.position = viewLeaderSquad.Position + new Vector3(0, 3, 0); } } }