Ich habe 2 Warnungen. Es ist nicht so, dass ich das Spiel nicht ausführen kann, aber wie kann ich die Warnungen beheben?Wie kann ich 2 Warnungen beheben, die ich in einem Skript bekomme? Warnungen sollten behoben werden?
Die erste Warnung ist:
Assets/My Scripts/Ai_Scripts/Editor/Editor.cs (56,26): Warnung CS0618: UnityEditor.EditorGUIUtility.LookLikeControls()' is obsolete:
LookLikeControls und LookLikeInspector Modi sind veraltet. Verwenden Sie EditorGUIUtility.labelWidth und EditorGUIUtility.fieldWidth, um die Breite von Beschriftungen und Feldern zu steuern. '
Die Linie ist:
EditorGUIUtility.LookLikeControls();
Was soll ich die Linie zu ändern? Was bedeutet es, EditorGUIUtility.labelWidth und EditorGUIUtility.fieldWidth zu verwenden? Wie benutze ich beides?
Der zweite Fehler ist identisch mit dem ersten nur in einem anderen Teil im Skript.
Die Warnung in dieser Methode:
//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();
}
Bitte geben Sie mehr Kontext, zeigen Sie uns die Methode, die die Warnung auch passiert. –
Kommentieren Sie die Zeilen und sehen Sie den Unterschied in Ihrem benutzerdefinierten Editor. Wenn es Ihnen gut aussieht, entfernen Sie die Linien dauerhaft. Wenn dies nicht der Fall ist, passen Sie 'labelWidth' und' fieldWidth' manuell an Ihre Präferenz an. – EvilTak