private void Awake() { if (instance != null && instance != this) { Debug.LogWarning("PickingManager instance already set. Are there multiple instances in the scene?"); Destroy(this); return; } instance = this; }
public Pickable GetPickableAt(Vector2 screenPosition) { if (!cpuData.IsCreated) { return(null); } int scaledX = (int)screenPosition.x / scaleDivisor; int scaledY = (int)screenPosition.y / scaleDivisor; Color32 packedId = cpuData[scaledX + dataWidth * scaledY]; int id = PickingManager.DecodeId(packedId); return(PickingManager.GetPickable(id)); }
private void OnDestroy() { entries.Clear(); foreach (Material material in materials.Values) { Destroy(material); } materials.Clear(); if (instance == this) { instance = null; } }
private void OnEnable() { // Picking manager may not be instantiated, in which case we can't do anything useful, so stop. if (!PickingManager.Add(this)) { return; } if (renderers == null) { return; } if (properties == null) { properties = new MaterialPropertyBlock(); } int id = PickingManager.GetPickableId(this); Color32 packedId = PickingManager.EncodeId(id); foreach (Renderer r in renderers) { properties.Clear(); // Keep existing changed properties. if (r.HasPropertyBlock()) { r.GetPropertyBlock(properties); } properties.SetColor(pickableIdPropertyId, packedId); r.SetPropertyBlock(properties); r.sharedMaterial = PickingManager.GetPickableMaterial(r.sharedMaterial); } }
private void OnDisable() { PickingManager.Remove(this); }