gpt4 book ai didi

c# - 错误 CS0246 : The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?)

转载 作者:行者123 更新时间:2023-12-05 01:50:21 25 4
gpt4 key购买 nike

我在尝试编写此脚本以在我的游戏中保存和加载时遇到这些错误。

Assets\Scripts\Save System\SaveData.cs(62,40): error CS0246: The typeor namespace name 'StreamingContext' could not be found (are youmissing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveData.cs(13,31): error CS0246: The typeor namespace name 'PlaceableObjectData' could not be found (are youmissing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveData.cs(61,6): error CS0246: The typeor namespace name 'OnDeserializedAttribute' could not be found (areyou missing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveData.cs(61,6): error CS0246: The typeor namespace name 'OnDeserialized' could not be found (are you missinga using directive or an assembly reference?)

这是我正在处理的脚本:

    using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization;


[Serializable]

public class SaveData
{
public static int IdCount;

public Dictionary<string, PlaceableObjectsData> placeableObjectDatas =
new Dictionary<string, PlaceableObjectsData>();

public static string GenerateId()
{
IdCount++;
return IdCount.ToString();

}

public void AddData(Data data)
{
if (data is placeableObjectDatas plObjData)

{

if (placeableObjectDatas.ContainsKey(plObjData.ID))
{
placeableObjectDatas[plObjData.ID] = plObjData;

}
else

{
placeableObjectDatas.Add(plObjData.ID, plObjData);
}

}

}

public void RemoveData(Data data)
{

if (data is placeableObjectDatas plObjData)

{

if (placeableObjectDatas.ContainsKey(plObjData.ID))
{
placeableObjectDatas.Remove(plObjData.ID);

}

}

}

[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
placeableObjectDatas ??= new Dictionary<string, PlaceableObjectsData>();

}

}

编辑:

这是 PlaceableObjectData 的脚本:

using System;
using UnityEngine;



public class PlaceableObjectsData : Data
{
public string assetName;
public Vector3 position;
}

编辑 2

Assets\Scripts\Save System\SaveSystem.cs(17,13): error CS0103: Thename 'Directory' does not exist in the current context

Assets\Scripts\Save System\SaveSystem.cs(20,13): error CS0103: Thename 'Directory' does not exist in the current context

Assets\Scripts\Save System\SaveData.cs(26,21): error CS0246: The typeor namespace name 'placeableObjectDatas' could not be found (are youmissing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveSystem.cs(31,28): error CS0246: Thetype or namespace name 'JsonSerializerSettings' could not be found(are you missing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveSystem.cs(32,42): error CS0103: Thename 'ReferenceLoopHandling' does not exist in the current context

Assets\Scripts\Save System\SaveSystem.cs(34,29): error CS0103: Thename 'JsonConvert' does not exist in the current context

Assets\Scripts\Save System\SaveSystem.cs(36,19): error CS1061:'string' does not contain a definition for 'WriteAllText' and noaccessible extension method 'WriteAllText' accepting a first argumentof type 'string' could be found (are you missing a using directive oran assembly reference?)

Assets\Scripts\Save System\SaveData.cs(48,21): error CS0246: The typeor namespace name 'placeableObjectDatas' could not be found (are youmissing a using directive or an assembly reference?)

Assets\Scripts\Save System\SaveSystem.cs(42,22): error CS1061:'string' does not contain a definition for 'Exists' and no accessibleextension method 'Exists' accepting a first argument of type 'string'could be found (are you missing a using directive or an assemblyreference?)

Assets\Scripts\Save System\SaveSystem.cs(45,42): error CS1061:'string' does not contain a definition for 'ReadAllText' and noaccessible extension method 'ReadAllText' accepting a first argumentof type 'string' could be found (are you missing a using directive oran assembly reference?)

Assets\Scripts\Save System\SaveSystem.cs(47,13): error CS0246: Thetype or namespace name 'saveData' could not be found (are you missinga using directive or an assembly reference?)

Assets\Scripts\Save System\SaveSystem.cs(47,31): error CS0103: Thename 'JsonConvert' does not exist in the current context

Assets\Scripts\Save System\SaveSystem.cs(47,61): error CS0246: Thetype or namespace name 'saveData' could not be found (are you missinga using directive or an assembly reference?)

最佳答案

您可以通过在文件顶部添加 using System.Runtime.Serialization; 来修复错误 1、3 和 4。

但我从未听说过 PlaceableObjectData,它可能是您在其他命名空间中创建的自定义类吗?然后,您还必须使用 using 关键字导入该命名空间。

关于c# - 错误 CS0246 : The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73250763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com