using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using EasyRoads3Dv3;
using EasyRoads3Dv3Editor;
public class ERAPIEditor : ScriptableObject {
[MenuItem( "EasyRoads3D/Custom Road Shape" )]
public static void RefreshRoad()
{
ERRoad road = EREditor.GetSelectedRoad();
if(road != null){
List<Vector2> shape = new List<Vector2>();
List<float> uv = new List<float>();
List<bool> tris = new List<bool>();
shape.Add(new Vector2(3f,0f));
uv.Add(1f);
tris.Add(true);
shape.Add(new Vector2(2.9f,0.05f));
uv.Add(0.99f);
tris.Add(true);
shape.Add(new Vector2(0f,0.1f));
uv.Add(0.5f);
tris.Add(true);
shape.Add(new Vector2(-2.9f,0.05f));
uv.Add(0.01f);
tris.Add(true);
shape.Add(new Vector2(-3f,0f));
uv.Add(0f);
tris.Add(true);
road.roadScript.roadShape = new List<Vector2>(shape);
road.roadScript.roadShapeUVs = new List<float>(uv);
road.roadScript.doConnectionTri = new List<bool>(tris);
road.roadScript.isCustomRoad = true;
foreach(ERMarkerExt m in road.roadScript.markersExt){
m.roadShape = new List<Vector2>(shape);
}
road.Refresh();
}else{
Debug.Log("Please select a road object first");
}
Debug.Log("done");
}
}
Thats the script. You can see the variables in how it adds the Vector2.
EDIT: also, I think the file I posted has the comments removed, but you need to remove the comments before using
EasyRoads3Dv3;
using EasyRoads3Dv3Editor;
I removed them in the script above.
EDIT2: Ok with the help of Shimonko, he helped me understand the script.
So with the script above the following is the graphic Shimonko gave me to help understand the road.
![unknown.png](https://cdn.discordapp.com/attachments/364886990493319168/448616604088008715/unknown.png)
And here is a sketchup I did to show how the variables are linked, its not pretty but helps me understand it.
![unknown.png](https://cdn.discordapp.com/attachments/364886990493319168/448617175993942026/unknown.png)
And then even with that great explanation and thinking I understood it, I still managed to mess it up but Shimonko was patient and helped me with it.
Here is the modified code that will work for cart paths that are 3 wide like mine.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using EasyRoads3Dv3;
using EasyRoads3Dv3Editor;
public class ERAPIEditor : ScriptableObject {
[MenuItem( "EasyRoads3D/Custom Road Shape" )]
public static void RefreshRoad()
{
ERRoad road = EREditor.GetSelectedRoad();
if(road != null){
List<Vector2> shape = new List<Vector2>();
List<float> uv = new List<float>();
List<bool> tris = new List<bool>();
shape.Add(new Vector2(1.5f,0f));
uv.Add(1f);
tris.Add(true);
shape.Add(new Vector2(1.4f,0.1f));
uv.Add(0.99f);
tris.Add(true);
shape.Add(new Vector2(0f,0.1f));
uv.Add(0.5f);
tris.Add(true);
shape.Add(new Vector2(-1.4f,0.1f));
uv.Add(0.01f);
tris.Add(true);
shape.Add(new Vector2(-1.5f,0f));
uv.Add(0f);
tris.Add(true);
road.roadScript.roadShape = new List<Vector2>(shape);
road.roadScript.roadShapeUVs = new List<float>(uv);
road.roadScript.doConnectionTri = new List<bool>(tris);
road.roadScript.isCustomRoad = true;
foreach(ERMarkerExt m in road.roadScript.markersExt){
m.roadShape = new List<Vector2>(shape);
}
road.Refresh();
}else{
Debug.Log("Please select a road object first");
}
Debug.Log("done");
}
}
I personally like the thicker road look and it should provide more forgiveness from floating roads that can happen with EasyRoads.
Some more pics: path with spline off:
![unknown.png](https://cdn.discordapp.com/attachments/364886990493319168/448706613830877185/unknown.png)
Path with spline on:
![unknown.png](https://cdn.discordapp.com/attachments/364886990493319168/448707281400365056/unknown.png)
A great view of what this script actually does (you will notice shimonko's drawing mimics this).
![unknown.png](https://cdn.discordapp.com/attachments/364886990493319168/448706899924221952/unknown.png)
NOTE: I think it causes trouble with pefab connnections, so depending on how you do your connections (I don't use connectors yet).
Matt, I think this will work with free version of v3.0. I don't see why it wouldn't. Let me know if you have any questions. Please note I am still a rookie with unity, CF, and easyroads.