【问题标题】:Cannot implicitly convert type `Steamworks.CSteamID' to `float'无法将类型“Steamworks.CSteamID”隐式转换为“float”
【发布时间】:2017-09-28 05:44:04
【问题描述】:

我目前正在使用带有 Unity3d 和 C# 的 Steamworks.net。我想做的是获取 Steam 用户 ID,在这种情况下是我自己的,然后执行一个函数。

这是我目前所拥有的:

private static float berdyevID = 76561198040013516;
private static float steamID;


void Start() {

    if(SteamManager.Initialized) {

        string name = SteamFriends.GetPersonaName();

        // get steam user id
        steamID = Steamworks.SteamUser.GetSteamID();

        // see if it matches
        if (berdyevID == steamID) {

            Debug.Log ("Steam ID did match");
        } else {

            Debug.Log ("Steam ID did not match");
        }


    }

}

我从 Unity 收到一条错误消息:

无法隐式转换类型Steamworks.CSteamID' tofloat'。存在显式转换(您是否缺少演员表?)

这让我很困惑。我尝试在谷歌上进行研究以找到可能的解决方法,但找不到任何东西。有人可以帮忙吗?

编辑

我试过了,但没用:

private static ulong berdyevID = 76561198040013516;
private static ulong steamID;

void Start() {

    if(SteamManager.Initialized) {

        string name = SteamFriends.GetPersonaName();

        // get steam user id
        steamID = Steamworks.SteamUser.GetSteamID();

        // see if it matches
        if (berdyevID == steamID) {

            Debug.Log ("Steam ID did match");
        } else {

            Debug.Log ("Steam ID did not match");
        }
    }
}

【问题讨论】:

    标签: c# unity3d steamworks-api


    【解决方案1】:

    您的GetSteamID() 返回一个Steamworks.CSteamID 类型的对象,该对象不可分配给float 类型的变量steamID

    CSteamID 结构中有一个名为m_SteamID 变量的ulong 变量。这就是 id 所在的位置。

    private static ulong berdyevID = 76561198040013516;
    private static ulong steamID;
    
    
    void Start() {
    
        if(SteamManager.Initialized) {
    
            string name = SteamFriends.GetPersonaName();
    
            // get steam user id
            steamID = Steamworks.SteamUser.GetSteamID().m_SteamID;
    
            // see if it matches
            if (berdyevID == steamID) {
    
                Debug.Log ("Steam ID did match");
            } else {
    
                Debug.Log ("Steam ID did not match");
            }
        }
    }
    

    【讨论】:

    • 好的.. 那我该怎么办?
    • 查看 api 并查看它如何从该类返回 id
    • @Programmer 很有趣,因为我已经尝试过 ulong 但它没有用。同样的错误,但显然是 ulong 而不是 float
    • 你试过 ulong。但是您是否尝试获取GetSteamID() 函数的m_SteamID 部分?
    • @Programmer 谢谢
    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多