码迷,mamicode.com
首页 > 其他好文 > 详细

AddParent

时间:2014-06-07 00:36:56      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class AddParent : ScriptableObject
{
    [MenuItem ("GameObject/+Add Parent")]
    static void MenuInsertParent()
    {
        Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel |
            SelectionMode.OnlyUserModifiable);
 
        GameObject newParent = new GameObject("_Parent");
        Transform newParentTransform = newParent.transform;
 
        if(transforms.Length == 1)
        {
            Transform originalParent = transforms[0].parent;
            transforms[0].parent = newParentTransform;
            if(originalParent)
                newParentTransform.parent = originalParent;
        }
        else
        {
            foreach(Transform transform in transforms)
                transform.parent = newParentTransform;
        }
    }
}
bubuko.com,布布扣

 

AddParent,布布扣,bubuko.com

AddParent

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/softimagewht/p/3765397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!