public ParticleSystemContainer GenerateSpecialEffectAtCharacter(AbstractBattleUnit unit,
                                                                 ProtoParticleSystem particleSystem,
                                                                 HardpointLocation locationToHit,
                                                                 Action afterAnimationIsFinishedAction = null)
 {
     return(PlaceParticleSystem(particleSystem,
                                unit.CorrespondingPrefab.Hardpoints.FromHardpointLocation(locationToHit),
                                afterAnimationIsFinishedAction
                                ));
 }
        public ParticleSystemContainer PlaceParticleSystem(ProtoParticleSystem particleSystem,
                                                           Transform intendedBoundingBox,
                                                           Action afterAnimationIsFinishedAction = null,
                                                           Transform parent = null)
        {
            if (parent == null)
            {
                parent = particleCamera.transform;
            }

            var loadedPrefab = Resources.Load <ParticleSystem>(particleSystem.PrefabPath);

            if (loadedPrefab == null)
            {
                Debug.LogError("Could not load particles from location: " + particleSystem.PrefabPath + "; using meeple instead");
                loadedPrefab = Resources.Load <ParticleSystem>(DefaultParticleSystemPath);
            }

            var instance = Instantiate(loadedPrefab, parent: parent);

            MoveParticleSystemToUiBoundingBox(instance, intendedBoundingBox);
            instance.transform.localScale *= particleSystem.SizeRatio;
            instance.Play();
            instance.gameObject.layer = 10;//particle layer
            var container = new ParticleSystemContainer {
                Particles = instance,
                GoodUntil = DateTime.Now + TimeSpan.FromSeconds(particleSystem.KillAfterNumSeconds)
            };

            if (afterAnimationIsFinishedAction != null)
            {
                container.AfterAnimationIsFinishedAction = afterAnimationIsFinishedAction;
            }
            SpecialEffectsInProgress.Add(container);

            Debug.Log("Started particle effect: " + particleSystem.PrefabPath);

            return(container);
        }