public Texture2D CreateTexture(Source source)
 {
     Texture2D texture = new Texture2D(_samplingWidth, _samplingheight);
     texture.filterMode = FilterMode.Point;
     UnityEngine.Color[] pixels = new Color[texture.width * texture.height];
     Vector3 co = Vector3.zero;
     float sample = 0f;
     for (int z = 0; z < texture.height; z++) {
         for (int x = 0; x < texture.width; x++) {
             co.x = x * _samplingStep;
             co.z = z * _samplingStep;
             sample = source.GetFloat(co);
             pixels[z * texture.width + x].a = 1f;
             pixels[z * texture.width + x].r = sample;
             pixels[z * texture.width + x].g = sample;
             pixels[z * texture.width + x].b = sample;
         }
     }
     pixels[0] = UnityEngine.Color.green;
     pixels[pixels.Length - 1] = UnityEngine.Color.red;
     texture.SetPixels(pixels);
     texture.Apply();
     return texture;
 }
 void OnSelectionChange()
 {
     if (_lockSource) {
         return;
     }
     Source source = Selection.activeObject as Source;
     if (source != null && source.IsValid()) {
         _source = source;
         _previewTexture = CreateTexture(_source);
         Repaint();
         UpdateLastValue();
     } else {
         _previewTexture = null;
     }
 }