I made a window to create a scriptable object and export it into the venture folder like Belongings
.
And I need to add an array to the scriptable object to retailer some knowledge in it; for instance, path factors knowledge from one level on a map to a different.
And I added the array, however I must divide the trail properties to cut back file house as a result of there’s generally unused info like if the consumer would not want the velocity restrict knowledge or road names.
Due to this fact, the concept of dividing the struct will make the file smaller in house in response to the knowledge that the consumer needs.
My drawback is that after I divided the trail properties, this resulted 3 structs for representing a path level, resembling:
- struct for the situation.
- struct for the situation and road identify.
- struct for the situation, road identify, and velocity restrict in KM.
What I want is a approach to decide the suitable struct for the array and learn how to deal with the identical creation course of with “MapManager” features that be used so as to add info to the PathPointData struct (that’s the struct that I need to divide).
Notice: I’ve two toggles within the window: one to incorporate the road identify and one other to incorporate the velocity restrict.
PathFile: (The scriptable object which have the trail factors array)
public class PathFile : ScriptableObject
{
public PathPointData[] Path;
Vector2 GetNextPathPointLocation(int NextPointIndex)
{
return Path[NextPointIndex].Location;
}
string GetPathPointStreetName(int PointIndex)
{
return Path[PointIndex].StreetName;
}
string GetPathPointSpeedLimit(int PointIndex)
{
float Path[PointIndex].SpeedLimit;
}
}
The code that I made for making and exporting the scriptable Object within the window editor script:
personal void OnCreatePathButtonClicked(ClickEvent evt)
{
PathFile path = CreatePathFile();
CheckExportInfo();
if (!_locationTextField.worth.EndsWith("/"))
{
_locationTextField.worth += "/";
}
if (!Listing.Exists(_locationTextField.worth))
{
Listing.CreateDirectory(_locationTextField.worth);
}
string finalPath = _locationTextField.worth + $"{_nameTextField.worth}.asset";
finalPath = AssetDatabase.GenerateUniqueAssetPath(finalPath);
AssetDatabase.CreateAsset(PathFile, finalPath);
CheckExportResult(finalPath);
}
PathFile CreatePathFile()
{
PathFile path = CreateInstance();
path.Description = _descriptionTextField.worth;
path.mapPath = MapManager.GetPath(_startPoint, _endPoint);
if (_includeStreetNames)
{
path.mapPath = MapManager.GetStreetNames(path.mapPath);
}
if (_includeSpeedLimit)
{
path.mapPath = MapManager.GetSpeedLimit(path.mapPath);
}
return path;
}
PathPointData Struct: (Which I must divide)
utilizing System;
[Serializable]
public struct PathPointData
{
public Vector2 Location;
public string StreetName;
public float SpeedLimit;
}
MapManager features: (Through which particular knowledge is modified inside a array and return the array after setting the needed knowledge)
Public static PathPointData[] GetPath(Level begin, Level finish)
{
PathPointData[] pathPoints = new PathPointData[distanceToPointes(start, end)];
for (int i = 0; i