public void Load(XTransform param) { GameObject go = ZTEffect.Instance.LoadEffectById(Id); if (go == null || mOwner == null || mOwner.CacheTransform == null) { this.State = EEffectState.Error; return; } this.Obj = go; this.CacheTransform = go.transform; switch (mData.Bind) { case EEffectBind.World: { CacheTransform.position = mData.Offset; CacheTransform.eulerAngles = mData.Euler; } break; case EEffectBind.Trans: { if (mData.Parent == null) { CacheTransform.position = mData.Offset; CacheTransform.eulerAngles = mData.Euler; } else { mData.SetParent = true; CacheTransform.position = mData.Parent.position + mData.Offset; CacheTransform.eulerAngles = mData.Parent.eulerAngles + mData.Euler; } } break; case EEffectBind.OwnBody: { CacheTransform.eulerAngles = mOwner.CacheTransform.localEulerAngles + mData.Euler; CacheTransform.position = mOwner.GetBind(EActorBindPos.Body, mData.Offset); } break; case EEffectBind.OwnHead: { CacheTransform.eulerAngles = mOwner.CacheTransform.localEulerAngles + mData.Euler; CacheTransform.position = mOwner.GetBind(EActorBindPos.Head, mData.Offset); } break; case EEffectBind.OwnFoot: { CacheTransform.eulerAngles = mOwner.CacheTransform.localEulerAngles + mData.Euler; CacheTransform.position = mOwner.GetBind(EActorBindPos.Foot, mData.Offset); } break; case EEffectBind.OwnHand: { mData.SetParent = true; Transform[] hands = mOwner.GetHands(); if (hands != null && hands[0] != null) { mData.Parent = hands[0]; CacheTransform.position = mData.Parent.position + mData.Offset; CacheTransform.eulerAngles = mData.Parent.eulerAngles + mData.Euler; } else { CacheTransform.position = mData.Offset; CacheTransform.eulerAngles = mData.Euler; } } break; case EEffectBind.TarBody: { Actor actor = mTarget == null ? mOwner : mTarget; CacheTransform.position = actor.GetBind(EActorBindPos.Head, mData.Offset); } break; case EEffectBind.TarFoot: { Actor actor = mTarget == null ? mOwner : mTarget; CacheTransform.position = actor.GetBind(EActorBindPos.Foot, mData.Offset); } break; case EEffectBind.TarHead: { Actor actor = mTarget == null ? mOwner : mTarget; CacheTransform.position = actor.GetBind(EActorBindPos.Head, mData.Offset); } break; case EEffectBind.OwnVTar: { if (mOwner != null && mTarget != null) { Vector3 pos1 = mTarget.GetBind(EActorBindPos.Body, Vector3.zero); Vector3 pos2 = mOwner.GetBind(EActorBindPos.Body, Vector3.zero); CacheTransform.position = (pos1 - pos2) * 0.5f + pos2; } else { CacheTransform.position = mOwner.GetBind(EActorBindPos.Body, Vector3.zero) + mOwner.Dir * 10; } } break; } if (mData.SetParent && mData.Parent != null) { CacheTransform.parent = mData.Parent; } mStartPos = CacheTransform.position; ZTAudio.Instance.PlayEffectAudio(mData.Sound); this.State = EEffectState.Update; }
void TickRemote() { XTransform xform = new XTransform(); xform.Pos = helper.CurrentDeadReckonedValue; xform.Rot = helper.CurrentDeadReckonedRotation; float simTimeDelta = Time.deltaTime; float simTime = Time.time; if (helper.IsUpdated()) { //helper.SetLastTranslationUpdatedTime(simTime); helper.SetTranslationElapsedTimeSinceUpdate(0.0f); //helper.SetLastRotationUpdatedTime(simTime - simTimeDelta); helper.SetRotationElapsedTimeSinceUpdate(0.0f); helper.RotationResolved = false; } //We want to do this every time. make sure it's greater than 0 in case of time being set. float transElapsedTime = helper.GetTranslationElapsedTimeSinceUpdate() + simTimeDelta; if (transElapsedTime < 0.0) { transElapsedTime = 0.0f; } helper.SetTranslationElapsedTimeSinceUpdate(transElapsedTime); float rotElapsedTime = helper.GetRotationElapsedTimeSinceUpdate() + simTimeDelta; if (rotElapsedTime < 0.0) { rotElapsedTime = 0.0f; } helper.SetRotationElapsedTimeSinceUpdate(rotElapsedTime); // Actual dead reckoning code moved into the helper.. // BaseGroundClamper::GroundClampRangeType* groundClampingType = &BaseGroundClamper::GroundClampRangeType::NONE; bool transformChanged = helper.DoDR(ref xform); // if (helper.GetDeadReckoningAlgorithm() != DeadReckoningAlgorithm::NONE) // { // // Only ground clamp and move remote objects. // if (helper.GetEffectiveUpdateMode(gameActor.IsRemote()) // == DeadReckoningHelper::UpdateMode::CALCULATE_AND_MOVE_ACTOR) // { // osg::Vec3 velocity(helper.GetCurrentInstantVelocity()); // helper.GetLastKnownVelocity() + helper.GetLastKnownAcceleration() * simTimeDelta ); // // // Call the ground clamper for the current object. The ground clamper should // // be smart enough to know what to do with the supplied values. // mGroundClamper->ClampToGround(*groundClampingType, tickMessage.GetSimulationTime(), // xform, gameActor.GetGameActorProxy(), // helper.GetGroundClampingData(), transformChanged, velocity); // } // } if (transformChanged) { if (bUsePhys) { Vector3 deltaMove = xform.Pos - rigidbody.position; float t = Mathf.Max(Time.deltaTime, 0.01f); rigidbody.velocity = deltaMove / t; rigidbody.MoveRotation(xform.Rot); m_Recorder.SetPath(xform.Pos); } else { transform.position = xform.Pos; if (bClampToGround) { ClampToGround(); } transform.rotation = xform.Rot; m_Recorder.SetPath(transform.position); } } else { m_Recorder.SetPath(transform.position); } // Clear the updated flag. helper.ClearUpdated(); }