I am trying to fill-in a static list of Arrays.
The function RTTWifiPositionsToJava
is used from Unity (C#) to pass the Parameters for each WifiPosition.
But each item of the list m_RTTWifiPositions
has the same value as the last added value.
Can somebody help please, thanks :)
static class RTTWifiPos
{
static String strMacAddress;
static double posX, posY, posZ;
static double distance;
static double distanceDev;
}
static List<RTTWifiPos> m_RTTWifiPositions;
public static boolean RTTWifiPositionsToJava(int nIndex, String strMacAddress, double PosX, double PosY, double PosZ, double distance, double distanceStdDev)
{
if(nIndex == 0)
{
if(m_RTTWifiPositions != null)
m_RTTWifiPositions.clear();
else
m_RTTWifiPositions = new ArrayList<RTTWifiPos>();
}
RTTWifiPos rttpos = new RTTWifiPos();
rttpos.strMacAddress = strMacAddress;
rttpos.posX = PosX;
rttpos.posY = PosY;
rttpos.posZ = PosZ;
rttpos.distance = distance;
rttpos.distanceDev = distanceStdDev;
m_RTTWifiPositions.add(rttpos);
return true;
}
The function RTTWifiPositionsToJava
is called from Unity3D like this:
for (nIndex = 0; nIndex < WifiRTTSignals.Count; nIndex++)
{
result = m_pluginWifiRTTClass.CallStatic<bool>("RTTWifiPositionsToJava", nIndex, WifiRTTSignals[nIndex].macAddress, (double) WifiRTTSignals[nIndex].pos.x, (double) WifiRTTSignals[nIndex].pos.y, (double) WifiRTTSignals[nIndex].pos.z, (double) WifiRTTSignals[nIndex].distance, (double) 0f);
}
The variables in RTTWifiPos will always be the same becus the are static. Static variables will always have the same value independent of objects explanation. Example:
static class RTTWifiPos
{
String strMacAddress;
double posX, posY, posZ;
double distance;
double distanceDev;
}
I would also make them private and with getter/setter methods instead for better control.
Thank you flaimme, I thought by using
RTTWifiPos rttpos = new RTTWifiPos();
everything is having a new instance ? But I will follow your and sleepToken's hint.By using
RTTWifiPos rttpos = new RTTWifiPos();
you got a new object but the variables declared static will be the same as for all the objects of the same type.