How to match automatically the texture proportion with a plane proportion scale?

Hello,

I’m new with Unity.

I would like to match the texture size with a plane size. But actually the texture is stretched by default.

I have a 400x300 texture in a Material (4/3 proportion). I want to set the material in my plane.
So I have to set manually the scale according the texture proportion : ScaleX = 4 and ScaleY = 3.

But it’s really boring to set manually all this.

Thanks.

Write an editor script to do it for you.

I tried to write an editor script but I can’t get the native texture file size.
I got the texture size compressed with Unity.

Here my editor script :

#if UNITY_EDITOR

using UnityEditor;
using UnityEngine;


class ProportionalSizeWithTexture {
	
	[MenuItem("Tools/Benoit/Propotional Scale With Texture")]
	
	static void UpgradeSolutions() {
		//Debug.Log(Selection.activeGameObject);
		if (Selection.activeGameObject) {
			GameObject go = Selection.activeGameObject;
			Debug.Log(go.renderer.material.mainTexture.width + " " + go.renderer.material.mainTexture.height);
			float scaleX = go.renderer.material.mainTexture.width / 100f;
			float scaleZ = go.renderer.material.mainTexture.height / 100f;
			go.transform.localScale = new Vector3(scaleX, 1f, scaleZ);
		}

	}
}
#endif

The go.renderer.material.mainTexture.width value returns : a power of 2 size.
Even if I set a Non Power Of Two texture I got the same result.