コード例 #1
0
        protected virtual void WriteGettersAndSetters(List <string> keys, IndentedTextWriter outFile)
        {
            outFile.Indent++;
            outFile.WriteLine("#region GET AND SET");
            outFile.WriteLine();

            foreach (string k in keys)
            {
                System.Type type = System.Type.GetType(QuickPlayerPrefs.GetSetting(k).GetTypeName());
                if (type == null)
                {
                    type = typeof(string);
                }

                string typeName;
                if (type == typeof(string))
                {
                    typeName = "string";
                }
                else if (type == typeof(int))
                {
                    typeName = "int";
                }
                else if (type == typeof(float))
                {
                    typeName = "float";
                }
                else if (type == typeof(bool))
                {
                    typeName = "bool";
                }
                else
                {
                    typeName = QuickUtils.GetTypeFullName(type);
                }

                //The getter
                outFile.WriteLine("public static " + typeName + " Get" + k + "()");
                outFile.WriteLine("{");
                outFile.Indent++;
                if (type == typeof(string))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetString(\"" + k + "\");");
                }
                else if (type == typeof(int))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetInt(\"" + k + "\");");
                }
                else if (type == typeof(float))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetFloat(\"" + k + "\");");
                }
                else if (type == typeof(bool))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetBool(\"" + k + "\");");
                }
                else if (type.IsEnum)
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetEnum<" + typeName + ">(\"" + k + "\");");
                }
                outFile.Indent--;
                outFile.WriteLine("}");

                outFile.WriteLine();

                //The setter
                outFile.WriteLine("public static void Set" + k + "(" + typeName + " value)");
                outFile.WriteLine("{");
                outFile.Indent++;
                outFile.WriteLine("QuickPlayerPrefs.SetValue(\"" + k + "\", value);");
                outFile.Indent--;
                outFile.WriteLine("}");

                outFile.WriteLine();
            }

            outFile.WriteLine("#endregion");
            outFile.Indent--;
        }