public void run() { if (!hasInit) { return; } DoBeforeRun(); if (!_doBeforeRun) { return; } for (int i = 0; i < _bubbleAgents.Count; i++) { BubbleAgent bubbleAgent = _bubbleAgents[i]; // 如果气球已需要销毁 if (_bubbleAgents[i].IsOverTop()) { float k = Random.Range(0f, 1f); float position_x = Mathf.Lerp(0, Screen.width, k); // 清理 if (_bubbleAgents[i].bubbleType == BubbleType.Clear) { _clearBubbleAgentPool.ReleaseObj(_bubbleAgents[i] as ClearBubbleAgent); _bubbleAgents.Remove(_bubbleAgents[i]); CreateClearBubble(new Vector3(position_x, 0)); } else { _dimBubbleAgentPool.ReleaseObj(_bubbleAgents[i] as DimBubbleAgent); _bubbleAgents.Remove(_bubbleAgents[i]); CreateDimBubble(new Vector3(position_x, 0)); } } else { float minf, maxf; if (bubbleAgent.bubbleType == BubbleType.Clear) { minf = _manager.managerConfig.BackgroundClearMoveMinFactor; maxf = _manager.managerConfig.BackgroundClearMoveMaxFactor; } else { minf = _manager.managerConfig.BackgroundDimMoveMinFactor; maxf = _manager.managerConfig.BackgroundDimMoveMaxFactor; } float moveFactor = bubbleAgent.GetMoveFactor(minf, maxf); _bubbleAgents[i].Raise(moveFactor); } } }
void CreateDimBubble(Vector3 position) { BubbleAgent bubble = _dimBubbleAgentPool.GetObj(); float height = bubble.GetComponent <RectTransform>().rect.height; position = position - new Vector3(0, height, 0); bubble.Init(this, _manager, BubbleType.Dim, position); bubble.GetComponent <RectTransform>().SetAsFirstSibling(); _bubbleAgents.Add(bubble); }
void CreateClearBubble(Vector3 position) { BubbleAgent bubble = _clearBubbleAgentPool.GetObj(); float height = bubble.GetComponent <RectTransform>().rect.height; position = position - new Vector3(0, height, 0); bubble.Init(this, _manager, BubbleType.Clear, position); _bubbleAgents.Add(bubble); }