public static void ParticleProcessor(MPWorld world, int numParticles, MPParticle *particles) { for (int i = 0; i < numParticles; ++i) { if (particles[i].hit == -1 || particles[i].hit == particles[i].hit_prev) { continue; } GameObject col = world.colliders[particles[i].hit]; RedirectForceToParent cp = col.GetComponent <RedirectForceToParent>(); if (cp) { Transform parent = col.transform.parent; if (parent) { MPUtils.CallParticleHitHandler(world, parent.gameObject, ref particles[i]); } } else { MPUtils.CallParticleHitHandler(world, col, ref particles[i]); } } }
void Start() { mpw = GetComponentInParent <MPWorld>(); if (mpw) { mpw.particleProcessor = ParticleProcessor; } }
public override void OnEnable() { m_world = GetComponent<MPWorld>(); m_max_instances = m_world.m_max_particle_num; base.OnEnable(); ResetGPUResoures(); }
public override void OnEnable() { m_world = GetComponent <MPWorld>(); m_max_instances = m_world.m_max_particle_num; base.OnEnable(); ResetGPUResoures(); }
public static void CallParticleHitHandler(MPWorld world, GameObject obj, ref MPParticle particle) { var mpcattr = obj.GetComponent <MPColliderAttribute>(); if (mpcattr) { mpcattr.particleHitHandler(world, obj, ref particle); } }
public static void CallGathereditHandler(MPWorld world, GameObject obj, ref MPHitData hit) { var mpcattr = obj.GetComponent <MPColliderAttribute>(); if (mpcattr) { mpcattr.gatheredHitHandler(world, obj, ref hit); } }
public unsafe void PropagateHit(ref MPParticle particle) { Vector3 f = MPAPI.mpGetIntermediateData(MPWorld.GetCurrentContext())->accel *MPWorld.GetCurrent().m_particle_mass; if (m_rigid3d) { m_rigid3d.AddForceAtPosition(f, particle.position); } if (m_rigid2d) { m_rigid2d.AddForceAtPosition(f, particle.position); } }
public void PropagateForce(ref MPParticleForce force) { Vector3 pos = force.position_average; Vector3 f = force.force * MPWorld.GetCurrent().m_particle_mass; if (m_rigid3d != null) { m_rigid3d.AddForceAtPosition(f, pos); } if (m_rigid2d != null) { m_rigid2d.AddForceAtPosition(f, pos); } }
public override void OnEnable() { m_world = GetComponent <MPWorld>(); m_max_instances = m_world.m_max_particle_num; m_cameras = m_camera == null ? Camera.allCameras : new Camera[] { m_camera }; if (m_cameras.Length > 0) { m_hdr = m_cameras[0].hdr; } base.OnEnable(); ResetGPUResoures(); }
public static unsafe void DefaultParticleProcessor(MPWorld world, int numParticles, MPParticle *particles) { for (int i = 0; i < numParticles; ++i) { if (particles[i].hit != -1 && particles[i].hit != particles[i].hit_prev) { GameObject col = world.colliders[particles[i].hit]; MPColliderAttribute cattr = col.GetComponent <MPColliderAttribute>(); if (cattr) { cattr.particleHitHandler(world, col, ref particles[i]); } } } }
public static unsafe void DefaultGatheredHitProcessor(MPWorld world, int numColliders, MPHitData *hits) { for (int i = 0; i < numColliders; ++i) { if (hits[i].num_hits > 0) { GameObject col = world.colliders[i]; MPColliderAttribute cattr = col.GetComponent <MPColliderAttribute>(); if (cattr) { cattr.gatheredHitHandler(world, col, ref hits[i]); } } } }
static void ImmediateUpdate() { foreach (MPWorld w in s_instances) { w.UpdateKernelParams(); } UpdateMPObjects(); foreach (MPWorld w in s_instances) { MPAPI.mpUpdate(w.GetContext(), Time.deltaTime); s_current = w; MPAPI.mpCallHandlers(w.GetContext()); MPAPI.mpClearCollidersAndForces(w.GetContext()); w.CallUpdateRoutines(); s_current = null; } }
/// <summary> /// /// </summary> /// <param name="game"></param> /// <param name="space"></param> public Projectiles ( Entity entity, World world, string explosionFX, float velocity, float radius, short damage, float impulse, float lifeTime ) : base(entity,world) { this.space = ((MPWorld)world).PhysSpace; this.world = (MPWorld)world; this.velocity = velocity; this.impulse = impulse; this.damageValue = damage; this.lifeTime = lifeTime; this.explosionFX = explosionFX; this.radius = radius; // step projectile forward compensate server latency if (world.IsServerSide) { UpdateProjectile( entity, 1.0f / world.GameServer.TargetFrameRate ); } }
public static void AddRadialSphereForce(MPWorld world, Vector3 pos, float radius, float strength) { Matrix4x4 mat = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one * radius); MPForceProperties p = new MPForceProperties(); p.shape_type = MPForceShape.Sphere; p.dir_type = MPForceDirection.Radial; p.center = pos; p.strength_near = strength; p.strength_far = 0.0f; p.attenuation_exp = 0.5f; p.range_inner = 0.0f; p.range_outer = radius; world.AddOneTimeAction(() => { MPAPI.mpAddForce(world.GetContext(), ref p, ref mat); }); }
public static void DefaultGatheredHitHandler(MPWorld world, GameObject obj, ref MPHitData hit) { float force = world.force; Vector3 vel = hit.velocity3; Rigidbody rb3d = obj.GetComponent <Rigidbody>(); if (rb3d) { rb3d.AddForceAtPosition(vel * force, hit.position3); } Rigidbody2D rb2d = obj.GetComponent <Rigidbody2D>(); if (rb2d) { rb2d.AddForceAtPosition(vel * force, hit.position3); } }
public static void DefaultParticleHitHandler(MPWorld world, GameObject obj, ref MPParticle particle) { float force = world.force; Vector3 vel = particle.velocity3; Rigidbody rb3d = obj.GetComponent <Rigidbody>(); if (rb3d) { rb3d.AddForceAtPosition(vel * force, particle.position3); } Rigidbody2D rb2d = obj.GetComponent <Rigidbody2D>(); if (rb2d) { rb2d.AddForceAtPosition(vel * force, particle.position3); } }
void Start() { trans = gameObject.GetComponent <Transform>(); world = gameObject.GetComponent <MPWorld>(); dummyMesh = new Mesh(); meshes = new GameObject("MPMeshes"); gameObject.GetComponent <MeshFilter>().mesh = dummyMesh; meshData = new MPMeshData(); children = new List <GameObject>(); dataTexture = new RenderTexture(dataTextureWidth, dataTextureHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default); dataTexture.isPowerOfTwo = false; dataTexture.filterMode = FilterMode.Point; dataTexture.Create(); if (material) { material.SetTexture("_DataTex", dataTexture); material.SetFloat("_DataTexPitch", 1.0f / dataTextureWidth); } }
public static unsafe void GatheredHitProcessor(MPWorld world, int numHits, MPHitData *hits) { for (int i = 0; i < numHits; ++i) { if (hits[i].num_hits == 0) { continue; } GameObject col = world.colliders[i]; RedirectForceToParent cp = col.GetComponent <RedirectForceToParent>(); if (cp) { Transform parent = col.transform.parent; if (parent) { MPUtils.CallGathereditHandler(world, parent.gameObject, ref hits[i]); } } else { MPUtils.CallGathereditHandler(world, col, ref hits[i]); } } }
void Start() { if (mpWorldObj != null) { world = mpWorldObj.GetComponent<MPWorld>(); emitter = emitterObj.GetComponent<MPEmitter>(); } }
public override void OnEnable() { m_world = GetComponent<MPWorld>(); m_max_instances = m_world.m_max_particle_num; m_cameras = m_camera == null ? Camera.allCameras : new Camera[] { m_camera }; if(m_cameras.Length > 0) { m_hdr = m_cameras[0].hdr; } base.OnEnable(); ResetGPUResoures(); }
/// <summary> /// /// </summary> /// <param name="attacker"></param> /// <param name="damage"></param> void FireRail ( MPWorld world, Entity attacker, int damage, float impulse, short cooldown ) { if (!attacker.ConsumeItem( Inventory.Slugs, 1 )) { return; } var view = Matrix.RotationQuaternion( attacker.Rotation ); Vector3 n,p; Entity e; var direction = view.Forward; var origin = AttackPos( attacker ); if (world.RayCastAgainstAll( origin, origin + direction * 200, out n, out p, out e, attacker )) { //world.SpawnFX( "PlayerDeathMeat", attacker.ID, p, n ); world.SpawnFX( "RailHit", attacker.ID, p, n ); world.SpawnFX( "RailMuzzle", attacker.ID, origin, n ); world.SpawnFX( "RailTrail", attacker.ID, origin, p - origin, attacker.Rotation ); world.InflictDamage( e, attacker.ID, (short)damage, view.Forward * impulse, p, DamageType.RailHit ); } else { world.SpawnFX( "RailMuzzle", attacker.ID, origin, n ); world.SpawnFX( "RailTrail", attacker.ID, origin, direction * 200, attacker.Rotation ); } attacker.SetItemCount( Inventory.WeaponCooldown, cooldown ); }
/// <summary> /// /// </summary> /// <param name="attacker"></param> /// <param name="damage"></param> void FireShot ( MPWorld world, Entity attacker, int damage, int count, float impulse, short cooldown, float spread ) { if (!attacker.ConsumeItem( Inventory.Bullets, 1 )) { return; } var view = Matrix.RotationQuaternion( attacker.Rotation ); Vector3 n,p; Entity e; var origin = AttackPos( attacker ); world.SpawnFX( "MZShotgun", attacker.ID, origin ); for (int i=0; i<count; i++) { var direction = view.Forward + rand.UniformRadialDistribution(0, spread); if (world.RayCastAgainstAll( origin, origin + direction * 400, out n, out p, out e, attacker )) { world.SpawnFX( "ShotTrail", attacker.ID, p, n ); world.InflictDamage( e, attacker.ID, (short)damage, view.Forward * impulse, p, DamageType.BulletHit ); } } attacker.SetItemCount( Inventory.WeaponCooldown, cooldown ); }
/// <summary> /// /// </summary> /// <param name="world"></param> /// <param name="attacker"></param> /// <param name="cooldown"></param> void FireRocket( MPWorld world, Entity attacker, short cooldown ) { if (!attacker.ConsumeItem( Inventory.Rockets, 1 )) { return; } var origin = AttackPos(attacker); var e = world.Spawn( "rocket", attacker.ID, origin, attacker.Rotation ); world.SpawnFX( "MZRocketLauncher", attacker.ID, origin ); attacker.SetItemCount( Inventory.WeaponCooldown, cooldown ); }
/// <summary> /// /// </summary> /// <param name="world"></param> /// <param name="attacker"></param> /// <param name="cooldown"></param> void FirePlasma( MPWorld world, Entity attacker, short cooldown ) { if (!attacker.ConsumeItem( Inventory.Cells, 1 )) { return; } var origin = AttackPos(attacker); var e = world.Spawn( "plasma", attacker.ID, origin, attacker.Rotation ); world.SpawnFX( "MZBlaster", attacker.ID, origin ); attacker.SetItemCount( Inventory.WeaponCooldown, cooldown ); }
void Start() { world = mpWorldObj.GetComponent <MPWorld>(); emitter = emitterObj.GetComponent <MPEmitter>(); }