统一成员修饰符必须在公共之前 [英] unity member modifier public must precede

查看:176
本文介绍了统一成员修饰符必须在公共之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们在此站点上向我提出了这个问题,但是没有一个是真正的问题.我确定我在检查代码时可能错过了一些东西,但是我无法确定弄清楚它是什么.现在,Unity困扰着我,据说我没有将 public 修饰符放在正确的位置,即使它正好位于我所看到的位置.

People have asked this before me on this site, but none of them are really the same issue. I'm sure that I probably missed something when I checked my code but I can't figure out what it is. Now Unity is bugging me about me supposedly not putting the public modifier in the right spot even though it's exactly where it should be, from what I'm seeing.

让我向您展示真实的速度...

Let me show you real quick...

Unity返回给我的错误:

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


我的代码(我有点发疯了,在这里发布了这么长的代码,只是忽略那些显然我懒得删除的注释.这是在我进一步开发时使用的.)


My code (I'm kinda insane to post this long chunk here, just ignore those comments that I'm obviously too lazy to delete. That's for when I get further in development.)

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" 修饰符?

So in this situation here, how come Unity starts going nuts asking me to add a "public" modifier where there already is one?

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

And if I missed something then let me know.

谢谢.

推荐答案

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

Let's reformat your code to be easier to read:

....
[ComVisibleAttribute(true)]
public sealed class FileIOPermission
{
}

(AllAccess View, string MyDocuments) // Grants access to the User's Documents folder.

public class saveFiles : MonoBehaviour {
....

现在可以看到问题了吗?

Can you see the problem now?

(AllAccess View, string MyDocuments)不在任何类中,因此编译器试图弄清楚这是什么意思,并且认为您正在尝试声明一个类,接口或枚举,并且最好猜测是您丢失了修饰符.

(AllAccess View, string MyDocuments) is not in any class, so the compiler is trying to figure out what that means, and it thinks you are trying to declare a class or an interface or an enum, and it's best guess is that you are missing a modifier.

在我看来,您好像是错误地从其他地方复制并粘贴了此行.您应该将其删除.

it looks to me like you have copied and pasted this line by mistake from somewhere else. You should remove it.

这篇关于统一成员修饰符必须在公共之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆