- Home /
PlayerPrefsX plugin error when build for windows store
Hi, im using playerprefsX plugin by wiki.unity3d.com to store my Arrays. it worked perfectly on any other platform including ios, and windows phone 8, but when im trying to build for windows store, i encounter this error:
Assets\Plugins\PlayerPrefsX.cs(213,9): error CS1061: 'System.Collections.BitArray' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.Collections.BitArray' could be found (are you missing a using directive or an assembly reference?)
and
Assets\Plugins\PlayerPrefsX.cs(212,34): error CS1061: 'System.Collections.BitArray' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Collections.BitArray' could be found (are you missing a using directive or an assembly reference?)
im new with program$$anonymous$$g and i have no idea what happens. in monodevelop there was no error and i can hit play, i even can run it on windows phone 8.0. but when i change platform to wsa 8.1, this error occur. doesnt make sense because it worked fine in wp8.0
Are you sure you use this version:
http://wiki.unity3d.com/index.php/ArrayPrefs
Line 212 / 213 are inside SetStringArray and there isn't any use of BitArray class. You should link the actual source which you are using. We're not here to guess what scripts you're using.
sorry, the script that i was using is from here ArrayPrefs2
Does anyone have a solution for this? I've also been using this script on Android and iOS with no problems. Now I'm building for Windows Store and getting the same error.
Answer by Bunny83 · Apr 28, 2015 at 04:30 PM
It seems that the BitArray class, used to store a bool array in the PlayerPrefs, isn't fully supported on WS.
I haven't tested this yet, but it should work the same as the original methods.
edit
Just cross-tested it (saving with the old method loading with the new and reverse) and it seems to work properly (tested with two different 10 item bool arraya). So it should be 100% compatible with data that has been stored with the old version.
I can't test it in a Windows Store project, so feel free to test it and give feedback if you get errors or if it doesn't work as it should.
Just replace those two methods in the "PlayerPrefsX.cs". I only created a C# version ^^ If someone is willing to create
public static bool SetBoolArray(String key, bool[] boolArray)
{
// Make a byte array that's a multiple of 8 in length, plus 5 bytes to store the number of entries as an int32 (+ identifier)
// We have to store the number of entries, since the boolArray length might not be a multiple of 8, so there could be some padded zeroes
var bytes = new byte[(boolArray.Length + 7) / 8 + 5];
bytes[0] = System.Convert.ToByte(ArrayType.Bool); // Identifier
int mask = 1;
int targetIndex = 5;
for(int i = 0; i < boolArray.Length; i++)
{
if (boolArray[i])
bytes[targetIndex] |= (byte)mask;
mask <<= 1;
if (mask > 128)
{
mask = 1;
targetIndex++;
}
}
Initialize();
ConvertInt32ToBytes(boolArray.Length, bytes); // The number of entries in the boolArray goes in the first 4 bytes
return SaveBytes(key, bytes);
}
public static bool[] GetBoolArray(String key)
{
if (PlayerPrefs.HasKey(key))
{
var bytes = System.Convert.FromBase64String(PlayerPrefs.GetString(key));
if (bytes.Length < 5)
{
Debug.LogError("Corrupt preference file for " + key);
return new bool[0];
}
if ((ArrayType)bytes[0] != ArrayType.Bool)
{
Debug.LogError(key + " is not a boolean array");
return new bool[0];
}
Initialize();
int count = ConvertBytesToInt32(bytes);
var boolArray = new bool[count];
int mask = 1;
int targetIndex = 5;
for (int i = 0; i < boolArray.Length; i++)
{
boolArray[i] = (bytes[targetIndex] & (byte)mask) != 0;
mask <<= 1;
if (mask > 128)
{
mask = 1;
targetIndex++;
}
}
return boolArray;
}
return new bool[0];
}
I've put the fixed script on my dropbox for the time being.
Answer by unimechanic · Oct 09, 2014 at 03:01 PM
According to the page that script is obsolete, and it was developed for WebPlayer:
This script has been made obsolete by Unity 2.1; PlayerPrefs now works in Web players.
http://wiki.unity3d.com/index.php/PlayerPrefsx
Use the actual PlayerPrefs instead:
Hi, thanks for the reply. Yes, the script is obsolete and then someone posted anew version called arrayprefs2. This is the one that i was using. It worked for all platform except windows store app.
@unimechanic: the page being discussed in this question is http://wiki.unity3d.com/index.php/ArrayPrefs2
Your answer
Follow this Question
Related Questions
Attempting to store an Inventory Array in PlayerPrefsX 1 Answer
How to save an array to PlayerPrefs? 1 Answer
assigning arrays with for in 1 Answer
For In Loop Fills all values in arrays problem 2 Answers
Saving Array Objects in Android. 0 Answers