private void MovementQuery(Entity entity,
                                   UnitTransform unit,
                                   ref MovementData movement,
                                   ref BaseUnitStatus.Component status)
        {
            if (status.State != UnitState.Alive)
            {
                return;
            }

            if (UnitUtils.IsAutomaticallyMoving(status.Type) == false)
            {
                return;
            }

            // check ground
            if (unit == null || unit.GetGrounded(out var hitInfo) == false)
            {
                return;
            }

            var rigidbody = EntityManager.GetComponentObject <Rigidbody>(entity);

            if (movement.MoveSpeed == 0.0f &&
                movement.RotSpeed == 0.0f)
            {
                return;
            }

            var trans = rigidbody.transform;

            var uVec    = trans.forward * movement.MoveSpeed;
            var moveVec = uVec * Time.fixedDeltaTime;

            //rigidbody.velocity = uVec;
            var pos = rigidbody.position;

            rigidbody.MovePosition(pos + moveVec);

            if (movement.RotSpeed != 0.0f)
            {
                trans.Rotate(trans.up, movement.RotSpeed * Time.fixedDeltaTime);
            }
        }
        private void Query(ref BaseUnitStatus.Component status, Rigidbody rigidbody, UnitTransform unit)
        {
#if true
            if (UnitUtils.IsBuilding(status.Type) == false)
            {
                return;
            }

            if (rigidbody == null ||
                rigidbody.isKinematic)
            {
                return;
            }

            if (unit != null && unit.GetGrounded())
            {
                rigidbody.isKinematic = true;
            }
#endif
        }
        private void SyncTroop(Dictionary <EntityId, SimpleUnit> simpleUnits, Transform trans)
        {
            UnityEngine.Profiling.Profiler.BeginSample("SyncTroop");
            var pos = trans.position;
            var rot = trans.rotation;

            var posDiff = MovementDictionary.SleepPosDiff;
            var rotDiff = MovementDictionary.SleepRotDiff;

            foreach (var kvp in simpleUnits)
            {
                UnitTransform unit = null;
                if (TryGetComponentObject(kvp.Key, out unit) == false)
                {
                    continue;
                }

                var t      = unit.transform.parent;
                var buffer = unit.BufferVector.magnitude;

                var p      = GetGrounded(pos + rot * kvp.Value.RelativePos.ToUnityVector(), buffer);
                var p_diff = p - t.position;
                if (p_diff.sqrMagnitude >= posDiff * posDiff)
                {
                    t.position = NavMeshUtils.GetNavPoint(t.position, p, unit.Bounds.size.magnitude, WalkableNavArea);
                }

                var r      = kvp.Value.RelativeRot.ToUnityQuaternion() * rot;
                var r_diff = Vector3.Angle(t.forward, r * Vector3.forward);
                if (r_diff > rotDiff)
                {
                    t.rotation = r;
                }
            }

            UnityEngine.Profiling.Profiler.EndSample();
        }
示例#4
0
 void Attack(UnitTransform unit, float time, float angleSpeed, in Vector3 epos, in SpatialEntityId entityId, ref BaseUnitPosture.Component posture, ref GunComponent.Component gun, out bool updPosture, out bool updGuns)