| | |
| | | using UnityEngine.UI; |
| | | using DG.Tweening; |
| | | using System.Linq; |
| | | using System; |
| | | |
| | | //工人是固定的跟随模式,监工是随机分配的,场上的监工数量会比实际更多 |
| | | //分配监工 |
| | |
| | | |
| | | void OnEnable() |
| | | { |
| | | GoldRushManager.Instance.GoldRushEvent += GoldRushEvent; |
| | | GoldRushManager.Instance.PathEvent += PathEvent; |
| | | GoldRushManager.Instance.OnGoldRushCampEvent += OnGoldRushCampEvent; |
| | | GoldRushManager.Instance.OnGoldRushInfoEvent += Display; |
| | |
| | | |
| | | void OnDisable() |
| | | { |
| | | GoldRushManager.Instance.GoldRushEvent -= GoldRushEvent; |
| | | GoldRushManager.Instance.PathEvent -= PathEvent; |
| | | GoldRushManager.Instance.OnGoldRushCampEvent -= OnGoldRushCampEvent; |
| | | GoldRushManager.Instance.OnGoldRushInfoEvent -= Display; |
| | |
| | | if (realCount > leaderCount) |
| | | { |
| | | //分配监工 |
| | | GoldRushManager.Instance.NotifyGoldRushEvent(campID, 0, realCount - leaderCount); |
| | | GoldRushEvent(campID, 0, realCount - leaderCount); |
| | | } |
| | | else if (realCount < leaderCount) |
| | | { |
| | | //召回监工 |
| | | GoldRushManager.Instance.NotifyGoldRushEvent(campID, 1, leaderCount - realCount); |
| | | GoldRushEvent(campID, 1, leaderCount - realCount); |
| | | } |
| | | leaderCount = realCount; |
| | | Display(); |
| | |
| | | |
| | | |
| | | |
| | | |
| | | void AssignLeader(int addCount) |
| | | { |
| | | //不同营地之间错位出发 |
| | | float addTime = 0; |
| | | var curTime = Time.time; |
| | | if (curTime - GoldRushManager.Instance.lastAssignWorkTime < 0.2f) |
| | | { |
| | | addTime = 0.2f - (curTime - GoldRushManager.Instance.lastAssignWorkTime); |
| | | } |
| | | |
| | | if (addTime != 0) |
| | | { |
| | | GoldRushManager.Instance.lastAssignWorkTime += 0.2f; |
| | | } |
| | | else |
| | | { |
| | | GoldRushManager.Instance.lastAssignWorkTime = curTime; |
| | | } |
| | | |
| | | |
| | | //分配的时候加新的监工 |
| | | for (int i = 0; i < addCount; i++) |
| | | { |
| | | float waitTime = i * 0.6f; |
| | | float waitTime = i * 0.3f + addTime; |
| | | var newLeader = RequestLeader(); |
| | | workingLeaderList.Add(newLeader); |
| | | newLeader.Init(leaderPathPointArr, waitTime, campID, i, false, (bool value) => |
| | | { |
| | | //是否返程 |
| | | if (!value) |
| | | { |
| | | workingLeaderList.Remove(newLeader); |
| | | ReturnLeader(newLeader); |
| | | } |
| | | else |
| | | { |
| | | //半路返回的监工 |
| | | callBackLeaderList.Add(newLeader); |
| | | ReturnLeader(newLeader); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | GoldRushLeader RequestLeader() |
| | |
| | | //半路召回的,拉货回来的 |
| | | void CallBackLeader(int callBackCount) |
| | | { |
| | | //不同营地之间错位出发 |
| | | float addTime = 0; |
| | | var curTime = Time.time; |
| | | if (curTime - GoldRushManager.Instance.lastCallBackTime < 0.2f) |
| | | { |
| | | addTime = 0.2f - (curTime - GoldRushManager.Instance.lastCallBackTime); |
| | | } |
| | | |
| | | if (addTime != 0) |
| | | { |
| | | GoldRushManager.Instance.lastCallBackTime += 0.2f; |
| | | } |
| | | else |
| | | { |
| | | GoldRushManager.Instance.lastCallBackTime = curTime; |
| | | } |
| | | |
| | | |
| | | bool followBack = false; |
| | | |
| | | bool forcrCallBack = false; |
| | | if (GoldRushManager.Instance.forceStopCampID == campID) |
| | | { |
| | | forcrCallBack = true; |
| | | GoldRushManager.Instance.forceStopCampID = 0; |
| | | } |
| | | |
| | | //从workingLeaderList 中取出最后面调回的监工,不够的新建 |
| | | for (int i = 0; i < callBackCount; i++) |
| | | { |
| | |
| | | callBackLeaderList.Add(leader); |
| | | workingLeaderList.Remove(leader); |
| | | leader.StartLeaderMove(true); |
| | | leader.forcrCallBack = forcrCallBack; |
| | | leader.OnComplete = (bool value) => |
| | | { |
| | | callBackLeaderList.Remove(leader); |
| | | ReturnLeader(leader); |
| | | |
| | | }; |
| | | if (workingLeaderList.Count == 0 && workState == 1) |
| | | { |
| | | followBack = true; |
| | |
| | | } |
| | | else |
| | | { |
| | | //需要显示货物 |
| | | float waitTime = i * 0.6f; |
| | | float waitTime = i * 0.6f + addTime; |
| | | var newLeader = RequestLeader(); |
| | | callBackLeaderList.Add(newLeader); |
| | | newLeader.Init(leaderPathPointArr, waitTime, campID, i, true, (bool value) => |
| | | int index = Math.Max(leaderCount - i - 1, 0); //从后往前召回 |
| | | newLeader.Init(leaderPathPointArr, waitTime, campID, index, true, (bool value) => |
| | | { |
| | | if (value) |
| | | { |
| | | //返回的监工,需要显示货物 |
| | | callBackLeaderList.Add(newLeader); |
| | | //返回的监工 |
| | | callBackLeaderList.Remove(newLeader); |
| | | ReturnLeader(newLeader); |
| | | } |
| | | }); |
| | | newLeader.forcrCallBack = forcrCallBack; |
| | | |
| | | if (workState == -1) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (followBack&& GoldRushManager.Instance.GetCampWorkerCnt(campID) == 0) |
| | | if (followBack && GoldRushManager.Instance.GetCampWorkerCnt(campID) == 0) |
| | | { |
| | | StartMove(true); |
| | | workState = 2; |
| | | } |
| | | |
| | | } |
| | | |
| | | void ClickTent() |