protected override void OnOwnerChange(PESkEntity oldOwner, PESkEntity newOwner) { base.OnOwnerChange(oldOwner, newOwner); if (oldOwner) { PeEntity entity = oldOwner.GetComponent <PeEntity>(); if (PeCreature.Instance.mainPlayerId == entity.Id) { _playerFollower = null; if (onPlayerLoseRobot != null) { onPlayerLoseRobot(); } } } if (newOwner) { PeEntity entity = newOwner.GetComponent <PeEntity>(); if (PeCreature.Instance.mainPlayerId == entity.Id) { _playerFollower = this; if (onPlayerGetRobot != null) { onPlayerGetRobot(itemObject, gameObject); } } } }
// 更新锁定目标 void UpdateLockTarget() { // 锁定目标 if (PeInput.Get(PeInput.LogicFunction.MissleTarget)) { _lockedTarget = null; _lockedTargetView = null; if (_aimEntity) { _targetToLock = _aimEntity; _targetViewToLock = _aimEntity.GetComponent <ViewCmpt>(); _timeToLock = PEVCConfig.instance.lockTargetDuration; } else { _targetToLock = null; _targetViewToLock = null; _timeToLock = -1; } } if (_timeToLock > 0f) { if (_targetToLock == _aimEntity && _targetToLock && (!_targetViewToLock || _targetViewToLock.hasView)) { _timeToLock -= Time.deltaTime; if (_timeToLock <= 0f) { _lockedTarget = _targetToLock; _lockedTargetView = _targetViewToLock; } } else { _targetToLock = null; _targetViewToLock = null; _timeToLock = -1; } } else { if ((_lockedTarget && _lockedTarget.isDead) || (_lockedTargetView && !_lockedTargetView.hasView)) { _lockedTarget = null; _lockedTargetView = null; } } }
void LateUpdate() { int showType = 0; // 0 不显示, 1 可攻击, 2 锁定中, 3 已锁定 var carrier = CarrierController.playerDriving; PESkEntity target = null; if (carrier) { if (carrier.lockedTarget) { showType = 3; target = carrier.lockedTarget; } else if (carrier.timeToLock > 0f) { showType = 2; target = carrier.targetToLock; } else if (carrier.aimEntity) { showType = 1; target = carrier.aimEntity; } } if (showType != lastShowType && !hiding) { lastShowType = showType; _background.enabled = showType == 1 || showType == 2; _progress.enabled = showType == 2 || showType == 3; _cross.enabled = true; _crossShow.enabled = showType == 0 || showType == 1; _crossLocking.enabled = showType == 2; _crossLocked.enabled = showType == 3; if (_crossShow.enabled) { _crossShow.speed = showType == 0 ? -1f : 1f; } else if (_crossLocking.enabled) { Color c = _cross.color; c.a = 1f; _cross.color = c; _cross.transform.localScale = Vector3.one; _crossLocking.normalizedTime = 0; } else if (_crossLocked.enabled) { Color c = _cross.color; c.a = 1f; _cross.color = c; _cross.transform.localEulerAngles = Vector3.zero; } } if (target) { if (target != lastTarget) { lastTarget = target; lastTrans = target.GetComponent <PeTrans>(); lastCreationController = target.GetComponent <CreationController>(); } var camera = Camera.main; Vector3 targetPosition = this.targetPosition; if (visible != (Vector3.Dot(camera.transform.forward, targetPosition - camera.transform.position) > 1f)) { visible = !visible; for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(visible); } } if (visible) { _progress.fillAmount = 1f - carrier.timeToLock / PEVCConfig.instance.lockTargetDuration; rectTrans.anchoredPosition = camera.WorldToScreenPoint(targetPosition) / rectTransParent.localScale.x; } } }