//typeOverride = use to discard what reticle entity is set to, // or if there's no entity public Reticle Activate(Transform attachTo, Reticle.Type typeOverride = Reticle.Type.NumType) { Reticle ret = null; EntityBase ent = attachTo.GetComponentInChildren <EntityBase>(); //verify reticle type Reticle.Type reticleType = typeOverride; if (ent != null && reticleType == Reticle.Type.NumType) { reticleType = ent.reticle; } if (reticleType != Reticle.Type.NumType) { ret = attachTo.GetComponentInChildren <Reticle>(); //add a reticle to target if (ret == null) { Transform trans = transform; Transform child = null; //get or create a reticle if (trans.childCount > 0) { child = trans.GetChild(0); child.gameObject.SetActiveRecursively(true); } else { child = Transform.Instantiate(template) as Transform; } //add child to attachee, then switch its layer to target for grabbing child.parent = attachTo; Transform childTrans = child.transform; Vector2 parentPos = child.parent.position; childTrans.position = new Vector3(parentPos.x, parentPos.y, childZOfs); childTrans.localRotation = Quaternion.identity; childTrans.localScale = Vector3.one; ret = childTrans.GetComponentInChildren <Reticle>(); mActiveReticles.Add(new ReticleHolder(ent, ret)); } //set data if (ent != null && !ent.FlagsCheck(Entity.Flag.Targetted)) { ent.FlagsAdd(Entity.Flag.Targetted); ent.OnTargetted(true); } ret.Activate(reticleType, ent); } return(ret); }
public void ActivateInRange(Vector3 pos, float radius, int layerMask, Reticle.Type typeOverride = Reticle.Type.NumType) { //TODO: optimize DeactivateAll(); RaycastHit[] hits = Physics.SphereCastAll(pos, radius, new Vector3(0, 0, 1.0f), Mathf.Infinity, layerMask); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { Transform t = hit.transform; Activate(t, typeOverride); } } }