public void Execute(Entity entity, int index, [ReadOnly] ref MassPoint_C mass, [ReadOnly] ref Translation translation) { for (int j = 0; j < gravtiySenders.Length; j++) { var same = sendertranslations[j].Value == translation.Value; if (same.x && same.y && same.z) { continue; } double3 dir = math.normalize(sendertranslations[j].Value - translation.Value); if (double.IsNaN(dir.x) || double.IsNaN(dir.y) || double.IsNaN(dir.z)) { continue; } double distance = math.distance(sendertranslations[j].Value, translation.Value); if (distance < 1) { distance = 1; } double power = mass.Mass * gravtiySenders[j].GravityMass * G * (1f / distance); // 添加受力情况 Force_C force = new Force_C(); force.value = power * dir; force.type = ForceType.Gravity; force.time = double.MaxValue; force.from = fromEntities[j]; force.to = entity; concurrent.AddComponent(index, concurrent.CreateEntity(index), force); } }
public void Execute(Entity entity, int index, ref SimapleForceSender_C sender) { double t = deltime; if (sender.time < t) { t = sender.time; } sender.time -= t; if (sender.time <= 0) { concurrent.RemoveComponent(index, entity, typeof(SimapleForceSender_C)); concurrent.DestroyEntity(index, entity); return; } Force_C f = new Force_C(); f.from = entity; f.time = t; f.to = sender.to; f.value = sender.value; f.type = sender.type; var forceClone = concurrent.CreateEntity(index); concurrent.AddComponent(index, forceClone, f); //var senderClone = concurrent.Instantiate (index, entity); //concurrent.SetComponent (index, senderClone, sender); //concurrent.DestroyEntity (index, entity); }