本文整理汇总了Java中com.unity3d.player.UnityPlayer类的典型用法代码示例。如果您正苦于以下问题:Java UnityPlayer类的具体用法?Java UnityPlayer怎么用?Java UnityPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnityPlayer类属于com.unity3d.player包,在下文中一共展示了UnityPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BroadcastConstants.NEWAPP)) {
String packageName = intent.getStringExtra("packageName");
if (!TextUtils.isEmpty(packageName)) {
//判断是否可以加入缓存列表
if(!appController.addable(packageName)){
return;
}
List<AppModel> list = appController.getModelListByPackageName(packageName);
if(list==null||list.size()==0)return;
Random random =new Random();
for(AppModel appModel : list){
appModel.setBeUsed(false);
appModel.setAppStatus(0);
appController.addNew(appModel);
_loadApp(appModel, random.nextInt(100));
}
String json = mGson.toJson(list);
UnityPlayer.UnitySendMessage("LauncherController", "MessageInstalled", json);
LogUtil.d(TAG, "newAppReceiver json:"+json);
}
}
}
示例2: CreateChannel
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static void CreateChannel(String identifier, String name, String description, int importance, String soundName, int enableLights, int lightColor, int enableVibration, long[] vibrationPattern, String bundle) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return;
channels.add(identifier);
NotificationManager nm = (NotificationManager) UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(identifier, name, importance);
channel.setDescription(description);
if (soundName != null) {
Resources res = UnityPlayer.currentActivity.getResources();
int id = res.getIdentifier("raw/" + soundName, null, UnityPlayer.currentActivity.getPackageName());
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
channel.setSound(Uri.parse("android.resource://" + bundle + "/" + id), audioAttributes);
}
channel.enableLights(enableLights == 1);
channel.setLightColor(lightColor);
channel.enableVibration(enableVibration == 1);
if (vibrationPattern == null)
vibrationPattern = new long[] { 1000L, 1000L };
channel.setVibrationPattern(vibrationPattern);
nm.createNotificationChannel(channel);
}
示例3: onReceive
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
int id = intent.getIntExtra("id", 0);
String gameObject = intent.getStringExtra("gameObject");
String handlerMethod = intent.getStringExtra("handlerMethod");
String actionId = intent.getStringExtra("actionId");
boolean foreground = intent.getBooleanExtra("foreground", true);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(id);
if (foreground) {
Intent launchIntent = new Intent(context, UnityPlayerActivity.class);
launchIntent.setPackage(null);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launchIntent);
}
UnityPlayer.UnitySendMessage(gameObject, handlerMethod, actionId);
}
示例4: handleMessage
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public void handleMessage(Message msg) {
switch(msg.what) {
case MESSAGE_STATE_CHANGE:
UnityPlayer.UnitySendMessage(TARGET, "OnStateChanged", String.valueOf(msg.arg1));
break;
case MESSAGE_READ:
byte[] readBuf = (byte[])msg.obj;
String readMessage = new String(readBuf, 0, msg.arg1);
UnityPlayer.UnitySendMessage(TARGET, "OnReadMessage", readMessage);
break;
case MESSAGE_WRITE:
byte[] writeBuf = (byte[])msg.obj;
String writeMessage = new String(writeBuf);
UnityPlayer.UnitySendMessage(TARGET, "OnSendMessage", writeMessage);
break;
case MESSAGE_DEVICE_NAME:
BluetoothPlugin.this.mConnectedDeviceName = msg.getData().getString("device_name");
Toast.makeText(BluetoothPlugin.this.getApplicationContext(), "Connected to " + BluetoothPlugin.this.mConnectedDeviceName, Toast.LENGTH_SHORT).show();
break;
case MESSAGE_TOAST:
Toast.makeText(BluetoothPlugin.this.getApplicationContext(), msg.getData().getString("toast"), Toast.LENGTH_SHORT).show();
break;
}
}
示例5: onReceive
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
@RequiresPermission("android.permission.BLUETOOTH")
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if("android.bluetooth.device.action.FOUND".equals(action)) {
BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
BluetoothPlugin.this.singleAddress.add(device.getName() + "\n" + device.getAddress());
UnityPlayer.UnitySendMessage(TARGET, "OnFoundDevice", device.getName() + ",\n" + device.getAddress());
} else if("android.bluetooth.adapter.action.DISCOVERY_FINISHED".equals(action)) {
if(BluetoothPlugin.this.IsScan) {
UnityPlayer.UnitySendMessage(TARGET, "OnScanFinish", "");
}
if(BluetoothPlugin.this.singleAddress.size() == 0) {
UnityPlayer.UnitySendMessage(TARGET, "OnFoundNoDevice", "");
}
}
}
示例6: setupUnity
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public void setupUnity() {
try {
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
// if (mUnityPlayer.getSettings().getBoolean("hide_status_bar", true)) {
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// }
View playerView = mUnityPlayer.getView();
FrameLayout layout = (FrameLayout) findViewById(R.id.frameUnity);
layout.addView(playerView, getWindow().getAttributes().width, getWindow().getAttributes().height);
mUnityPlayer.requestFocus();
} catch (Exception e) {
Log.e(TAG, "setupUnity() : " + e.getMessage());
}
}
示例7: openAppSettings
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
/**
* Open app notification settings
*/
public static void openAppSettings(){
Activity activity = UnityPlayer.currentActivity;
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
//for Android 5-7
intent.putExtra("app_package", activity.getPackageName());
intent.putExtra("app_uid", activity.getApplicationInfo().uid);
// for Android O
intent.putExtra("android.provider.extra.APP_PACKAGE", activity.getPackageName());
activity.startActivity(intent);
}
示例8: setLocalNotification
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
/**
* ローカル通知をセットする
* @param notificationId 通知ID
* @param title 通知タイトル
* @param message 通知メッセージ
* @param sentAt 何秒後に通知するか
* @param isUnique 通知を重複させないか
*/
public static void setLocalNotification(int notificationId, String title, String message, int sentAt, boolean isUnique) {
// Delete duplicate notification
if (isUnique)
cancelLocalNotification(notificationId);
// Create intent
Activity activity = UnityPlayer.currentActivity;
Context context = activity.getApplicationContext();
Intent intent = new Intent(context, NotificationReceiver.class);
// Set intent params
intent.putExtra(LocalNotificationConstants.INTENT_ID_KEY, notificationId);
intent.putExtra(LocalNotificationConstants.INTENT_TITLE_KEY, title);
intent.putExtra(LocalNotificationConstants.INTENT_MESSAGE_KEY, message);
intent.putExtra(LocalNotificationConstants.INTENT_ACTION_KEY, UnityPlayerActivity.class.getName());
// Set notification time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, sentAt);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
示例9: Share
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
static void Share(final String title, final String text, final int withImage) throws IOException
{
if (Build.VERSION.SDK_INT >= 23 && withImage != 0)
{
new PermissionRequester(UnityPlayer.currentActivity, new PermissionListener() {
@Override
public void onComplete(boolean status)
{
try
{
if (status)
ShareWoRequestPermissions(title, text, withImage);
} catch (IOException e)
{
e.printStackTrace();
}
}
});
}
else
ShareWoRequestPermissions(title, text, withImage);
}
示例10: notify
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static void notify(String title, String body) {
Activity activity = UnityPlayer.currentActivity;
Context context = activity.getApplicationContext();
int id =(int)(Math.random() * 10000.0f) + 1;
Intent intent2 = new Intent();
intent2.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent2,
PendingIntent.FLAG_UPDATE_CURRENT);
final PackageManager pm=context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return;
}
final int appIconResId = applicationInfo.icon;
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), appIconResId);
// NotificationBuilderを作成
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentIntent(contentIntent);
builder.setTicker(title);
builder.setSmallIcon(appIconResId);
builder.setContentTitle(title);
builder.setContentText(body);
builder.setLargeIcon(largeIcon);
builder.setWhen(System.currentTimeMillis());
builder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_LIGHTS);
builder.setAutoCancel(true);
NotificationManager manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(id, builder.build());
}
示例11: SetRepeatingNotification
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static void SetRepeatingNotification(int id, long delayMs, String title, String message, String ticker, long rep, int sound, String soundName, int vibrate, int lights,
String largeIconResource, String smallIconResource, int bgColor, String bundle, String channel, ArrayList<NotificationAction> actions)
{
Activity currentActivity = UnityPlayer.currentActivity;
AlarmManager am = (AlarmManager)currentActivity.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(currentActivity, UnityNotificationManager.class);
intent.putExtra("ticker", ticker);
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.putExtra("id", id);
intent.putExtra("color", bgColor);
intent.putExtra("sound", sound == 1);
intent.putExtra("soundName", soundName);
intent.putExtra("vibrate", vibrate == 1);
intent.putExtra("lights", lights == 1);
intent.putExtra("l_icon", largeIconResource);
intent.putExtra("s_icon", smallIconResource);
intent.putExtra("bundle", bundle);
intent.putExtra("channel", channel);
Bundle b = new Bundle();
b.putParcelableArrayList("actions", actions);
intent.putExtra("actionsBundle", b);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayMs, rep, PendingIntent.getBroadcast(currentActivity, id, intent, 0));
}
示例12: countryCodeFromLastKnownLocation
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static String countryCodeFromLastKnownLocation() throws IOException {
Activity current = UnityPlayer.currentActivity;
LocationManager locationManager =
(LocationManager) current.getSystemService(Context.LOCATION_SERVICE);
Location location =
locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null && Geocoder.isPresent()) {
Geocoder gcd = new Geocoder(current, Locale.getDefault());
List<Address> addresses;
addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
return address.getCountryCode();
}
}
return null;
}
示例13: showLoginUIWithCallback
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static void showLoginUIWithCallback(final String gameObjectName)
{
OKBridgeLog("Launching Login UI with callback");
OKLoginActivity.setActivityHandler(new OKLoginActivityHandler() {
@Override
public void onLoginDialogComplete() {
String returnString = "OpenKit login dialog finished";
UnityPlayer.UnitySendMessage(gameObjectName, ASYNC_CALL_SUCCEEDED, returnString);
}
});
UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Intent loginUI = new Intent(UnityPlayer.currentActivity, OKLoginActivity.class);
UnityPlayer.currentActivity.startActivity(loginUI);
}
});
}
示例14: submitScore
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
/**
* Submits a given score value and leaderboard ID. Uses UnitySendMessage to send a success or fail message to the gameobjectname specified
* @param scoreValue
* @param leaderboardID
* @param gameObjectName GameObject that acts as an event handler
*/
public static void submitScore(long scoreValue, int leaderboardID, int metadata, String displayString, final String gameObjectName)
{
OKBridgeLog("Submitting score");
OKScore score = new OKScore();
score.setScoreValue(scoreValue);
score.setOKLeaderboardID(leaderboardID);
score.setMetadata(metadata);
score.setDisplayString(displayString);
score.submitScore(new ScoreRequestResponseHandler() {
@Override
public void onSuccess() {
UnityPlayer.UnitySendMessage(gameObjectName, "scoreSubmissionSucceeded", "");
}
@Override
public void onFailure(Throwable arg0) {
UnityPlayer.UnitySendMessage(gameObjectName, "scoreSubmissionFailed", arg0.getLocalizedMessage());
}
});
}
示例15: submitAchievementScore
import com.unity3d.player.UnityPlayer; //导入依赖的package包/类
public static void submitAchievementScore(int progress, int achievementID, final String gameObjectName)
{
OKBridgeLog("Submitting achievement score");
OKAchievementScore achievementScore = new OKAchievementScore();
achievementScore.setOKAchievementId(achievementID);
achievementScore.setProgress(progress);
achievementScore.submitAchievementScore(new OKAchievementScore.AchievementScoreRequestResponseHandler() {
@Override
public void onSuccess() {
OKBridgeLog("Achievement score submitted successfully");
UnityPlayer.UnitySendMessage(gameObjectName, "scoreSubmissionSucceeded", "");
}
@Override
public void onFailure(Throwable error) {
OKBridgeLog("Achievement score submission failed");
UnityPlayer.UnitySendMessage(gameObjectName, "scoreSubmissionFailed", error.getLocalizedMessage());
}
});
}