public ExploderSettings(ExploderObject exploder) { Position = ExploderUtils.GetCentroid(exploder.gameObject); DontUseTag = exploder.DontUseTag; Radius = exploder.Radius; UseCubeRadius = exploder.UseCubeRadius; CubeRadius = exploder.CubeRadius; ForceVector = exploder.ForceVector; UseForceVector = exploder.UseForceVector; Force = exploder.Force; FrameBudget = exploder.FrameBudget; TargetFragments = exploder.TargetFragments; DeactivateOptions = exploder.DeactivateOptions; DeactivateTimeout = exploder.DeactivateTimeout; MeshColliders = exploder.MeshColliders; ExplodeSelf = exploder.ExplodeSelf; HideSelf = exploder.HideSelf; DestroyOriginalObject = exploder.DestroyOriginalObject; ExplodeFragments = exploder.ExplodeFragments; SplitMeshIslands = exploder.SplitMeshIslands; FragmentOptions = exploder.FragmentOptions.Clone(); SfxOptions = exploder.SFXOptions.Clone(); Use2DCollision = exploder.Use2DCollision; FragmentPoolSize = exploder.FragmentPoolSize; FragmentPrefab = exploder.FragmentPrefab; FadeoutOptions = exploder.FadeoutOptions; SFXOptions = exploder.SFXOptions; DisableRadiusScan = exploder.DisableRadiusScan; UniformFragmentDistribution = exploder.UniformFragmentDistribution; AllowOpenMeshCutting = exploder.AllowOpenMeshCutting; }
void OnExplosion(float timeMS, ExploderObject.ExplosionState state) { if (state == ExploderObject.ExplosionState.ExplosionFinished) { Finish(); } }
public ExploderParams(ExploderObject exploder) { Position = ExploderUtils.GetCentroid(exploder.gameObject); DontUseTag = exploder.DontUseTag; Radius = exploder.Radius; UseCubeRadius = exploder.UseCubeRadius; CubeRadius = exploder.CubeRadius; ForceVector = exploder.ForceVector; UseForceVector = exploder.UseForceVector; Force = exploder.Force; FrameBudget = exploder.FrameBudget; TargetFragments = exploder.TargetFragments; ExplodeSelf = exploder.ExplodeSelf; HideSelf = exploder.HideSelf; ThreadOptions = exploder.ThreadOption; DestroyOriginalObject = exploder.DestroyOriginalObject; SplitMeshIslands = exploder.SplitMeshIslands; FragmentOptions = exploder.FragmentOptions.Clone(); FragmentDeactivation = exploder.FragmentDeactivation.Clone(); FragmentSFX = exploder.FragmentSFX.Clone(); Use2DCollision = exploder.Use2DCollision; FragmentPoolSize = exploder.FragmentPoolSize; DisableRadiusScan = exploder.DisableRadiusScan; UniformFragmentDistribution = exploder.UniformFragmentDistribution; DisableTriangulation = exploder.DisableTriangulation; ExploderGameObject = exploder.gameObject; CuttingStyle = exploder.CuttingStyle; }
public ExploderParams(ExploderObject exploder) { this.Position = ExploderUtils.GetCentroid(((Component)exploder).get_gameObject()); this.DontUseTag = exploder.DontUseTag; this.Radius = exploder.Radius; this.UseCubeRadius = exploder.UseCubeRadius; this.CubeRadius = exploder.CubeRadius; this.ForceVector = exploder.ForceVector; this.UseForceVector = exploder.UseForceVector; this.Force = exploder.Force; this.FrameBudget = exploder.FrameBudget; this.TargetFragments = exploder.TargetFragments; this.ExplodeSelf = exploder.ExplodeSelf; this.HideSelf = exploder.HideSelf; this.ThreadOptions = exploder.ThreadOption; this.DestroyOriginalObject = exploder.DestroyOriginalObject; this.SplitMeshIslands = exploder.SplitMeshIslands; this.FragmentOptions = exploder.FragmentOptions.Clone(); this.FragmentDeactivation = exploder.FragmentDeactivation.Clone(); this.FragmentSFX = exploder.FragmentSFX.Clone(); this.Use2DCollision = exploder.Use2DCollision; this.FragmentPoolSize = exploder.FragmentPoolSize; this.DisableRadiusScan = exploder.DisableRadiusScan; this.UniformFragmentDistribution = exploder.UniformFragmentDistribution; this.DisableTriangulation = exploder.DisableTriangulation; this.ExploderGameObject = ((Component)exploder).get_gameObject(); this.CuttingStyle = exploder.CuttingStyle; }
public void Explode(ExploderObject.OnExplosion callback) { var settings = new ExploderSettings { Position = ExploderUtils.GetCentroid(exploder.gameObject), DontUseTag = exploder.DontUseTag, Radius = exploder.Radius, UseCubeRadius = exploder.UseCubeRadius, CubeRadius = exploder.CubeRadius, ForceVector = exploder.ForceVector, UseForceVector = exploder.UseForceVector, Force = exploder.Force, FrameBudget = exploder.FrameBudget, TargetFragments = exploder.TargetFragments, DeactivateOptions = exploder.DeactivateOptions, DeactivateTimeout = exploder.DeactivateTimeout, MeshColliders = exploder.MeshColliders, ExplodeSelf = exploder.ExplodeSelf, HideSelf = exploder.HideSelf, DestroyOriginalObject = exploder.DestroyOriginalObject, ExplodeFragments = exploder.ExplodeFragments, SplitMeshIslands = exploder.SplitMeshIslands, FragmentOptions = exploder.FragmentOptions.Clone(), SfxOptions = exploder.SFXOptions.Clone(), Callback = callback, processing = false, }; queue.Enqueue(settings); ProcessQueue(); }
public void Enqueue( ExploderObject exploderObject, ExploderObject.OnExplosion callback, bool crack, params GameObject[] obj) { this.queue.Enqueue(exploderObject, callback, crack, obj); }
public void Initialize(ExploderObject exploder) { if (initialized) { return; } initialized = true; parameters = new ExploderParams(exploder); // init pool FragmentPool.Instance.Reset(parameters); frameWatch = new Stopwatch(); explosionWatch = new Stopwatch(); crackManager = new CrackManager(this); bakeSkinManager = new BakeSkinManager(this); // // init queue // queue = new ExploderQueue(this); // // init tasks // tasks = new ExploderTask[(int)TaskType.TaskMax]; tasks[(int)TaskType.Preprocess] = new Preprocess(this); #if DISABLE_MULTITHREADING tasks[(int)TaskType.ProcessCutter] = new CutterST(this); #else if (parameters.ThreadOptions == ExploderObject.ThreadOptions.Disabled) { tasks[(int)TaskType.ProcessCutter] = new CutterST(this); } else { tasks[(int)TaskType.ProcessCutter] = new CutterMT(this); } #endif tasks[(int)TaskType.IsolateMeshIslands] = new IsolateMeshIslands(this); tasks[(int)TaskType.PostprocessExplode] = new PostprocessExplode(this); tasks[(int)TaskType.PostprocessCrack] = new PostprocessCrack(this); PreAllocateBuffers(); audioSource = gameObject.AddComponent <AudioSource>(); }
public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, bool crack, params GameObject[] target) { var settings = new ExploderParams(exploderObject) { Callback = callback, Targets = target, Crack = crack, processing = false }; queue.Enqueue(settings); ProcessQueue(); }
public void Enqueue( ExploderObject exploderObject, ExploderObject.OnExplosion callback, bool crack, params GameObject[] target) { this.queue.Enqueue(new ExploderParams(exploderObject) { Callback = callback, Targets = target, Crack = crack, processing = false }); this.ProcessQueue(); }
// Use this for initialization void Awake() { notePostion = false; isExploded = false; revertEvent = false; framePos = new Vector3[5]; originPos = this.transform.position; originRotation = this.transform.rotation; mRigidbody = this.GetComponent <Rigidbody>(); exploderObj = GameObject.FindObjectOfType <Exploder.ExploderObject>() as Exploder.ExploderObject; revertHandType = Fingo.HandType.Invalid; canRevertClips = false; revertTime = 0.0f; }
public void EnqueuePartialExplosion(ExploderObject exploderObject, ExploderObject.OnExplosion callback, GameObject target, Vector3 shotDir, Vector3 hitPosition, float bulletSize) { var settings = new ExploderParams(exploderObject) { Callback = callback, Target = target, HitPosition = hitPosition, BulletSize = bulletSize, PartialExplosion = true, ShotDir = shotDir, processing = false, }; queue.Enqueue(settings); ProcessQueue(); }
/// <summary> /// exploder callback /// </summary> private void OnExplosion(float time, ExploderObject.ExplosionState state) { // explosion is finished if (state == ExploderObject.ExplosionState.ExplosionFinished) { //! //! HERE IS THE LIST OF ACTIVE FRAGMENTS //! // var list = FragmentPool.Instance.GetActiveFragments(); // NOTE: // if you run another explosion afterwards and you dont clear or deactivate fragmets in fragment pool // you might get some of the fragments from old explosion as well // to deactivate fragments you can call FragmentPool.Instance.DeactivateFragments() } }
public override void BeginState(IAiProcess currentState) { m_ownerUnit.m_ai.m_dead = true; m_ownerUnit.Die(); m_ownerUnit.m_unitGagebar.gameObject.SetActive(false); m_time = 0; Exploder.ExploderObject l_ExploderObject = m_ownerUnit.GetComponent <Exploder.ExploderObject> (); if (l_ExploderObject != null) { l_ExploderObject.Explode(); } if (m_UnityActionDeadStart != null && m_UnityActionDeadStart.Target != null) { m_UnityActionDeadStart.Invoke(); } }
public void Initialize(ExploderObject exploder) { if (this.initialized) { return; } this.initialized = true; this.parameters = new ExploderParams(exploder); FragmentPool.Instance.Reset(this.parameters); this.frameWatch = new Stopwatch(); this.explosionWatch = new Stopwatch(); this.crackManager = new CrackManager(this); this.bakeSkinManager = new BakeSkinManager(this); this.queue = new ExploderQueue(this); this.tasks = new ExploderTask[6]; this.tasks[1] = (ExploderTask) new Preprocess(this); this.tasks[2] = this.parameters.ThreadOptions != ExploderObject.ThreadOptions.Disabled ? (ExploderTask) new CutterMT(this) : (ExploderTask) new CutterST(this); this.tasks[3] = (ExploderTask) new IsolateMeshIslands(this); this.tasks[4] = (ExploderTask) new PostprocessExplode(this); this.tasks[5] = (ExploderTask) new PostprocessCrack(this); this.PreAllocateBuffers(); this.audioSource = (AudioSource)((Component)this).get_gameObject().AddComponent <AudioSource>(); }
public ExploderQueue(ExploderObject exploder) { this.exploder = exploder; queue = new Queue <ExploderSettings>(); }
private void Start() { this.Exploder = ExploderSingleton.Instance; }
/// <summary> /// set options for fragment rigid bodies and layer /// </summary> public void SetFragmentPhysicsOptions(ExploderObject.FragmentOption options, bool physics2d) { if (pool != null) { var constrains = RigidbodyConstraints.None; if (options.FreezePositionX) constrains |= RigidbodyConstraints.FreezePositionX; if (options.FreezePositionY) constrains |= RigidbodyConstraints.FreezePositionY; if (options.FreezePositionZ) constrains |= RigidbodyConstraints.FreezePositionZ; if (options.FreezeRotationX) constrains |= RigidbodyConstraints.FreezeRotationX; if (options.FreezeRotationY) constrains |= RigidbodyConstraints.FreezeRotationY; if (options.FreezeRotationZ) constrains |= RigidbodyConstraints.FreezeRotationZ; foreach (var fragment in pool) { if (fragment.gameObject) { fragment.gameObject.layer = LayerMask.NameToLayer(options.Layer); } fragment.SetConstraints(constrains); fragment.DisableColliders(options.DisableColliders, meshColliders, physics2d); } } }
/// <summary> /// set options for fragment sound and particle effects /// </summary> /// <param name="sfx"></param> public void SetSFXOptions(ExploderObject.SFXOption sfx) { if (pool != null) { HitSoundTimeout = sfx.HitSoundTimeout; MaxEmitters = sfx.EmitersMax; for (int i = 0; i < pool.Length; i++) { pool[i].SetSFX(sfx, i < MaxEmitters); } } }
void Start() { Exploder = Utils.ExploderSingleton.Instance; }
void Start() { exploder = GameObject.FindGameObjectWithTag("TheExploder").GetComponent <ExploderObject>(); ForceVector = -Camera.main.transform.up.normalized; }
/// <summary> /// apply physical explosion to fragment piece (2D case) /// </summary> void ApplyExplosion2D(Transform meshTransform, Vector3 centroid, Vector3 mainCentroid, ExploderObject.FragmentOption fragmentOption, bool useForceVector, Vector2 ForceVector, float force, GameObject original, int targetFragments) { var rigid = rigid2D; // apply fragment mass and velocity properties var parentVelocity = Vector2.zero; var parentAngularVelocity = 0.0f; var mass = fragmentOption.Mass; // inherit velocity and mass from original object if (fragmentOption.InheritParentPhysicsProperty) { if (original && original.GetComponent<Rigidbody2D>()) { var parentRigid = original.GetComponent<Rigidbody2D>(); parentVelocity = parentRigid.velocity; parentAngularVelocity = parentRigid.angularVelocity; mass = parentRigid.mass / targetFragments; } } Vector2 forceVector = (meshTransform.TransformPoint(centroid) - mainCentroid).normalized; float angularVelocity = fragmentOption.AngularVelocity * (fragmentOption.RandomAngularVelocityVector ? Random.insideUnitCircle.x : fragmentOption.AngularVelocityVector.y); if (useForceVector) { forceVector = ForceVector; } rigid.velocity = forceVector * force + parentVelocity; rigid.angularVelocity = angularVelocity + parentAngularVelocity; rigid.mass = mass; maxVelocity = fragmentOption.MaxVelocity; }
public void Initialize(ExploderObject exploder) { if (initialized) { return; } initialized = true; parameters = new ExploderParams(exploder); // init pool FragmentPool.Instance.Allocate(parameters.FragmentPoolSize, parameters.MeshColliders, parameters.Use2DCollision, parameters.FragmentPrefab); FragmentPool.Instance.SetDeactivateOptions(parameters.DeactivateOptions, parameters.FadeoutOptions, parameters.DeactivateTimeout); FragmentPool.Instance.SetExplodableFragments(parameters.ExplodeFragments, parameters.DontUseTag); FragmentPool.Instance.SetFragmentPhysicsOptions(parameters.FragmentOptions, parameters.Use2DCollision); FragmentPool.Instance.SetSFXOptions(parameters.SFXOptions); frameWatch = new Stopwatch(); explosionWatch = new Stopwatch(); crackManager = new CrackManager(); // // init queue // queue = new ExploderQueue(this); // // init tasks // tasks = new ExploderTask[(int)TaskType.TaskMax]; tasks[(int)TaskType.Preprocess] = new Preprocess(this); #if DISABLE_MULTITHREADING tasks[(int)TaskType.ProcessCutter] = new CutterST(this); #else if (parameters.ThreadOptions == ExploderObject.ThreadOptions.Disabled) { tasks[(int)TaskType.ProcessCutter] = new CutterST(this); } else { tasks[(int)TaskType.ProcessCutter] = new CutterMT(this); } #endif tasks[(int)TaskType.IsolateMeshIslands] = new IsolateMeshIslands(this); tasks[(int)TaskType.PostprocessExplode] = new PostprocessExplode(this); tasks[(int)TaskType.PostprocessCrack] = new PostprocessCrack(this); tasks[(int)TaskType.PartialSeparator] = new PartialSeparator(this); PreAllocateBuffers(); if (parameters.SFXOptions.ExplosionSoundClip) { audioSource = gameObject.GetComponent <AudioSource>(); if (!audioSource) { audioSource = gameObject.AddComponent <AudioSource>(); } } }
/// <summary> /// apply physical explosion to fragment piece /// </summary> public void ApplyExplosion(Transform meshTransform, Vector3 centroid, Vector3 mainCentroid, ExploderObject.FragmentOption fragmentOption, bool useForceVector, Vector3 ForceVector, float force, GameObject original, int targetFragments) { if (rigid2D) { ApplyExplosion2D(meshTransform, centroid, mainCentroid, fragmentOption, useForceVector, ForceVector, force, original, targetFragments); return; } var rigid = rigidBody; // apply fragment mass and velocity properties var parentVelocity = Vector3.zero; var parentAngularVelocity = Vector3.zero; var mass = fragmentOption.Mass; var useGravity = fragmentOption.UseGravity; rigid.maxAngularVelocity = fragmentOption.MaxAngularVelocity; // inherit velocity and mass from original object if (fragmentOption.InheritParentPhysicsProperty) { if (original && original.GetComponent<Rigidbody>()) { var parentRigid = original.GetComponent<Rigidbody>(); parentVelocity = parentRigid.velocity; parentAngularVelocity = parentRigid.angularVelocity; mass = parentRigid.mass / targetFragments; useGravity = parentRigid.useGravity; } } var forceVector = (meshTransform.TransformPoint(centroid) - mainCentroid).normalized; var angularVelocity = fragmentOption.AngularVelocity * (fragmentOption.RandomAngularVelocityVector ? Random.onUnitSphere : fragmentOption.AngularVelocityVector); if (useForceVector) { forceVector = ForceVector; } rigid.velocity = forceVector * force + parentVelocity; rigid.angularVelocity = angularVelocity + parentAngularVelocity; rigid.mass = mass; maxVelocity = fragmentOption.MaxVelocity; rigid.useGravity = useGravity; }
public void SetSFX(ExploderObject.SFXOption sfx, bool allowParticle) { audioClip = sfx.FragmentSoundClip; if (audioClip && !audioSource) { audioSource = gameObject.AddComponent<AudioSource>(); } if (sfx.FragmentEmitter && allowParticle) { if (!particleChild) { var dup = Instantiate(sfx.FragmentEmitter) as GameObject; if (dup) { particleChild = new GameObject("Particles"); particleChild.transform.parent = gameObject.transform; dup.transform.parent = particleChild.transform; } } if (particleChild) { emmiters = particleChild.GetComponentsInChildren<ParticleEmitter>(); } emmitersTimeout = sfx.ParticleTimeout; stopEmitOnTimeout = emmitersTimeout > 0.0f; } else { if (particleChild) { Destroy(particleChild); emmitersTimeout = -1.0f; stopEmitOnTimeout = false; } } }
public void Enqueue(ExploderObject.OnExplosion callback, GameObject obj) { var settings = new ExploderSettings(exploder) { Callback = callback, Target = obj, processing = false }; queue.Enqueue(settings); ProcessQueue(); }
public ExploderQueue(ExploderObject exploder) { this.exploder = exploder; queue = new Queue<ExploderSettings>(); }
public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, GameObject obj, bool crack) { queue.Enqueue(exploderObject, callback, obj, crack); }
void Start() { Exploder = Utils.ExploderSingleton.ExploderInstance; }
public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, GameObject obj, Vector3 shotDir, Vector3 hitPosition, float bulletSize) { }