예제 #1
0
        //--------------------------------------------------------------//
        static XRTarget CreateXRTarget( MenuCommand menuCommand )
        //--------------------------------------------------------------//
        {

            BlockManager blockManager = AddBlockManagerIfNull();
            BlockGroup group = null;

            //If we have a GameObject for context, check if we can add a new BlockView to it directly
            if( menuCommand != null && menuCommand.context != null &&
                menuCommand.context.GetType() == typeof( GameObject ) )
            {
                //Is this a BlockManager?
                if( ( (GameObject)menuCommand.context ).GetComponent<BlockManager>() != null )
                {
                    //We are adding a BlockGroup to a BlockManager, check to see if there's a valid 3D BlockView available

                    //If there's no BlockViews available, let's add one now!
                    AddBlockViewSiblingsIfNull();

                    group = AddXRTargetToLatestBlockView();
                }

                //Is this a BlockView?
                else if( ( (GameObject)menuCommand.context ).GetComponent<BlockView>() != null )
                {
                    //We are adding a BlockGroup to a BlockView!
                    BlockView view = ( (GameObject)menuCommand.context ).GetComponent<BlockView>();
                    SetBlockViewToXRTarget( view );
                    group = view.AddBlockGroup();
                }

                //If this is a BlockGroup?
                else if( ( (GameObject)menuCommand.context ).GetComponent<BlockGroup>() != null )
                {
                    //We are adding a Nested BlockGroup to an existing BlockGroup!
                    group = AddNestedXRTargetBlockGroup( ( (GameObject)menuCommand.context ).GetComponent<BlockGroup>() );
                }

            }

            //We were unable to add the BlockGroup to the context, let's just add it to the most recent BlockView we can find
            if( group == null )
            {
                AddBlockViewSiblingsIfNull();
                group = AddXRTargetToLatestBlockView();
            }

            Debug.Log( "BXRCreateMenu.cs CreateXRTarget() Added XRTarget to " + group.transform.parent.name );

            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo( group.gameObject, "Create " + group.gameObject.name );
            Selection.activeObject = group.gameObject;

            return group.GetComponent<XRTarget>();

        } //END CreateXRTarget