Unity3d Web Player

0 views
Skip to first unread message

Ariel Wascom

unread,
Aug 5, 2024, 5:39:35 AM8/5/24
to braganperloo
Im new to both Unity and Android programming. My goal is to add some extra category specifiers to AppManifest.xml. As I understand it, to modify the manifest, I need to take Unity's generated manifest, copy it to my project to use as a starting point, then modify it.

Update: So I just took a look inside the generated APK file, and I see that it does include a class named com.unity3d.player.UnityPlayerActivity. I am not sure why it's looking for UnityPlayerActivity in my app's package instead of com.unity3d.player.


Ok, I got it working, I manually changed android:name in the application element from com.companyname.glass.screen.UnityPlayerActivity to com.unity3d.player.UnityPlayerActivity. But I'm not going to attempt to post a self-answer because I have no idea why I had to do that or if that was the "proper" solution. Will accept any reasonable explanation of this. (I arrived at this conclusion by comparing the manifests from the APKs both with and without my custom manifest; I do not understand why Unity filled in an incorrect application class name with "Export" vs "Build and Run").


We will need to write a very simple C# script for the teleportation. What the script does is that when the player collides with the trigger, which in this case will be the teleportation pad, it switches the position of the player to the designated location which is the Teleport Target.


Unity supports multiple plug-in types for Android applications. This post relates to Java (non-native) plugins: JAR, AAR, source code Java. We show how to access surface view instance created by Unity player instance from inside android Java plugin. Unity version 2021.3.16f1, Android minimal API level 26 (Android 8.0 Oreo), Unity scripting backend Mono .NET Standard 2.1, Java v8.0.


We use java reflection to read mGlView. But before that, we need to have an instance of UnityPlayer. To get the instance of UnityPlayer we should read protected mUnityPlayer field of UnityPlayerActivity. Thus, we have the following algorithm:


Note, that both UnityPlayer and UnityPlayerActivity should be instances of com.unity3d.player and com.unity3d.player.UnityPlayerActivity classes respectively. Otherwise, reflect API will throw with invalid argument type.


This project allows you to extend UnityPlayerActivity in an isolated source-control friendly Android Studio project, without a need to work on the exported Android Studio project of your game. It also removes the need to copy, maintain (and even worse, include) the file classes.jar from the Unity installation.


When you develop a Unity Android application, you can use plug-ins to extend the standard UnityPlayerActivity class (the primary Java class for the Unity Player on Android, similar to AppController.mm on Unity iOS). An application can override all basic interactions between the Android OS and the Unity Android application.


The suggested method in Unity documentation is to extend UnityPlayerActivity is to open the exported Android project in Android Studio, and do modifications from there. However, this method may introduce friction and difficulties in workflow, such as difficulty in source control of the extension plugin, and maintaining other modules/plugins that you may want to introduce.


Another method suggested around the web is to manually copy classes.jar from the Unity directory to your working directory. However, this requires including the classes.jar file within the plugin, or needs extra effort to exclude it from builds.


On the other hand, with this method, you can have an isolated Android Studio project for your Unity plugin, by referencing the Unity classes without a need to copy and maintain classes.jar, and keeping the reference import com.unity3d.player.UnityPlayerActivity; intact.


The whole idea is to mock com.unity3d.player.UnityPlayerActivity; by including a compile-only module for UnityPlayerActivity. This way you can work on a fresh isolated Android Studio project as if you are working on an exported Android Studio project.


For example, if I have a character, in this case a simple 2D box, with a Rigidbody and a Collider component attached to it, I can make the box jump by applying force to the Rigidbody when a jump button is pressed.


This is useful, as it allows you to change how an object experiences gravity, without changing the global gravity value in the physics settings. So you could, for example, make an object float by turning off its gravity, without affecting any other objects.


While using a continuous collision detection mode is generally less efficient, the performance hit is often justifiable, as it will help to prevent the player from passing through the environment if they move too fast.


This can be done by creating a short window of time at the beginning of the jump, the Button Time, which is measured using a timer, the Jump Time, as soon as the jump starts.


Now that I can measure how long the player pressed the jump button for, all I need to do to create a variable jump is to keep adding an amount of force while Jumping is equal to true, to keep the jump going.


While, for a simulation of physics, this kind of sudden movement can be unrealistic, it can also be beneficial as setting the Velocity basically has the same effect as the Add Force method in Impulse mode.


Except that, while the Add Force method adds force creating an acceleration over time, setting the Velocity property over a number of frames will, instead, overwrite and maintain the amount of velocity that is set.


Likewise, tailoring the amount of in-air control can help make it easier for players to plan where they will land, by increasing the time spent at the apex of the jump, or by allowing them to go back more easily if they change their mind.


However, continuous physics forces, such as the Add Force function, should usually only be used inside Fixed Update, in order to keep any application of force in sync with the physics system that will respond to it.


Most of the time, the simplest way to create character movement in Unity, including making a player jump, is to do it with physics, by adding a Rigidbody component to the object and applying forces to it.


Snapping the player to the floor in 3D works in a similar way to 2D, as both the 2D and 3D physics engines support very similar Overlap and Raycast functions that can be used to get a reference to a Collider.


While you will need to manually check for the floor and other static objects when creating your own jumping movement in 2D, in 3D, Unity provides a built-in Component that makes collision detection a little easier.


The Character Controller component provides a straightforward way to add movement, and jumping, to your game quickly and easily. It works particularly well for first person games and allows you to create collision-based movement without needing to use physics.


Like in the previous examples, this can be done with a Raycast, or an Overlap method, or by simply checking when the Rigidbody has collided with another object using the On Collision messages.


However, ever since Unity 5, when the 3D physics system was improved, the performance penalty for moving a Static Collider was, reportedly, fixed. So much so that, for some, it is now more efficient to move Static Collider objects using the wrong method, with their Transforms, rather than to move them explicitly using Kinematic Rigidbodies.


And, while it can be a lot of work building a Kinematic Controller that works in the way you want it to, there are some very good ready-made options available on the Asset Store that can save you a lot of time, with excellent results. Such as the Kinematic Character Controller, which can make setting up a Kinematic character controller much, much easier.


Thanks Ryan, to answer your question, if you add another condition to the if statement (that checks for the spacebar press) to also check if the player is grounded, that should solve this problem. That way a jump can only be started from the ground.


Wow! I normally help people but this actually helped me better understand all the different ways to go about doing this in a easy to learn fashion and even changed how I went about doing my jumps! Kudos good sir! Awesome article!


I found all the problems in my game that you talk about in the article. And falling through the ground, gravity not working and many other things. But with the help of your article everything works perfectly now. Very useful article, thank you very much! Added your site to my favorites ?


Each float value in the array is a texture mix, which is a value between 0 and 1, that corresponds to how much of the texture is applied at that position. I can use this to find out what mix of surfaces the player is standing on.


To get the alpha map data I need to use the Get Alphamaps function. This is a function of terrain Data on the terrain class and takes four parameters:


I am thinking of stacking all of that 4 times (for each terrain texture) and ramping volume up and down same as you have it. This would result in 24 clips loaded and possibly all 24 being played at once. I have max 8 other sounds loaded in the scene as well.


For performance improvements I would cache (store in a variable) the alpha map you get from GetAlphamaps (Use GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight)), its height and width as well as the overall terrain size at the start of the game. These are almost never something you change at runtime, so its just unnecessary calculations, and even then if you change them you can just re-cache them.


As of now this is how the current set up looks. All the transitions come from Any State, because all the work deciding when to transition happens within the script. And since there are so many possible to and from transitions, it was easiest to do it this way.


Within Update is where all one time inputs are checked, like jumping or breaking out into a run. If you try to check for these in Fixed Update, inputs can be missed, so they have to be done in Update. The Animation function, where all the animations take place is called at the bottom of the Update function.

3a8082e126
Reply all
Reply to author
Forward
0 new messages