Copy files from Resources/StreamingAssets to Application.persistentDataPath upon installation

You can put the file in the Resources folder from the Editor folder then read with the Resources API. TextAsset txtAsset = (TextAsset)Resources.Load(“textfile”, typeof(TextAsset)); string tileFile = txtAsset.text; You can check if this is the first time the app is running with this. After that you can copy the loaded data to the Application.persistentDataPath directory. … Read more

Pass byte array from Unity C# to C++ plugin

Few things you need to do with your current code: 1.You have to send the size of the array to the C++ plugin in another parameter as UnholySheep mentioned. 2.You also have to pin the array before sending it to the C++ side. This is done with the fixed keyword or GCHandle.Alloc function. 3.If the … Read more

Start android service from Unity3D code

Below are two ways to send Activity instance/reference to Java plugin that doesn’t use the onCreate function or extend from UnityPlayerActivity. Method 1: Send Activity reference once then store it in a static variable in Java for re-usual: Java: public final class StatusCheckStarter { static Activity myActivity; // Called From C# to get the Activity … Read more

Repeated serialization and deserialization creates duplicate items

The reason this is happening is due to the combination of two things: Your class constructors automatically add default items to their respective lists. Json.Net calls those same constructors to create the object instances during deserialization. Json.Net’s default behavior is to reuse (i.e. add to) existing lists during deserialization instead of replacing them. To fix … Read more

Errors managing the UnityPlayer lifecycle in a native android application

Ok, easy things first W/libc(21095): pthread_create sched_setscheduler call failed: Operation not permitted There is nothing you can do about it. You even get this when you compile directly from Unity for Android, so it’s a problem inside the engine. Basic Setup The guide you linked is pretty outdated. You no longer need to copy files … Read more

Convert data type from inherited classes in C#

Your problem stems from the fact that the base classes are poorly designed in the first place, in the following ways: The hierarchy makes no sense. A behaviour is not a special kind of position. Prefer composition to inheritance. Fields should never be public. Use properties, not fields. “is” checks are runtime type checks; don’t … Read more

Piecewise linear integer curve interpolation in C#/Unity3D

I would use this interpolation cubic: x=a0+a1*t+a2*t*t+a3*t*t*t y=b0+b1*t+b2*t*t+b3*t*t*t where a0..a3 are computed like this: d1=0.5*(p2.x-p0.x); d2=0.5*(p3.x-p1.x); a0=p1.x; a1=d1; a2=(3.0*(p2.x-p1.x))-(2.0*d1)-d2; a3=d1+d2+(2.0*(-p2.x+p1.x)); b0 .. b3 are computed in same way but use y coordinates of course p0..p3 are control points for cubic interpolation curve t = < 0.0 , 1.0 > is curve parameter from p1 to … Read more

Best way to save large amount of data locally in unity3D android? [closed]

NOTE – do not use “StreamWriter” for any reason. Just use the trivial File.Write commands. This is a common misunderstanding in Unity! Regarding this topic, a bad example code was propagated on the www for years. Simply use File.Write. Regarding the question on this page, “thousands” of entries is absolutely nothing. Note that for example: … Read more