This is the 13th day of my participation in the August More Text Challenge. For details, see:August is more challenging

πŸ‘‰ About the author

As we all know, life is a long process of overcoming difficulties, reflecting and moving forward. In this process, there will be a lot of questions and thinking about life, so I decided to share my own thinking, experience and story, in order to find resonance!! Focus on Android/Unity and various game development skills, as well as various resource sharing (website, tools, materials, source code, games, etc.)

πŸ‘‰ Soon to learn

From head to toe, from ignorant to running, perfect joint development of Android and Unity. The article is divided into two parts.

πŸ‘‰ background

πŸ™ˆ xiao Kong and πŸ™Ž Xiao Zhi: This is a very long story!

πŸ‘‰ Practice Process

Layout of the rendering

We need to load 3D in any layout, how any? I’m just going to find a view to add the View that doesn’t affect the 3D or the android native interface

Android :layout_width="match_parent" Android :layout_height="match_parent" Android :layout_margin="50dp" Android :orientation=" /> // Java file mlinear.removeallviews (); mLinear.addView(mUnityPlayer.getView()); mUnityPlayer.requestFocus();Copy the code

RXlung/Android — Unity– Android/Unity Brawl — Complete interactive guide (github.com

Communication interaction

Android calls the Unity

/ / the second is the Unity of the methods of parameters which is an object hanging in the c # script parameters of three strings UnityPlayer. UnitySendMessage (" Main Camera ", "AndroidCallUnity", "");Copy the code

Unity calls Android to read the comments carefully

using System.Collections; using System.Collections.Generic; using UnityEngine; //https://juejin.cn/user/4265760844943479/posts //https://zhima.blog.csdn.net/ public class Manager : MonoBehaviour { private AndroidJavaObject m_androidObj = null; public GameObject diqiu; Void the Start () {/ / note - different com. Unity3d. Player. UnityPlayer may be different, Can be reference for other bloggers AndroidJavaClass androidClass = new AndroidJavaClass (com. Unity3d. Player. "UnityPlayer"); m_androidObj = androidClass.GetStatic<AndroidJavaObject>("currentActivity"); diqiu.SetActive(false); } public void UnityCallAndroid() {debug.log (" call method "); if (m_androidObj ! = null) {debug.log (" call method in "); // The first argument is the method name of the Java code in Android, and the second is the string argument m_androidobj. Call("CallAndroid", "I'm Unity, I'm sending you a message "); Public void AndroidCallUnity(string json) {if (Diqiu-.activeinhierarchy) { diqiu.SetActive(false); } else { diqiu.SetActive(true); }}}Copy the code

Scene: the switch

  • Unity handles it internally, just like playing a game, and let Unity develop it.
  • Andorid triggers, Unity changes the scene, and this is done using the message communication described above.
  • This is also a tip, if the resources are not many and in a scene, you can let Unity directly render a dictionary, and then want to show which Android sent to Unity message, Unity according to the message, show different content, this benefit is to switch display speed is extremely fast. Focus on the time it takes to start.

Dynamic resource

Unity supports reading the storage files of Android devices, allowing them to process them, and then Android sends them a message telling them the address

// The first argument is the name of the object in Unity, Parameters method of the two Unity three path string UnityPlayer. UnitySendMessage (" AndriodMethodMgr ", "CallUnitySetPath", Environment.getExternalStorageDirectory() + "");Copy the code

Aha, that’s pretty much the end of it. Fast and happy.

Pit pit

It’s best to look at the problems and save at least a few days for fun.

1. Confusion, if you open confusion, remember to add confusion, this big hole for me for a long time

2. If the model works in Unity but doesn’t work on Android, look at the release quality and set it to high

3. If the repeated execution of the model animation is wrong, why not? Take heart beating for example. It pays great attention to the cohesion of animation. If the cohesion time is not correct, it will cause the jitters of heart animation, which will be very obvious.

You can see the exit time of the animation setting. The exit time is the proportion (as shown in the figure below), 1 represents all the animation, 0.5 represents the animation pressed hard normal. Overtime animation overlaps before and after (like default.95?) You can change it to 0, as shown in the picture

4. After integration into APK, I applied for vertical and horizontal screen, but APK did not work. This is caused by the setting of Unity release, and then the publicity direction is set in the Other setting when Unity export

5. Permissions, the above said will export an Android project, you carefully look at the project’s Android manifest file, you will find that there are also permissions. Note that if your Android project has permission A and your Unity exported project does not have permission A, when you integrate and merge, the final APK does not have permission A. This is not what we want to see; So to solve this problem, it’s easy to make the two manifest files have the same permissions. Remember, otherwise you won’t know how to cry.

6. There is still one unsolved problem, put it here, if anyone knows, thank you for your advice. An object with animation. On some Android devices, the animation shows the journey, but on others, the animation jumps, like a progress bar on a TV.

At the end

Finally, don’t ask me why I know so much. Ask me because I walked here on my knees.

πŸ‘‰ other

πŸ“’ by xiao Kong and xiao Kong in Xiao Zhi πŸ“’. πŸ“’ Welcome to like πŸ‘ save 🌟 leave πŸ“