/// <summary> /// Spawn to a specific position, rotation /// </summary> /// <param name="Position">Position to spawn to.</param> /// <param name="Rotation">Direction of rotation to spawn to.</param> /// <param name="WhichTarget">Target layers to pass to the spawned game object.</param> /// <returns>The instance of the game object that was instantiated.</returns> public GameObject Spawn(Vector3 Position, Quaternion Rotation, SpawnTarget WhichTarget) { Target = WhichTarget; GameObject goInstance; if (GlobalFuncs.MAGICAL_POOL && !DoNotPool) { if (PoolSlotId > 0) // pool slot already found { goInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(PoolSlotId - 1, Position, Rotation); // load from the pool } else { goInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(ref PoolSlotId, Prefab, Position, Rotation, WhichTarget); // load from the pool } } else { goInstance = UnityEngine.Object.Instantiate(Prefab, Position, Rotation); // load from the prefab goInstance.SetActive(false); // disable GlobalFuncs.SetComponentTagsSlotsAndLayers(ref goInstance, WhichTarget, -1); // update the components } SetSpawnOptions(ref goInstance, PhysicsForceOptions); // set the options return(goInstance); // pass the spawned object back for potential modification }
/// <summary> /// Occurs when the animator enters the parent state, creates hand particles and targeting. /// </summary> /// <param name="animator">Reference to the parent animator.</param> /// <param name="stateInfo">Information about the state.</param> /// <param name="layerIndex">Index of the current animator layer.</param> public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // set the magic spawn point if (!tMagicSpawn) { bAI = !(animator.gameObject.tag == "Player"); if (!bAI) { tMagicSpawn = animator.GetComponentInChildren <MagicSettings>().MagicSpawnPoint; } else { tMagicSpawn = animator.GetComponentInChildren <MagicAI>().MagicSpawnPoint; } } // handle the hand particle if (SpellOptions.LimbParticleEffect && !goLimb1_ParticleInstance) { // enabled, present and not already active? if (GlobalFuncs.MAGICAL_POOL && !SpellOptions.DoNotPoolLimbParticles) { // pooling enabled? if (iLimbPoolSlotID1 > 0) { // pool slot already known goLimb1_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(iLimbPoolSlotID1 - 1, tMagicSpawn); // load from the pool } else { goLimb1_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(ref iLimbPoolSlotID1, SpellOptions.LimbParticleEffect, tMagicSpawn, SpawnTarget.Any); // load from the pool } goLimb1_ParticleInstance.SetActive(true); // enable as will be returned from the pool disabled } else { // pool disabled goLimb1_ParticleInstance = Instantiate(SpellOptions.LimbParticleEffect); // load from the prefab } if (SpellOptions.attackLimb != SpellOptions.attackLimb2) { // dont create a second particle if both limbs the same if (GlobalFuncs.MAGICAL_POOL && !SpellOptions.DoNotPoolLimbParticles) { // pooling enabled? if (SpellOptions.LimbParticleEffect2) { // does limb 2 has a different particle effect? if (iLimbPoolSlotID2 > 0) { // pool slot already known goLimb2_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(iLimbPoolSlotID2 - 1, tMagicSpawn); // load from the pool } else { goLimb2_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(ref iLimbPoolSlotID2, SpellOptions.LimbParticleEffect2, tMagicSpawn, SpawnTarget.Any); // load from the pool } } else { // nope if (iLimbPoolSlotID1 > 0) { // pool slot already known goLimb2_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(iLimbPoolSlotID1 - 1, tMagicSpawn); // load from the pool } else { goLimb2_ParticleInstance = GlobalFuncs.TheMagicalPool().GatherFromPool(ref iLimbPoolSlotID1, SpellOptions.LimbParticleEffect, tMagicSpawn, SpawnTarget.Any); // load from the pool } } goLimb2_ParticleInstance.SetActive(true); // enable as will be returned from the pool disabled } else { // pool disabled goLimb2_ParticleInstance = Instantiate((SpellOptions.LimbParticleEffect2 ? SpellOptions.LimbParticleEffect2 : SpellOptions.LimbParticleEffect)); // load from the prefab } } } // spawn all immediate if charge state if (SpellOptions.ChargeState) { // spawn over time all as long as not the charge state foreach (SpawnerOptionsOverTime sootSpawnMe in SpellOptions.SpawnOverTime) { // process all spawns immediate if (sootSpawnMe.UseRootTransform) { // ground based effect? sootSpawnMe.goSpawnedParticle = sootSpawnMe.Spawn(animator.rootPosition, Quaternion.identity, (bAI ? SpawnTarget.Friend : SpawnTarget.Enemy)); // spawn } else { // negative, use the magic spawn point sootSpawnMe.goSpawnedParticle = sootSpawnMe.Spawn(tMagicSpawn, (bAI ? SpawnTarget.Friend : SpawnTarget.Enemy)); // spawn } } } }