public static void AddRaycaster(SpaceCaster spaceCaster) { if (!s_Raycasters.Contains(spaceCaster)) { s_Raycasters.Add(spaceCaster); } }
public override IEnumerator UpdateBeam(SpaceCaster caster, List <UnityEngine.EventSystems.RaycastResult> raycastHits) { while (caster.casterActive) { if (raycastHits.Count > 0) { var closestHit = raycastHits.OrderBy(h => h.distance).OrderByDescending(h => h.depth).First(); OnTarget(caster); float reach = closestHit.distance > maxReticleDistance ? maxReticleDistance : closestHit.distance; // TODO: change reposition into a lerp reticle.transform.localPosition = Vector3.forward * reach; reticle.transform.localScale = Vector3.Scale(reticleBaseScale, reticleSize) * (reach / maxReticleDistance); } else { Default(caster); reticle.transform.localPosition = Vector3.forward * minReticleDistance; reticle.transform.localScale = Vector3.Scale(reticleBaseScale, reticleSize); } yield return(null); } Default(caster); reticle.transform.localPosition = Vector3.forward * minReticleDistance; reticle.transform.localScale = Vector3.Scale(reticleBaseScale, reticleSize); }
public virtual IEnumerator UpdateBeam(SpaceCaster caster, List <UnityEngine.EventSystems.RaycastResult> beamHits) { while (caster.casterActive) { yield return(null); } }
public static void RemoveRaycasters(SpaceCaster baseRaycaster) { if (!s_Raycasters.Contains(baseRaycaster)) { return; } s_Raycasters.Remove(baseRaycaster); }
public override void Default(SpaceCaster caster) { base.Default(caster); beamPointRenderers.ForEach(r => r.material = beamPointMaterial); beamBodyRenderers.ForEach(r => r.material = beamBodyMaterial); UpdateMaterialColors(); }
protected PointerEventData GetSpaceCasterEventData(SpaceCaster caster) { PointerEventData casterData; bool created = GetSpaceCasterData(caster, out casterData, true); casterData.Reset(); if (created) { casterData.position = caster.eventCamera.ViewportToScreenPoint(Vector2.one * 0.5f); UpdateDeviceRelations(); } return(casterData); }
public override IEnumerator UpdateBeam(SpaceCaster caster, List <UnityEngine.EventSystems.RaycastResult> beamHits) { while (State != BeamState.Off) { if (beamHits.Where(hit => hit.gameObject).ToList().Count > 0) { var closestHit = beamHits.OrderBy(h => h.distance).OrderByDescending(h => h.depth).First(); if (closestHit.gameObject.GetComponent <UnityEngine.UI.Graphic>()) { beamPointRenderers.ForEach(r => { r.material = beamPointCanvasMaterial; r.sortingOrder = closestHit.sortingOrder + 1; }); beamBodyRenderers.ForEach(r => r.material = beamBodyCanvasMaterial); } else { beamPointRenderers.ForEach(r => r.material = beamPointMaterial); beamBodyRenderers.ForEach(r => r.material = beamBodyMaterial); } OnTarget(caster); float reach = closestHit.distance > currentStyle.maxBeamLength ? currentStyle.maxBeamLength : closestHit.distance; // TODO: change reposition into a lerp beamPoint.transform.localPosition = Vector3.forward * reach; beamBody.transform.localScale = GlobalizeScale(caster.transform, new Vector3(currentStyle.beamThickness.x, currentStyle.beamThickness.y, reach)); beamBody.transform.localPosition = Vector3.forward * reach * 0.5f; } else { Default(caster); beamPoint.transform.localPosition = Vector3.forward * currentStyle.minBeamLength; beamBody.transform.localScale = GlobalizeScale(caster.transform, new Vector3(currentStyle.beamThickness.x, currentStyle.beamThickness.y, currentStyle.minBeamLength)); beamBody.transform.localPosition = Vector3.forward * currentStyle.minBeamLength * 0.5f; } yield return(null); } Default(caster); beamPoint.transform.localPosition = Vector3.forward * currentStyle.minBeamLength; beamBody.transform.localScale = GlobalizeScale(caster.transform, new Vector3(currentStyle.beamThickness.x, currentStyle.beamThickness.y, currentStyle.minBeamLength)); beamBody.transform.localPosition = Vector3.forward * currentStyle.minBeamLength * 0.5f; }
public override void GenerateBeam(SpaceCaster caster) { // Beam Body setup if (reticlePrefab) { reticle = Instantiate(reticlePrefab.gameObject, caster.transform) as GameObject; reticleSpriteRenderer = reticle.GetComponent <SpriteRenderer>(); } else { reticle = new GameObject("Reticle"); reticleSpriteRenderer = reticle.AddComponent <SpriteRenderer>(); } reticle.layer = 2; reticleBaseScale = reticle.transform.localScale; }
// Returns true if event data was created protected bool GetSpaceCasterData(SpaceCaster caster, out PointerEventData data, bool create) { if (!m_CasterData.ContainsKey(caster) && create) { //Debug.Log("SpacesInputModule [Added CasterData " + caster.id + "] " + caster.name); var casterData = new CasterData() { eventData = new PointerEventData(eventSystem) { pointerId = caster.id }, #if UNITY_STANDALONE_WIN trackedObject = caster.GetComponentInParent <SteamVR_TrackedObject>(), #elif UNITY_ANDROID || UNITY_IOS trackedObject = caster.GetComponentInParent <Transform>().gameObject, #endif inputState = new InputDeviceState(), lastPointPosition = caster.Forward }; if (!casterData.trackedObject) { #if UNITY_STANDALONE_WIN casterData.trackedObject = caster.gameObject.AddComponent <SteamVR_TrackedObject>(); #endif } m_CasterData.Add(caster, casterData); data = casterData.eventData; return(true); } else { data = m_CasterData.ContainsKey(caster) ? m_CasterData[caster].eventData : null; return(false); } }
public override void OnTarget(SpaceCaster caster) { base.OnTarget(caster); reticleSpriteRenderer.color = OnTargetColor; }
public override void OnTarget(SpaceCaster caster) { base.OnTarget(caster); UpdateMaterialColors(); }
public override void Default(SpaceCaster caster) { base.Default(caster); reticleSpriteRenderer.color = DefaultColor; }
public virtual void OnInteractableTarget(SpaceCaster caster) { State = BeamState.OnInteractableTarget; }
public override void GenerateBeam(SpaceCaster caster) { // Beam Body setup if (!beamBody) { if (beamBodyPrefab) { beamBody = Instantiate(beamBodyPrefab, caster.transform) as GameObject; } else { beamBody = GameObject.CreatePrimitive(PrimitiveType.Cube); beamBody.transform.SetParent(caster.transform, false); beamBody.layer = LayerMask.NameToLayer("Ignore Raycast"); } beamBody.name = "BeamBody"; beamBody.layer = 2; } beamBody.transform.localPosition = Vector3.zero; beamBody.transform.localRotation = Quaternion.Euler(Vector3.zero); beamBody.transform.localScale = GlobalizeScale(caster.transform, new Vector3(currentStyle.beamThickness.x, currentStyle.beamThickness.y, currentStyle.minBeamLength)); // Beam Point setup if (!beamPoint) { if (beamPointPrefab != null) { beamPoint = Instantiate(beamPointPrefab, caster.transform) as GameObject; } else { beamPoint = GameObject.CreatePrimitive(PrimitiveType.Sphere); beamPoint.transform.SetParent(caster.transform, false); beamPoint.layer = LayerMask.NameToLayer("Ignore Raycast"); } beamPoint.name = "BeamPoint"; beamPoint.layer = 2; } beamPoint.transform.localPosition = Vector3.zero; beamPoint.transform.localRotation = Quaternion.Euler(Vector3.zero); beamPoint.transform.localScale = GlobalizeScale(caster.transform, currentStyle.pointSize); // Renderering settings if (!baseBeamMaterial) { beamBodyMaterial = new Material(Shader.Find("Unlit/Color")); } else { beamBodyMaterial = new Material(baseBeamMaterial); } if (!baseCanvasMaterial) { beamBodyCanvasMaterial = beamBodyMaterial; } else { beamBodyCanvasMaterial = new Material(baseCanvasMaterial); } beamBodyMaterial.color = currentStyle.beamColor; beamBodyCanvasMaterial.color = currentStyle.beamColor; if (!baseBeamMaterial) { beamPointMaterial = new Material(Shader.Find("Unlit/Color")); } else { beamPointMaterial = new Material(baseBeamMaterial); } if (!baseCanvasMaterial) { beamPointCanvasMaterial = beamPointMaterial; } else { beamPointCanvasMaterial = new Material(baseCanvasMaterial); } beamPointMaterial.color = currentStyle.pointColor; beamPointCanvasMaterial.color = currentStyle.pointColor; beamPointRenderers = beamPoint.GetComponentsInChildren <Renderer>().ToList(); beamBodyRenderers = beamBody.GetComponentsInChildren <Renderer>().ToList(); beamPointRenderers.ForEach(r => r.material = beamPointMaterial); beamBodyRenderers.ForEach(r => r.material = beamBodyMaterial); Default(caster); }
public virtual void OnTarget(SpaceCaster caster) { State = BeamState.OnTarget; }
public virtual void NearTarget(SpaceCaster caster) { State = BeamState.NearTarget; }
public virtual void Default(SpaceCaster caster) { State = BeamState.Default; }
public virtual void Off(SpaceCaster caster) { State = BeamState.Off; }
public virtual void GenerateBeam(SpaceCaster caster) { }