Skip to content

Instantly share code, notes, and snippets.

@sfszh
Created August 8, 2013 08:58
Show Gist options
  • Save sfszh/6182937 to your computer and use it in GitHub Desktop.
Save sfszh/6182937 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
/**
* originally by buffonomics
* originally posted on: http://forum.unity3d.com/threads/77444-How-to-create-new-GameObject-as-child-in-hierarchy
*/
public class SmartCreate : MonoBehaviour {
[MenuItem("GameObject/Create Empty Parent #&e")]
static void createEmptyParent() {
GameObject go = new GameObject("GameObject");
if (Selection.activeTransform != null) {
go.transform.parent = Selection.activeTransform.parent;
go.transform.Translate(Selection.activeTransform.position);
go.transform.localPosition = new Vector3(0, 0, 0);
go.transform.localScale = new Vector3(1, 1, 1);
go.transform.localRotation = new Quaternion(0, 0, 0, 1);
Selection.activeTransform.parent = go.transform;
}
}
[MenuItem("GameObject/Create Empty Duplicate #&d")]
static void createEmptyDuplicate() {
GameObject go = new GameObject("GameObject");
if (Selection.activeTransform != null) {
go.transform.parent = Selection.activeTransform.parent;
go.transform.Translate(Selection.activeTransform.position);
}
}
[MenuItem("GameObject/Create Empty Child #&c")]
static void createEmptyChild() {
GameObject go = new GameObject("GameObject");
if (Selection.activeTransform != null) {
go.transform.parent = Selection.activeTransform;
go.transform.Translate(Selection.activeTransform.position);
go.transform.localPosition = new Vector3(0, 0, 0);
go.transform.localScale = new Vector3(1, 1, 1);
go.transform.localRotation = new Quaternion(0, 0, 0, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment