gpt4 book ai didi

c# - 我不断收到异常功能 `interpolated strings' 无法使用,因为它不是 C# 4.0 语言的一部分?

转载 作者:行者123 更新时间:2023-11-30 20:15:55 25 4
gpt4 key购买 nike

首先,我在 visual studio 中遇到了异常错误。所以我点击了有错误的行并选择修复它以将 visual studio 目标更改为 csharp 6

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class PrefabReplace : EditorWindow
{
[SerializeField] private GameObject prefab;

[MenuItem("Tools/Prefab Replace")]
static void CreateReplaceWithPrefab()
{
EditorWindow.GetWindow<PrefabReplace>();
}

private void OnGUI()
{
prefab = (GameObject)EditorGUILayout.ObjectField("Prefab", prefab, typeof(GameObject), false);

if (GUILayout.Button("Replace"))
{
var selection = Selection.gameObjects.ToList();

if (prefab != null && selection.Count > 0)
{
for (var i = selection.Count - 1; i >= 0; --i)
{
var selected = selection[i];
var prefabType = PrefabUtility.GetPrefabType(prefab);
GameObject newObject;

if (prefabType == PrefabType.Prefab)
{
newObject = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
}
else
{
newObject = Instantiate(prefab);
newObject.name = prefab.name;
}

if (newObject == null)
{
Debug.LogError("Error instantiating prefab");
break;
}

Undo.RegisterCreatedObjectUndo(newObject, "Replace With Prefabs");
newObject.transform.parent = selected.transform.parent;
newObject.transform.localPosition = selected.transform.localPosition;
newObject.transform.localRotation = selected.transform.localRotation;
newObject.transform.localScale = selected.transform.localScale;
newObject.transform.SetSiblingIndex(selected.transform.GetSiblingIndex());
Undo.DestroyObjectImmediate(selected);
}
}
}

if (GUILayout.Button("Copy settings"))
{
var selection = Selection.gameObjects.ToList();

for (int i = selection.Count - 1; i >= 0; --i)
{
var selected = selection[i].transform;
string toWrite = $"{selected.parent}:{selected.localPosition}:{selected.localRotation}:{selected.localScale}";
WriteDataToFile(toWrite);
}
}

GUI.enabled = false;
EditorGUILayout.LabelField("Selection count: " + Selection.objects.Length);
}

private void OnInspectorUpdate()
{
Repaint();
}

private void WriteDataToFile(string line)
{
string path = "Assets/Resources/test.txt";
string[] text = new string[4];
if (File.Exists(path))
{
text = File.ReadAllLines(path);
if (!text.Contains(line))
File.AppendAllText(path, line);
}
}
}

错误出现在 visual studio 中的这一行:

string toWrite = $"{selected.parent}:{selected.localPosition}:{selected.localRotation}:{selected.localScale}";
WriteDataToFile(toWrite);

现在错误从 visual studio 中消失了,我可以毫无问题地构建它,但是在 unity 编辑器中,异常仍然存在于控制台中,单击清除按钮并没有删除它:

Exception in editor

最佳答案

您必须在编辑器中启用 .NET 4.x 才能使用内插字符串。功能。

转到编辑 --> 项目设置 --> 播放器 --> 其他设置 --> 配置 --> 脚本运行时版本 --> .NET 4.x 等效

关于c# - 我不断收到异常功能 `interpolated strings' 无法使用,因为它不是 C# 4.0 语言的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51851507/

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