public bool GetCBuffer(int pixelX, int pixelY, out CBufferHit cBuffer) { cBuffer = null; if (null == m_renderTexture || null == m_readTexture) { //throw new UChartException("please call method [AddRenderer] firstly."); return(false); } // read screen pixel to texture2d RenderTexture.active = m_renderTexture; m_readTexture.ReadPixels(m_readTextureRect, 0, 0); m_readTexture.Apply(); // get pixel color and set cbuffer value. Color pickColor = m_readTexture.GetPixel(pixelX, pixelY); Debug.Log(pickColor); foreach (KeyValuePair <string, Color> pair in cbufferDic) { if (pair.Value == pickColor) { cBuffer = new CBufferHit(); cBuffer.name = pair.Key; cBuffer.point = transDic[pair.Key]; return(true); } } // get pickId in colorbuffer for (int i = 0; i < m_colorBuffer.Length; i++) { if (pickColor == m_colorBuffer[i]) { cBuffer = new CBufferHit(); cBuffer.pickId = i; return(true); } } return(false); }
public bool GetCBuffer(Vector2 pixelPosition, out CBufferHit cBuffer) { return(GetCBuffer((int)(pixelPosition.x), (int)(pixelPosition.y), out cBuffer)); }