Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from rfadeev/upm-support
Browse files Browse the repository at this point in the history
Make PlayerPrefsEditor Unity Package Manager compatible
  • Loading branch information
Sabresaurus authored Jun 25, 2020
2 parents 6296ecf + c2f0f89 commit b9810c5
Show file tree
Hide file tree
Showing 18 changed files with 1,641 additions and 1,566 deletions.
57 changes: 30 additions & 27 deletions Editor/ImportPlayerPrefsWizard.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
using UnityEngine;
using UnityEditor;
using UnityEditor;
using UnityEngine;

public class ImportPlayerPrefsWizard : ScriptableWizard
namespace Sabresaurus.PlayerPrefsEditor
{
// Company and product name for importing PlayerPrefs from other projects
[SerializeField] string importCompanyName = "";
[SerializeField] string importProductName = "";

private void OnEnable()
public class ImportPlayerPrefsWizard : ScriptableWizard
{
importCompanyName = PlayerSettings.companyName;
importProductName = PlayerSettings.productName;
}
// Company and product name for importing PlayerPrefs from other projects
[SerializeField] string importCompanyName = "";
[SerializeField] string importProductName = "";

private void OnInspectorUpdate()
{
if (Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor)).Length == 0)
private void OnEnable()
{
Close();
importCompanyName = PlayerSettings.companyName;
importProductName = PlayerSettings.productName;
}
}

protected override bool DrawWizardGUI()
{
GUILayout.Label("Import PlayerPrefs from another project, also useful if you change product or company name", EditorStyles.wordWrappedLabel);
EditorGUILayout.Separator();
bool v = base.DrawWizardGUI();
return v;
}
private void OnInspectorUpdate()
{
if (Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor)).Length == 0)
{
Close();
}
}

private void OnWizardCreate()
{
if (Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor)).Length >= 1)
protected override bool DrawWizardGUI()
{
GUILayout.Label("Import PlayerPrefs from another project, also useful if you change product or company name", EditorStyles.wordWrappedLabel);
EditorGUILayout.Separator();
bool v = base.DrawWizardGUI();
return v;
}

private void OnWizardCreate()
{
((PlayerPrefsEditor)Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor))[0]).Import(importCompanyName, importProductName);
if (Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor)).Length >= 1)
{
((PlayerPrefsEditor)Resources.FindObjectsOfTypeAll(typeof(PlayerPrefsEditor))[0]).Import(importCompanyName, importProductName);
}
}
}
}
48 changes: 24 additions & 24 deletions Editor/Mac/Plist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// PlistCS Property List (plist) serialization and parsing library.
//
// https://github.com/animetrics/PlistCS
//
//
// Copyright (c) 2011 Animetrics Inc. (marc@animetrics.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -33,7 +33,7 @@
using System.Text;
using System.Xml;

namespace Sabresaurus.PlayerPrefsExtensions
namespace Sabresaurus.PlayerPrefsEditor
{
public static class Plist
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public static object readPlist(Stream stream, plistType type)
{
using (BinaryReader reader = new BinaryReader(stream))
{
byte[] data = reader.ReadBytes((int) reader.BaseStream.Length);
byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);
return readBinary(data);
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public static string writeXml(object value)

using (XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings))
{
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartDocument();
//xmlWriter.WriteComment("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
xmlWriter.WriteStartElement("plist");
Expand Down Expand Up @@ -186,7 +186,7 @@ public static byte[] writeBinary(object value)

offsetTable.Add(objectTable.Count - 8);

offsetByteSize = RegulateNullBytes(BitConverter.GetBytes(offsetTable[offsetTable.Count-1])).Length;
offsetByteSize = RegulateNullBytes(BitConverter.GetBytes(offsetTable[offsetTable.Count - 1])).Length;

List<byte> offsetBytes = new List<byte>();

Expand All @@ -206,7 +206,7 @@ public static byte[] writeBinary(object value)
objectTable.Add(Convert.ToByte(offsetByteSize));
objectTable.Add(Convert.ToByte(objRefSize));

var a = BitConverter.GetBytes((long) totalRefs + 1);
var a = BitConverter.GetBytes((long)totalRefs + 1);
Array.Reverse(a);
objectTable.AddRange(a);

Expand Down Expand Up @@ -321,11 +321,11 @@ private static object parse(XmlNode node)
case "string":
return node.InnerText;
case "integer":
// int result;
// int result;
//int.TryParse(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo, out result);
return Convert.ToInt32(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
case "real":
return Convert.ToDouble(node.InnerText,System.Globalization.NumberFormatInfo.InvariantInfo);
return Convert.ToDouble(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
case "false":
return false;
case "true":
Expand Down Expand Up @@ -569,7 +569,7 @@ private static byte[] composeBinary(object obj)

public static byte[] writeBinaryDate(DateTime obj)
{
List<byte> buffer =new List<byte>(RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)), 8));
List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)), 8));
buffer.Reverse();
buffer.Insert(0, 0x33);
objectTable.InsertRange(0, buffer);
Expand All @@ -585,8 +585,8 @@ public static byte[] writeBinaryBool(bool obj)

private static byte[] writeBinaryInteger(int value, bool write)
{
List<byte> buffer = new List<byte>(BitConverter.GetBytes((long) value));
buffer =new List<byte>(RegulateNullBytes(buffer.ToArray()));
List<byte> buffer = new List<byte>(BitConverter.GetBytes((long)value));
buffer = new List<byte>(RegulateNullBytes(buffer.ToArray()));
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
buffer.Add(0);
int header = 0x10 | (int)(Math.Log(buffer.Count) / Math.Log(2));
Expand All @@ -603,7 +603,7 @@ private static byte[] writeBinaryInteger(int value, bool write)

private static byte[] writeBinaryDouble(double value)
{
List<byte> buffer =new List<byte>(RegulateNullBytes(BitConverter.GetBytes(value), 4));
List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(value), 4));
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
buffer.Add(0);
int header = 0x20 | (int)(Math.Log(buffer.Count) / Math.Log(2));
Expand Down Expand Up @@ -852,7 +852,7 @@ public static object parseBinaryDate(int headerPosition)
DateTime result = PlistDateConverter.ConvertFromAppleTimeStamp(appleTime);
return result;
}

private static object parseBinaryInt(int headerPosition)
{
int output;
Expand All @@ -877,10 +877,10 @@ private static object parseBinaryReal(int headerPosition)
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
Array.Reverse(buffer);

// Sabresaurus Note: This wasn't producing the right results with doubles, needed singles anyway, so I
// added this line. (original line is commented out)
return BitConverter.ToSingle(buffer, 0);
// return BitConverter.ToDouble(RegulateNullBytes(buffer, 8), 0);
// Sabresaurus Note: This wasn't producing the right results with doubles, needed singles anyway, so I
// added this line. (original line is commented out)
return BitConverter.ToSingle(buffer, 0);
// return BitConverter.ToDouble(RegulateNullBytes(buffer, 8), 0);
}

private static object parseBinaryAsciiString(int headerPosition)
Expand All @@ -901,10 +901,10 @@ private static object parseBinaryUnicodeString(int headerPosition)
byte[] buffer = new byte[charCount];
byte one, two;

for (int i = 0; i < charCount; i+=2)
for (int i = 0; i < charCount; i += 2)
{
one = objectTable.GetRange(charStartPosition+i,1)[0];
two = objectTable.GetRange(charStartPosition + i+1, 1)[0];
one = objectTable.GetRange(charStartPosition + i, 1)[0];
two = objectTable.GetRange(charStartPosition + i + 1, 1)[0];

if (BitConverter.IsLittleEndian)
{
Expand All @@ -930,7 +930,7 @@ private static object parseBinaryByteArray(int headerPosition)

#endregion
}

public enum plistType
{
Auto, Binary, Xml
Expand Down
17 changes: 17 additions & 0 deletions Editor/PlayerPrefsEditor.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "PlayerPrefsEditor.Editor",
"references": [
"GUID:a478bb7e4764e7d4693af7f70e27dec8"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/PlayerPrefsEditor.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b9810c5

Please sign in to comment.