我有 2 个警告。并不是我无法运行游戏,而是我该如何修复警告?
第一个警告是:
Assets/My Scripts/Ai_Scripts/Editor/Editor.cs(56,26):警告 CS0618:
LookLikeControls 和 LookLikeInspector 模式已弃用。使用 EditorGUIUtility.labelWidth 和 EditorGUIUtility.fieldWidth 来控制标签和字段宽度。'UnityEditor.EditorGUIUtility.LookLikeControls()' is obsolete:
线路是:
EditorGUIUtility.LookLikeControls();
我应该将线路更改为什么?使用 EditorGUIUtility.labelWidth 和 EditorGUIUtility.fieldWidth 是什么意思?我如何同时使用两者?
第二个错误与第一个错误相同,只是在脚本的另一部分。
此方法中的警告:
//called whenever the inspector gui gets rendered
public override void OnInspectorGUI()
{
//this pulls the relative variables from unity runtime and stores them in the object
//always call this first
m_Object.Update();
//show default iMove.cs public variables in inspector
DrawDefaultInspector();
//get Path Manager component by calling method GetWaypointArray()
var path = GetPathTransform();
EditorGUILayout.Space();
//make the default styles used by EditorGUI look like controls
EditorGUIUtility.LookLikeControls();
//display custom float input field to change value of variable "sizeToAdd"
EditorGUILayout.PropertyField(m_Size);
//draw bold delay settings label
GUILayout.Label("Delay Settings:", EditorStyles.boldLabel);
//check whether a Path Manager component is set, if not display a label
if (path == null)
{
GUILayout.Label("No path set.");
//get StopAtPoint array count from serialized property and resize it to zero
//(in case of previously defined delay settings, clear old data)
m_Object.FindProperty(spArraySize).intValue = 0;
}
//path is set and boolean for displaying delay settings is true
//(button below was clicked)
else if (showDelaySetup)
{
//get StopAtPoint array reference by calling method GetStopPointArray()
var stopPoints = GetStopPointArray();
EditorGUILayout.BeginHorizontal();
//begin a scrolling view inside GUI, pass in Vector2 scroll position
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(105));
//loop through waypoint array
for (int i = 0; i < path.waypoints.Length; i++)
{
GUILayout.BeginHorizontal();
//draw label with waypoint index,
//increased by one (so it does not start at zero)
GUILayout.Label((i + 1) + ".", GUILayout.Width(20));
//create a float field for every waypoint delay slot
var result = EditorGUILayout.FloatField(stopPoints[i], GUILayout.Width(50));
//if the float field has changed, set waypoint delay to new input
//(within serialized StopAtPoint array property)
if (GUI.changed)
SetPointDelay(i, result);
GUILayout.EndHorizontal();
}
//ends the scrollview defined above
EditorGUILayout.EndScrollView();
EditorGUILayout.BeginVertical();
//draw button for hiding of delay settings
if (GUILayout.Button("Hide Delay Settings"))
{
showDelaySetup = false;
}
//draw button to set all delay value slots to the value specified in "delayAll"
if (GUILayout.Button("Set All:"))
{
//loop through all delay slots, call SetPointDelay() and pass in "delayAll"
for (int i = 0; i < stopPoints.Length; i++)
SetPointDelay(i, delayAll);
}
//create a float field for being able to change variable delayAll
delayAll = EditorGUILayout.FloatField(delayAll, GUILayout.Width(50));
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
else
{
if (GUILayout.Button("Show Delay Settings"))
{
showDelaySetup = true;
}
}
m_Object.ApplyModifiedProperties();
}
您收到警告是因为
LookLikeControls()
已过时。使用 EditorGUIUtility.labelWidth
和 EditorGUIUtility.fieldWidth
来控制标签和字段宽度。