Hi Jake,
I don't really know what Unity Editor alphasort means.
The empty nodes that my artist gave me are already sorted correctly when i brought them into Unity.
You second idea and link to other thread has given me the idea how to solve my problem. Thank you.
For everyone else benefit.
I have created a new menuItem (along the top of the menus) to clone the hierarchy of the gameObjects that represent the spline.
(sorry the formatting is out of wack. I have wrap it around a code tag but still not showing correctly).
I believe you can just paste the code any where in your code (within a Monobehaviour class, and include "using UnityEditor" at the top) and Unity will just picked it up.
(not 100% sure. it's the first time I did something with MenuItem).
Just found out I can just paste the code here. But my color scheme in MonoBehavour is dark, so the colors wont show up nicely here.
[MenuItem ("MyMenu/Create Curvy from GameOject")]
static void CreatCurvyFromGO()
{
// Get the active selected GameObject.
GameObject node = Selection.activeGameObject;
if (node != null)
{
// Get the number of children.
int childCount = node.transform.childCount;
if (childCount > 0)
{
// Create a new GameObject to host CurvySpline..
GameObject newSpline = new GameObject("Curvy "+node.name);
// Add CurvySpline to new GameObject
CurvySpline cs = newSpline.AddComponent<CurvySpline>;();
// Here you can apply some sorting here if required.
// My nodes already sorted correctly, so no sorting is required for me.
for (int i=0; i<childCount; i++)
{
Transform trans = node.transform.GetChild(i);
CurvySplineSegment css = cs.Add();
css.transform.position = trans.position;
css.transform.rotation = trans.rotation;
}
}
else
{
Debug.Log ("There is no child. No curvy spline created.");
}
}
else
{
Debug.Log ("There is no GameObject selected. No curvy spline created.");
}
}
I don't really know what Unity Editor alphasort means.
The empty nodes that my artist gave me are already sorted correctly when i brought them into Unity.
You second idea and link to other thread has given me the idea how to solve my problem. Thank you.
For everyone else benefit.
I have created a new menuItem (along the top of the menus) to clone the hierarchy of the gameObjects that represent the spline.
Code:
[MenuItem ("MyMenu/Create Curvy from GameOject")]
static void CreatCurvyFromGO()
{
// Get the active selected GameObject.
GameObject node = Selection.activeGameObject;
if (node != null)
{
// Get the number of children.
int childCount = node.transform.childCount;
if (childCount > 0)
{
// Create a new GameObject to host CurvySpline..
GameObject newSpline = new GameObject("Curvy "+node.name);
// Add CurvySpline to new GameObject
CurvySpline cs = newSpline.AddComponent<CurvySpline>;();
// Here you can apply some sorting here if required.
// My nodes already sorted correctly, so no sorting is required for me.
for (int i=0; i<childCount; i++)
{
Transform trans = node.transform.GetChild(i);
CurvySplineSegment css = cs.Add();
css.transform.position = trans.position;
css.transform.rotation = trans.rotation;
}
}
else
{
Debug.Log ("There is no child. No curvy spline created.");
}
}
else
{
Debug.Log ("There is no GameObject selected. No curvy spline created.");
}
}
I believe you can just paste the code any where in your code (within a Monobehaviour class, and include "using UnityEditor" at the top) and Unity will just picked it up.
(not 100% sure. it's the first time I did something with MenuItem).
Just found out I can just paste the code here. But my color scheme in MonoBehavour is dark, so the colors wont show up nicely here.
[MenuItem ("MyMenu/Create Curvy from GameOject")]
static void CreatCurvyFromGO()
{
// Get the active selected GameObject.
GameObject node = Selection.activeGameObject;
if (node != null)
{
// Get the number of children.
int childCount = node.transform.childCount;
if (childCount > 0)
{
// Create a new GameObject to host CurvySpline..
GameObject newSpline = new GameObject("Curvy "+node.name);
// Add CurvySpline to new GameObject
CurvySpline cs = newSpline.AddComponent<CurvySpline>;();
// Here you can apply some sorting here if required.
// My nodes already sorted correctly, so no sorting is required for me.
for (int i=0; i<childCount; i++)
{
Transform trans = node.transform.GetChild(i);
CurvySplineSegment css = cs.Add();
css.transform.position = trans.position;
css.transform.rotation = trans.rotation;
}
}
else
{
Debug.Log ("There is no child. No curvy spline created.");
}
}
else
{
Debug.Log ("There is no GameObject selected. No curvy spline created.");
}
}