Skip to content

Instantly share code, notes, and snippets.

@GOROman
Created July 31, 2015 05:26
Show Gist options
  • Save GOROman/5f18ecd9efe840eb26c0 to your computer and use it in GitHub Desktop.
Save GOROman/5f18ecd9efe840eb26c0 to your computer and use it in GitHub Desktop.
UnityのC#からAndroidのボリュームを変更する
void SetAndroidVolume( int volume )
{
#if (UNITY_ANDROID && !UNITY_EDITOR)
int STREAM_MUSIC = 3; // Constant Value: 3 (0x00000003)
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ac = jc.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject am = ac.Call<AndroidJavaObject>("getSystemService", "audio");
am.Call("setStreamVolume", STREAM_MUSIC, volume, 0);
#endif
}
@GOROman
Copy link
Author

GOROman commented Jul 31, 2015

give me more マシな方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment