统一成员修饰语公共必须先于

时间:2018-05-31 20:27:51

标签: c# debugging unity3d c#-4.0

我已经解决了这个问题,但是当事情变得更加疯狂时,我意识到尝试实现这个目标是多么愚蠢,因为它最终显然没有任何好处。

如果你有类似的问题,请随意查看这个问题,也许你会学到一两件事。 Idk¯\ _(ツ)_ /¯

人们在我这个网站上问过这个问题,但没有一个问题真的是同一个问题。我确定我在检查代码时可能会遗漏一些但是我无法想象它是什么。现在Unity正在困扰我,据说我不会把公共修饰符放在正确的位置,即使它正是应该的位置,从我所看到的。

让我快点告诉你......

Unity返回给我的错误:

Assets\saveFiles.cs(15,1): error CS1585: Member modifier 'public' must precede the member type and name

我的代码(我在这里发布这个长篇大论有点疯狂,只是忽略那些我显然懒得删除的评论。这就是我进一步开发的时候。)< / p>

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Security.Permissions; // Allows permission requests from within         script. VERY IMPORTANT.
using System.Security.AccessControl; // Also as important for the same reason.

[ComVisibleAttribute(true)]
public sealed class FileIOPermission{}(AllAccess View, string MyDocuments) // Grants access to the User's Documents folder.

public class saveFiles : MonoBehaviour {
    [DllImport("System.Windows.Forms.dll")]
    private static extern void SystemWindows();
    [DllImport("System.Drawing.dll")]
    private static extern void SystemDrawing();

    public string MyDocuments = System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) );

    // Reserve these variables for save file memory.
        public string UserData;
        public string UserConfig;
        public bool IsUserAvailable;

    void Start () {
        // On game execution, check for the game's configuration files. Load if they exist, save blank ones if they don't.
        // (Don't save in the Steam client's user data directory until you are aware of a way to find which user is logged into Steam.)

    // Check for saved progress and load it into memory if available. If not, it creates one and prepares it for editing.
        if(System.IO.File.Exists(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav") == true) {
            UserData = System.IO.File.ReadAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav");
        } else {
            System.IO.File.Create(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav");
            UserData = "statsA{\"xp\" : 0, \"money\" : 2000, \"MatchInProgress\" : false} Inventory{\"Default\":1;} loadout{1 null null null null}";
            System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav", UserData);
            // Rules for UserData string:
            //      Inventory is stored as: "[ItemTag string]:[QuantityOfItem integer];"
            //
            //    Optionally, you can add extra info about the item from within a parentheses, placed after [ItemTag]. Useful for upgrades and equipment, leveling up, etc.
            //     (e.g. "Default(  [JSON METADATA]  ):1;")
            //
            //      Anything in quotes is a string, otherwise it is an integer or a boolean value depending on the returned value.
            //  (e.g. 24 as an integer, true/false/null as a boolean)
            //
            //      Loadout section is stored as 5 different inventory slot numbers, seperated by spaces.
            //  Each number represents which item listing, counting from the start to the end of the Inventory string.
            //  (e.g. "Inventory{weaponA:1;weaponB:1;weaponC:1;weaponD:1;} loadout{1 3 4 null null}" 
            //  will return WeaponA in slot 1, weaponC in slot 2, weaponD in slot 3, and slots 4 and 5 empty)
            //
            //      Majority of user save data will use JSON format or one of a similar syntax.
            //      (This applies to pretty much 100% of the settings file.)
        }

    // Check for user settings and load it into memory if available. If not, it creates one and prepares it for editing.
        if(System.IO.File.Exists(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg") == true){
            UserConfig = System.IO.File.ReadAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg");
        } else {
            System.IO.File.Create(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg");
        };
    }
    public void saveUsr() {
        // Code for Windows Standalone:
        System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav", UserData);
        System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg", UserConfig);
    }

}

所以在这种情况下,为什么Unity开始疯狂地要求我添加一个“public”修饰符,哪里有一个?

如果我错过了什么,请告诉我。

谢谢。

1 个答案:

答案 0 :(得分:0)

让我们重新格式化您的代码以便于阅读:

[
    "Paragraphs are separated by a blank line.\n2nd paragraph. *Italic*, **bold**, and `monospace`.\n\nItemized lists look like:",
    "{% for (item in items) %}\n* {{ item }}",
    "{% endfor %}\n"
]

你现在能看到问题吗?

.... [ComVisibleAttribute(true)] public sealed class FileIOPermission { } (AllAccess View, string MyDocuments) // Grants access to the User's Documents folder. public class saveFiles : MonoBehaviour { .... 不在任何类中,因此编译器试图弄清楚这意味着什么,并且它认为您正在尝试声明类或接口或枚举,并且它是最好的猜测你错过了修饰语。

它让我觉得你已经错误地从其他地方复制并粘贴了这一行。你应该删除它。