Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            var hiddenValue = prop.FindPropertyRelative("hiddenValue");

            var cryptoKey       = prop.FindPropertyRelative("currentCryptoKey");
            var inited          = prop.FindPropertyRelative("inited");
            var fakeValue       = prop.FindPropertyRelative("fakeValue");
            var fakeValueActive = prop.FindPropertyRelative("fakeValueActive");

            var currentCryptoKey = cryptoKey.intValue;
            var val = 0;

            if (!inited.boolValue)
            {
                if (currentCryptoKey == 0)
                {
                    currentCryptoKey = cryptoKey.intValue = ObscuredInt.GenerateKey();
                }
                hiddenValue.intValue = ObscuredInt.Encrypt(0, currentCryptoKey);
                inited.boolValue     = true;
            }
            else
            {
                val = ObscuredInt.Decrypt(hiddenValue.intValue, currentCryptoKey);
            }

            label = EditorGUI.BeginProperty(position, label, prop);

            EditorGUI.BeginChangeCheck();
            val = EditorGUI.IntField(position, label, val);
            if (EditorGUI.EndChangeCheck())
            {
                hiddenValue.intValue      = ObscuredInt.Encrypt(val, currentCryptoKey);
                fakeValue.intValue        = val;
                fakeValueActive.boolValue = true;
            }
            EditorGUI.EndProperty();
        }