private double ModelInScreenHigh(Transform payerTranform) { Vector3 playerCenter = payerTranform.GetComponent <Collider>().bounds.center; Vector3 halfYVector3 = (Vector3.up * payerTranform.GetComponent <Collider>().bounds.size.y) * 0.5f; float topValue = ShootTextCamera.WorldToScreenPoint(playerCenter + halfYVector3).y; float bottomValue = ShootTextCamera.WorldToScreenPoint(playerCenter - halfYVector3).y; return(topValue - bottomValue); }
void Update() { float deltaTime = Time.deltaTime; //操作handleShootTextGroup中移动 for (int i = 0; i < handleShootTextGroup.Count; i++) { ShootTextComponent shootTextComponent = handleShootTextGroup[i]; Vector3 shootTextCreatPosition = Vector3.zero; shootTextCreatPosition = shootTextComponent.cacheTranform.GetComponent <Collider>().bounds.center + (((Vector3.up * shootTextComponent.cacheTranform.GetComponent <Collider>().bounds.size.y) * 0.5f)); shootTextCreatPosition.x += (float)shootTextComponent.initializedHorizontalPositionOffset; shootTextCreatPosition.y += (float)shootTextComponent.initializedVerticalPositionOffset; Vector2 anchors = ShootTextCamera.WorldToViewportPoint(shootTextCreatPosition); //飘字初始锚点位置 Vector2 changeAnchoredPosition = new Vector2((float)(anchors.x + shootTextComponent.xMoveOffeset), (float)(anchors.y + shootTextComponent.yMoveOffeset)); //飘字这一帧所在位置 //设定锚点 shootTextComponent.rectTransform.anchorMax = anchors; shootTextComponent.rectTransform.anchorMin = anchors; //设置相对坐标 shootTextComponent.rectTransform.anchoredPosition = changeAnchoredPosition; if (shootTextComponent.delayMoveTime <= Time.time)//允许移动操作 { shootTextComponent.isMove = true; } //处理近大远小 double objectHigh = ModelInScreenHigh(shootTextComponent.cacheTranform); double scale = (objectHigh / 100) * shootTextScaleFactor; shootTextComponent.ChangeScale(scale); double xMoveOffeset = horizontalMoveSpeed * deltaTime * objectHigh; double yMoveOffeset = verticalMoveSpeed * deltaTime * objectHigh; if (shootTextComponent.isMove == true)//处理位置信息 { switch (shootTextComponent.moveType) { case TextMoveType.None: break; case TextMoveType.Up: { shootTextComponent.yMoveOffeset += yMoveOffeset; } break; case TextMoveType.Down: { shootTextComponent.yMoveOffeset -= yMoveOffeset; } break; case TextMoveType.Left: { shootTextComponent.xMoveOffeset -= xMoveOffeset; } break; case TextMoveType.Right: { shootTextComponent.xMoveOffeset += xMoveOffeset; } break; case TextMoveType.LeftUp: { shootTextComponent.xMoveOffeset -= xMoveOffeset; shootTextComponent.yMoveOffeset += yMoveOffeset; } break; case TextMoveType.LeftDown: { shootTextComponent.xMoveOffeset -= xMoveOffeset; shootTextComponent.yMoveOffeset -= yMoveOffeset; } break; case TextMoveType.RightUp: { shootTextComponent.xMoveOffeset += xMoveOffeset; shootTextComponent.yMoveOffeset += yMoveOffeset; } break; case TextMoveType.RightDown: { shootTextComponent.xMoveOffeset += xMoveOffeset; shootTextComponent.yMoveOffeset -= yMoveOffeset; } break; case TextMoveType.LeftParabola: { float parabola = shootParabolaCure.Evaluate((float)(shootTextComponent.fadeCurveTime / moveLifeTime)); shootTextComponent.xMoveOffeset -= xMoveOffeset; shootTextComponent.yMoveOffeset += yMoveOffeset + parabola; } break; case TextMoveType.RightParabola: { float parabola = shootParabolaCure.Evaluate((float)(shootTextComponent.fadeCurveTime / moveLifeTime)); shootTextComponent.xMoveOffeset += xMoveOffeset; shootTextComponent.yMoveOffeset += yMoveOffeset + parabola; } break; default: break; } } //处理渐隐 if (shootTextComponent.isMove == true) { shootTextComponent.fadeCurveTime += deltaTime; float alpha = shootTextCure.Evaluate((float)(shootTextComponent.fadeCurveTime)); shootTextComponent.ChangeAlpha(alpha); } else { shootTextComponent.ChangeAlpha(1); } //处理删除对应的飘字 if (shootTextComponent.isMove == true && shootTextComponent.canvasGroup.alpha <= 0) { waitDestoryGroup.Add(shootTextComponent); } } //是否加速 isAccelerate = waitShootTextGroup.Count >= accelerateThresholdValue ? true : false; if (isAccelerate) { updateCreatTime = updateCreatTime / accelerateFactor; } else { updateCreatTime = updateCreatDefualtTime; } //创建 if ((updateCreatTempTime -= deltaTime) <= 0) { updateCreatTempTime = updateCreatTime; if (waitShootTextGroup.Count > 0) { GameObject tempObj = InstanceShootText(waitShootTextGroup.Dequeue()); tempObj.transform.SetParent(ShootTextCanvas, false); } } //删除已经完全消失飘字 for (int i = 0; i < waitDestoryGroup.Count; i++) { handleShootTextGroup.Remove(waitDestoryGroup[i]); Destroy(waitDestoryGroup[i].gameObject); } waitDestoryGroup.Clear(); }