/// <summary> /// Apply the specified force to surrounding game objects that match the targeting layers /// </summary> /// <param name="Instance">Game object to center the application of force radius on.</param> /// <param name="Target">Target game objects to apply force to.</param> public void Apply(GameObject Instance, SpawnTarget Target) { if (Enabled) // physics enabled? { // find all colliders within the blast radius LayerMask TargetLayers; switch (Target) { case SpawnTarget.Friend: TargetLayers = (1 << GlobalFuncs.targetingLayerMaskFriend.value) | (1 << GlobalFuncs.targetingLayerMaskPhysics); break; case SpawnTarget.Enemy: TargetLayers = (1 << GlobalFuncs.targetingLayerMaskEnemy.value) | (1 << GlobalFuncs.targetingLayerMaskPhysics); break; default: TargetLayers = (1 << GlobalFuncs.targetingLayerMaskAll.value) | (1 << GlobalFuncs.targetingLayerMaskPhysics); break; } Collider[] colliders = Physics.OverlapSphere(Instance.transform.position, Radius, TargetLayers); // process all found foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); // attempt grab the rigid body if (rb) // found a rigid body to apply force to? { rb.AddExplosionForce(Force, Instance.transform.position, Radius, UpwardsForce, Mode); // explode } } } }
/// <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 }
protected Bullet Spawn() { Bullet b = _spawningDelegate(this); SpawnTarget.AddBullet(b); return(b); }
public PreviewBackCombinatorInfo(SpawnTarget spawnTarget, LayoutTracker paren, List <int> path, Action place, Action highlight, Action unHighlight) { this.highlight = highlight; this.unHighlight = unHighlight; this.spawnTarget = spawnTarget; this.paren = paren; this.path = path; this.place = place; }
// Use this for initialization void Start() { inZone = false; gMan = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager> (); sMan = GameObject.FindGameObjectWithTag("SubManager").GetComponent <SpawnTarget> (); currentTimeing = captureTime; checkpoint = captureTime / 2; //zoneHealthBar = GameObject.FindGameObjectWithTag ("ZoneCompletionBar").GetComponent<Image> (); //zoneHealthBar.fillAmount = 0; }
/// <summary> /// Initialise a new pool slot. /// </summary> /// <param name="WhichSlotID">ID of this pool slot.</param> /// <param name="WhichPrefab">Prefab to instantiate.</param> /// <param name="WhichInitialSize">Minimum/initial pool size.</param> /// <param name="WhichMaxSize">Maximum pool size.</param> /// <param name="WhichTarget">Targeting to apply to the instance.</param> public MagicPoolItem(int WhichSlotID, GameObject WhichPrefab, int WhichInitialSize, int WhichMaxSize, SpawnTarget WhichTarget) { // initialise iSlotID = WhichSlotID; Prefab = WhichPrefab; InitialSize = WhichInitialSize; MaxSize = WhichMaxSize; Target = WhichTarget; // create initial instances BuildSlot(); }
public Sum <PreviewInfo, Unit> FreshPreview(SpawnTarget spawnTarget, List <Transform> targets) { if (targets.Count > 0) { return(MakeDrop(spawnTarget, targets[0]).Match(_ => Sum <PreviewInfo, Unit> .Inr(new Unit()), sum => Sum <PreviewInfo, Unit> .Inl(sum))); } else { return(Sum <PreviewInfo, Unit> .Inr(new Unit())); } }
private void Start() { instance = this; newTargetList = new List <GameObject>(); lineList = new List <LineRenderer>(); PickColor = new Vector4(); isSetStart = false; isSetTarget = false; scale = new Vector3(0.7f, 0.7f, 0.7f); }
/// <summary> /// Return the pool slot id for the specified prefab, creating a new pool slot if not found. /// </summary> /// <param name="Prefab">Prefab to search the pool for.</param> /// <param name="WhichTarget">Target filter to search the pool for.</param> /// <returns>ID of the pool slot.</returns> public int iFindPoolSlotID(GameObject Prefab, SpawnTarget WhichTarget) { MagicPoolItem mpiFound = PooledMagic.FirstOrDefault(i => i.Prefab == Prefab && i.Target == WhichTarget); // search slots for the prefab if (mpiFound != null) { // found? return(mpiFound.iSlotID); // return the slot index } else { // nope PooledMagic.Add(new MagicPoolItem(PooledMagic.Count, Prefab, DefaultInitialSize, DefaultMaxSize, WhichTarget)); // create new slot return(PooledMagic.Count - 1); // return new slot index } }
void UnPlace() { var pos = transform.position; List <int> index = GetComponent <LayoutTracker>().index; SymbolManager sm = GetComponentInParent <SymbolManager>(); SpawnTarget sp = GetComponentInParent <SpawnTarget>(); var lt = sm.RemoveAtAndReturn(index.Skip(1).ToList(), sm.GetComponentInChildren <LayoutTracker>()); lt.transform.SetParent(GetComponentInParent <Canvas>().transform, true); lt.transform.SetAsLastSibling(); lt.enabled = false; transform.position = pos; LayoutRebuilder.MarkLayoutForRebuild(sm.GetComponent <RectTransform>()); sp?.CheckSuccess(); }
void PlaceMe() { if (myDraggableType == DraggableHolder.DraggableType.LeftPane) { duplicate.enabled = true; } var lt = GetComponent <LayoutTracker>(); lt.root = lt.GetComponentInParent <SymbolManager>().skeletonRoot; lt.enabled = true; LayoutRebuilder.MarkLayoutForRebuild(lt.GetComponentInParent <Canvas>().GetComponent <RectTransform>()); SpawnTarget sp = GetComponentInParent <SpawnTarget>(); sp?.CheckSuccess(); }
/// <summary> /// Spawn from a transform at a specific time, called repeatedly during an animator state /// </summary> /// <param name="SpawnPoint"></param> /// <param name="Time"></param> /// <param name="Animator"></param> /// <param name="WhichTarget"></param> /// <returns>Reference to the instance of the instantiated game object</returns> public GameObject Spawn(Transform SpawnPoint, float Time, Animator Animator, SpawnTarget WhichTarget) { if (Time < 0.1 && SpawnedSoFar >= NumberToSpawn) // at the start of the animation and not already reset the counter { SpawnedSoFar = 1; // reset (1 rather than zero to avoid undesired instant spawn fSpawnRate = ((SpawnEndTime - SpawnStartTime) / NumberToSpawn); // cache } else if (SpawnedSoFar < NumberToSpawn + 1) // still more instances to spawn { if (Time > (SpawnStartTime + (fSpawnRate * SpawnedSoFar))) // time for the next spawn { SpawnedSoFar += 1; // count number spawned if (Prefab) // only spawn if the prefab is set { if (UseRootTransform) // spawn from the animator base { goSpawnedParticle = Spawn(Animator.rootPosition, Quaternion.identity, WhichTarget); } else // use the magic spawn point { goSpawnedParticle = Spawn(SpawnPoint, WhichTarget); // create the spawn instance } } if (PlayOnSpawn && SourceOfAudio && SourceOfAudio.isActiveAndEnabled) // play audio? { if (!SourceOfAudio.isPlaying) // ignore if already playing { SourceOfAudio.clip = PlayOnSpawn; // set the clip SourceOfAudio.Play(); // play the clip } } return(goSpawnedParticle); // return a reference to the instance } } return(null); // drop out clean }
/// <summary> /// Gather from the magical pool when the pool slot id is unknown (or needs creating) by direct position. /// </summary> /// <param name="Slot">Pool slot ID return by reference.</param> /// <param name="Prefab">Prefab to find.</param> /// <param name="Position">Position to move the gathered game object to.</param> /// <param name="Rotation">Rotation to set the gathered game object to.</param> /// <param name="WhichTarget">Target filter to search the pool for.</param> /// <returns>Game object gathered from the pool.</returns> public GameObject GatherFromPool(ref int Slot, GameObject Prefab, Vector3 Position, Quaternion Rotation, SpawnTarget WhichTarget) { Slot = iFindPoolSlotID(Prefab, WhichTarget) + 1; if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Gathering magic from the pool id " + Slot + " for " + Prefab.name); } return(GatherFromPool(Slot - 1, Position, Rotation)); }
/// <summary> /// Gather from the magical pool when the pool slot id is unknown (or needs creating) by transform. /// </summary> /// <param name="Slot">Pool slot ID return by reference.</param> /// <param name="Prefab">Prefab to find.</param> /// <param name="SpawnPoint">Transform to move the gathered game object to.</param> /// <param name="WhichTarget">Target filter to search the pool for.</param> /// <returns>Game object gathered from the pool.</returns> public GameObject GatherFromPool(ref int Slot, GameObject Prefab, Transform SpawnPoint, SpawnTarget WhichTarget) { Slot = iFindPoolSlotID(Prefab, WhichTarget) + 1; if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Gathering magic from the pool id " + Slot + " for " + Prefab.name); } return(GatherFromPool(Slot - 1, SpawnPoint)); }
/// <summary> /// Use to set the targeting on various components before making active /// </summary> /// <remarks> /// Called per spell when pooling is disabled however when pooling is enabled /// a master instance is created for cloning of each spell and the targeting is only set once /// </remarks> /// <param name="MasterInstance"></param> /// <param name="Target"></param> /// <param name="SlotID"></param> public static void SetComponentTagsSlotsAndLayers(ref GameObject MasterInstance, SpawnTarget Target, int SlotID) { // grab target tag list string[] TargetTags; LayerMask TargetLayers; string[] InverseTargetTags; LayerMask InverseTargetLayers; switch (Target) { case SpawnTarget.Friend: TargetTags = targetingTagsFriend; TargetLayers = targetingLayerMaskFriend; InverseTargetTags = targetingTagsEnemy; InverseTargetLayers = targetingLayerMaskEnemy; break; case SpawnTarget.Enemy: TargetTags = targetingTagsEnemy; TargetLayers = targetingLayerMaskEnemy; InverseTargetTags = targetingTagsFriend; InverseTargetLayers = targetingLayerMaskFriend; break; default: InverseTargetTags = TargetTags = targetingTagsAll; InverseTargetLayers = TargetLayers = targetingLayerMaskAll; break; } // set magic projectile target, tags, layers MagicProjectile[] allmProjectile = MasterInstance.GetComponentsInChildren <MagicProjectile>(); foreach (MagicProjectile mProjectile in allmProjectile) { mProjectile.Target = Target; mProjectile.iPoolSlotID = SlotID + 1; switch (Target) { case SpawnTarget.Friend: mProjectile.HeatSeekTags = targetingTagsFriend; mProjectile.HeatSeekLayers = targetingLayerMaskFriend; break; case SpawnTarget.Enemy: mProjectile.HeatSeekTags = targetingTagsEnemy; mProjectile.HeatSeekLayers = targetingLayerMaskEnemy; break; default: mProjectile.HeatSeekTags = targetingTagsAll; mProjectile.HeatSeekLayers = targetingLayerMaskAll; break; } } // target and slot for teleport MagicTeleport mt = MasterInstance.GetComponentInChildren <MagicTeleport>(); if (mt) { mt.Target = Target; mt.PoolSlotID = SlotID + 1; mt.TargetLayers = TargetLayers; mt.TargetTags = TargetTags; } #if !VANILLA // vobjectdamage target tags vObjectDamage[] allVDamage = MasterInstance.GetComponentsInChildren <vObjectDamage>(); foreach (vObjectDamage vd in allVDamage) { vd.tags = TargetTags.ToList(); } #endif // targeting for physics MagicProjectilePhysics[] allmPhysics = MasterInstance.GetComponentsInChildren <MagicProjectilePhysics>(); foreach (MagicProjectilePhysics mpp in allmPhysics) { mpp.TargetLayers = Target; } // and heal MagicHeal[] allHeal = MasterInstance.GetComponentsInChildren <MagicHeal>(); foreach (MagicHeal mh in allHeal) { mh.HealTargetLayers = InverseTargetLayers; mh.HealTargetTags = InverseTargetTags; } // same for magic damage MagicObjectDamage[] allmDamage = MasterInstance.GetComponentsInChildren <MagicObjectDamage>(); foreach (MagicObjectDamage md in allmDamage) { md.AOETarget = Target; } // slot for DestroyAndSpawn DestroyGameObjectAndSpawn[] allmDOS = MasterInstance.GetComponentsInChildren <DestroyGameObjectAndSpawn>(); foreach (DestroyGameObjectAndSpawn dos in allmDOS) { dos.iPoolSlotID = SlotID + 1; dos.Target = Target; } // slot for DestroyAndSpawn DelayedSpawn[] allmDS = MasterInstance.GetComponentsInChildren <DelayedSpawn>(); foreach (DelayedSpawn ds in allmDS) { ds.iPoolSlotID = SlotID + 1; } // same for collectible CollectableItem[] allmCI = MasterInstance.GetComponentsInChildren <CollectableItem>(); foreach (CollectableItem ci in allmCI) { ci.iPoolSlotID = SlotID + 1; } }
} // trigger all spawns in the array /// <summary> /// Spawn with the minimum options aka basic. /// </summary> /// <param name="Prefab">Prefab to spawn.</param> /// <param name="HowMany">Number of instances.</param> /// <param name="Where">Transform to center the spawns at.</param> /// <param name="Radius">Random radius options.</param> /// <param name="Target">Spawn targeting.</param> /// <returns></returns> public static List <GameObject> SpawnBasic(GameObject Prefab, int HowMany, Transform Where, RandomSphereOptions Radius, SpawnTarget Target) { // set up var retunedSpawns = new List <GameObject>(); if (HowMany <= 0) { HowMany = 1; } // generate instances for (int i = 0; i < HowMany; i++) { var soSpawnMe = new SpawnerOptionsDelayedSequence(); soSpawnMe.Prefab = Prefab; soSpawnMe.NumberToSpawn = 1; soSpawnMe.RandomSphere = Radius; soSpawnMe.PhysicsForceOptions = new PhysicsOptions(); soSpawnMe.RandomRotate = new RandomRotateOptions(); retunedSpawns.Add(soSpawnMe.Spawn(Where, Target)); } // all done return(retunedSpawns); }
/// <summary> /// Spawn a list of prefabs via a derived spawner options list. /// </summary> /// <param name="Spawns">List of the prefabs to spawn.</param> /// <param name="Delay">Initial delay.</param> /// <param name="NoneSequential">Spawn copies of each in the spawn array in a blocks until no more</param> /// <param name="SpawnPoint">Transform to spawn at.</param> /// <param name="DestroyWhenFinished">Destroy parent when spawning complete.</param> /// <param name="DestroyPoolSlotID">Pool slot to return the parent to if parent was pooled.</param> /// <param name="FaceSpawnPoint">Force spawned game objects to face the spawn point.</param> /// <param name="WhichTarget">Targeting selection.</param> /// <returns></returns> public static IEnumerator SpawnAllDelayed(List <SpawnerOptionsDelayedSequence> Spawns, float Delay, bool NoneSequential, Transform SpawnPoint, GameObject DestroyWhenFinished, int DestroyPoolSlotID, bool FaceSpawnPoint, SpawnTarget WhichTarget) { // wait for x seconds before starting if (Delay > 0) { // not instant? yield return(new WaitForSeconds(Delay)); // wait } // spawn the list if (NoneSequential) { // process the list instances elm 0-x looped until no more to spawn bool bFoundMore = true; int iNext = 0; while (bFoundMore) { // process until no more bFoundMore = false; // exit loop iNext += 1; // number to spawn test increment foreach (SpawnerOptionsDelayedSequence soSpawnMe in Spawns) { // process all spawnables if (soSpawnMe.NumberToSpawn >= iNext) { // spawn another instance bFoundMore = true; // loop again if (FaceSpawnPoint) { // rotate to face spawn point GameObject goSpawned = soSpawnMe.Spawn(SpawnPoint, WhichTarget); // create instance goSpawned.transform.LookAt(SpawnPoint); // rotate to source } else { // nope, just spawn soSpawnMe.Spawn(SpawnPoint, WhichTarget); // create instance } if (soSpawnMe.SourceOfAudio && soSpawnMe.PlayOnSpawn) { // play audio? if (!soSpawnMe.SourceOfAudio.isPlaying) { // ignore if already playing soSpawnMe.SourceOfAudio.clip = soSpawnMe.PlayOnSpawn; // set the clip soSpawnMe.SourceOfAudio.Play(); // play the clip } } if (soSpawnMe.DelayTillNext > 0) { // delay enabled? yield return(new WaitForSeconds(soSpawnMe.DelayTillNext)); // wait } } } } } else { // sequential foreach (SpawnerOptionsDelayedSequence soSpawnMe in Spawns) { // process all spawnables for (int i = 0; i < soSpawnMe.NumberToSpawn; i++) { // process desired number if (FaceSpawnPoint) { // rotate to face spawn point GameObject goSpawned = soSpawnMe.Spawn(SpawnPoint, WhichTarget); // create instance goSpawned.transform.LookAt(SpawnPoint); // rotate to source } else { // nope, just spawn soSpawnMe.Spawn(SpawnPoint, WhichTarget); // create instance } if (soSpawnMe.DelayTillNext > 0) { // delay enabled? yield return(new WaitForSeconds(soSpawnMe.DelayTillNext)); // wait } } } } // optional destruction if (DestroyWhenFinished) { // destruction prefab specified? ReturnToThePoolOrDestroy(DestroyPoolSlotID, DestroyWhenFinished); // attempt pooled returned } } // trigger all spawns in the array
private Sum <Action, PreviewInfo> MakeDrop(SpawnTarget spawnTarget, Transform target) //left is on failure, right is on success { var parenTracker = target.GetComponent <LayoutTracker>(); List <int> index = parenTracker.index; var my_term = myCombinator == null ? Shrub <Sum <Combinator, Variable> > .Node(new List <Shrub <Sum <Combinator, Variable> > >()) : Shrub <Sum <Combinator, Variable> > .Leaf(Sum <Combinator, Variable> .Inl(myCombinator)); if (!target.GetComponentInParent <DraggableHolder>()) { return(Sum <Action, PreviewInfo> .Inl(DestroyMe)); } if (spawnTarget && !spawnTarget.NoBackApplication.val) //Back application { if (myCombinator == null) { //You are a parenthesis int my_index; for (my_index = 0; my_index < target.childCount; my_index++) { if (transform.position.x < target.GetChild(my_index).position.x - target.GetChild(my_index).localScale.x / 4f) { break; } } if (true /*my_index != target.childCount*/) { return(Util.BackApplyParen(spawnTarget.goal, index.Skip(1).ToList(), my_index).Match(t => { List <IHighlightable> selected = new List <IHighlightable>(); for (int i = 0; i < my_index; i++) { selected = selected.Concat(target.GetChild(i).GetComponentsInChildren <IHighlightable>()).ToList(); } PreviewRedundantParenInfo prp = new PreviewRedundantParenInfo(index, my_index, () => { spawnTarget.addParens(index.Skip(1).ToList(), my_index, GetComponent <LayoutTracker>(), t); foreach (IHighlightable highlightable in selected) { highlightable.unselect(); } PlaceMe(); myDraggableType = DraggableHolder.DraggableType.RedundantParens; }, () => { foreach (IHighlightable highlightable in selected) { highlightable.select(); } }, () => { foreach (IHighlightable highlightable in selected) { highlightable.unselect(); } }); return Sum <Action, PreviewInfo> .Inr(PreviewInfo.In2(prp)); }, _ => { return Sum <Action, PreviewInfo> .Inl(DestroyMe); })); } else { return(Sum <Action, PreviewInfo> .Inl(DestroyMe)); } } else { //You not are a parenthesis HighlightParen hightligher = parenTracker.GetComponent <HighlightParen>(); return(Util.BackApply(spawnTarget.goal, myCombinator, index.Skip(1).ToList()).Match(t => Sum <Action, PreviewInfo> .Inr(PreviewInfo.In1(new PreviewBackCombinatorInfo(spawnTarget, parenTracker, index, () => { pushUndoGoalTerm.Invoke(spawnTarget.goal); spawnTarget.unApply(t, GetComponent <LayoutTracker>(), myCombinator, index.Skip(1).ToList()); PlaceMe(); hightligher.unselect(); myDraggableType = DraggableHolder.DraggableType.NoDragging; }, hightligher.select, hightligher.unselect))) , _ => Sum <Action, PreviewInfo> .Inl(DestroyMe))); } } else if (!spawnTarget && !NoForwardMode.val && target.GetComponentInParent <DraggableHolder>() && target.GetComponentInParent <DraggableHolder>().myType == DraggableHolder.DraggableType.Proposal) //forward application { if (evaluationMode.val) { return(Sum <Action, PreviewInfo> .Inl(DestroyMe)); } int my_index; for (my_index = 0; my_index < target.childCount; my_index++) { if (transform.position.x < target.GetChild(my_index).position.x) { break; } } var sm = target.GetComponentInParent <SymbolManager>(); return(Sum <Action, PreviewInfo> .Inr( PreviewInfo.In0(new PreviewForwardInfo(sm, index, target, my_index, () => { //if (pushUndoProposalTerm) { // pushUndoProposalTerm.Invoke(sm.readTerm()); //} else { // Debug.LogError("pushUndoProposalTerm is null in DraggableSpell: " + this); //} sm.Insert(index.Skip(1).Append(my_index).ToList(), my_term); // paren = AccessTransfrom(topTracker, paren_index); transform.SetParent(target, true); transform.SetSiblingIndex(my_index); PlaceMe(); myDraggableType = DraggableHolder.DraggableType.Proposal; }, UnPlace)) )); } return(Sum <Action, PreviewInfo> .Inl(DestroyMe)); }