Пример #1
0
        } //END AddBlockViewToNestedGroups

        //---------------------------------//
        private void CheckIfWeShouldCreateNewBlockView()
        //---------------------------------//
        {
            //If we couldn't find a BlockView earlier, then there's something wrong!
            //Take this BlockGroup and all of its children, and parent it to a new BlockView that
            //will be attached to the BlockManager's 3D Camera
            if( blockView == null )
            {
                bool createBlockView = false;

                //Create a BlockView parent if this BlockGroup is not a child of another BlockGroup,
                if( this.transform.parent != null && 
                    transform.parent.GetComponent<BlockGroup>() == null )
                {
                    createBlockView = true;
                }
                
                //We should also create a BlockView if there is no parent object above this BlockGroup
                else if( this.transform.parent == null )
                {
                    createBlockView = true;
                }
                
                //If we should create a BlockView above this BlockGroup...
                if( createBlockView )
                {
                    //This is the top-most BlockGroup, but without a BlockView
                    //Create a BlockView and parent this BlockGroup to it
                    //Also, don't forget to create the LinkedBlockView and add it to the manager as well

                    //If we already have a parent, add a BlockView component to it!
                    if( this.transform.parent != null && this.transform.parent.name != "BrandXR Tech" )
                    {
                        //Debug.Log( "BlockGroup.cs CheckIfWeShouldCreateNewBlock() adding BlockView to parent" );

                        blockView = this.transform.parent.gameObject.AddComponent<BlockView>();
                        blockView._PrefabManager = _PrefabManager;

                        if( this.transform.parent.name == "GameObject" )
                        {
                            this.transform.parent.name = "bxr_BlockView 3D";
                        }
                    }

                    //Otherwise create the BlockView from scratch
                    else
                    {
                        //Make sure our PrefabManager exists...
                        if( PrefabManager.instance != null )
                        {
                            blockView = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockView ).GetComponent<BlockView>();
                            blockView.name = "bxr_BlockView 3D";
                        }
                    }

                    //Create a new BlockView to be the Linked Block View
                    blockView.linkedBlockView = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockView ).GetComponent<BlockView>();
                    blockView.linkedBlockView.name = "bxr_BlockView 2D";

                    //Set the linkedBlockView's linkedBlockView to this blockView to complete the connection
                    blockView.linkedBlockView.linkedBlockView = blockView;

                    //When we have to create a BlockView from scratch, we default to making it a 3D BlockView
                    blockView.viewType = BlockView.ViewType.ThreeDimensional;

                    //Don't forget to setup the linkedBlockView to the opposite (2D)
                    blockView.linkedBlockView.viewType = BlockView.ViewType.TwoDimensional;

                    //Add this new BlockView to the BlockManager
                    blockView.ParentToBlockManagerTransform();

                    //Do the same parenting step for the linkedBlockView
                    blockView.linkedBlockView.ParentToBlockManagerTransform();

                    //Finally add this BlockGroup to be a child of the BlockView
                    transform.SetParent( blockView.transform );

                    //Add a number to the name of the BlockViews so we can make it clear that these two siblings are linked
                    //Count how many BlockViews there currently are, add one to that. This will be used as part of the name for the new BlockViews to keep it clear that they are siblings
                    
                    int blockViewNumber = 0;
                    List<BlockView> blockViews = GameObject.FindObjectsOfType<BlockView>().ToList();

                    if( blockViews != null && blockViews.Count > 0 )
                    {
                        foreach( BlockView view in blockViews )
                        {
                            if( view != null && view.viewType == BlockView.ViewType.TwoDimensional )
                            {
                                blockViewNumber++;
                            }
                        }
                    }

                    blockView.name += " (" + ( blockViewNumber ) + ")";
                    blockView.linkedBlockView.name += " (" + ( blockViewNumber ) + ")";
                    

                    //Debug.Log( "view1.name = " + blockView.name + ", view2.name = " + blockView.linkedBlockView.name );

                    //Debug.Log( "BlockGroup.cs CheckIfWeShouldCreateNewBlockView() ... " + name + " Setting parent to blockView transform" );
                }
                else
                {
                    //Debug.Log( "BlockGroup.cs CheckIfWeShouldCreateNewBlockView() ... " + name + " blockView is null but transform.parent is " + this.transform.parent + ", does it have a BlockGroup component?= " + transform.parent.GetComponent<BlockGroup>() );
                }
            }
            else
            {
                //Debug.Log( "BlockGroup.cs CheckIfWeShouldCreateNewBlockView() ... blockView already exists" );
            }

        } //END CheckIfWeShouldCreateNewBlockView
Пример #2
0
        } //END AddPrefabManagerIfNeeded

        //---------------------------------//
        protected void AddBlockEventIfNeeded()
        //---------------------------------//
        {

            //If this BlockEventBase does not have a parent with a BlockEvent component, make sure to add it!
            if( this.transform.parent == null ||
                ( this.transform.parent != null && this.transform.parent.GetComponent<BlockEvent>() == null ) )
            {
                BlockEvent blockEvent = null;

                //if we have a parent with no Block Components, make it into a BlockEvent
                if( this.transform.parent != null &&
                    this.transform.parent.GetComponent<BlockManager>() == null &&
                    this.transform.parent.GetComponent<BlockView>() == null &&
                    this.transform.parent.GetComponent<BlockGroup>() == null &&
                    this.transform.parent.GetComponent<Block>() )
                {
                    this.transform.parent.gameObject.AddComponent<BlockEvent>();

                    //Make sure the new blockEvent has a reference to the PrefabManager
                    blockEvent._PrefabManager = _PrefabManager;

                    //Rename the object if needed
                    if( this.transform.parent.name == "GameObject" )
                    {
                        this.transform.parent.name = "bxr_BlockEvent";
                    }
                }

                //If we have a parent, but it already is part of the Block system
                else if( this.transform.parent != null &&
                         ( this.transform.parent.GetComponent<BlockManager>() != null ||
                           this.transform.parent.GetComponent<BlockView>() != null ||
                           this.transform.parent.GetComponent<BlockGroup>() != null ||
                           this.transform.parent.GetComponent<Block>() != null ) )
                {
                    //Keep track of the original parent
                    Transform originalParent = this.transform.parent;

                    //Create a new BlockEvent and then parent this BlockEventBase to it
                    blockEvent = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockEvent ).GetComponent<BlockEvent>();
                    this.transform.parent = blockEvent.transform;

                    //Make sure the new blockEvent has a reference to the PrefabManager
                    blockEvent._PrefabManager = _PrefabManager;

                    //Then parent the blockEvent parent to the original parent
                    blockEvent.transform.parent = originalParent;
                }

                //If we don't have a parent, or we do but it cannot become a BlockEvent
                else
                {
                    //Create a new BlockEvent and parent this BlockEventBase to it
                    blockEvent = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockEvent ).GetComponent<BlockEvent>();
                    this.transform.parent = blockEvent.transform;

                    //Make sure the new blockEvent has a reference to the PrefabManager
                    blockEvent._PrefabManager = _PrefabManager;
                }

            }

        } //END AddBlockEventIfNeeded
Пример #3
0
        } //END Update

        //--------------------------------//
        public virtual void Start()
        //--------------------------------//
        {
            //All BrandXR code relies heavily upon calling Prefabs, make sure we can do that!
            AddPrefabManagerIfNeeded();

            //If the faceCameraTransform is null, try to find a child transform with the proper name and set it
            if( faceCameraTransform == null && 
                transform.GetComponentInChildren<Transform>() != null &&
                transform.GetComponentInChildren<Transform>().name == "FaceCamera" )
            {
                faceCameraTransform = transform.GetComponentInChildren<Transform>();
            }

            //Set our current blockGroup to null just to wipe the slate clean
            //We'll find the proper BlockGroup parent as our next step
            blockGroup = null;

            //All Blocks need to be the children of a BlockGroup
            //If we have a parent, and it does contain a BlockGroup,
            //then set that as our BlockGroup
            if( transform.parent != null && GetComponentInParent<BlockGroup>() != null )
            {
                //Debug.Log( name + " Using existing BlockGroup parent" );
                
                //We have a parent gameObject, and it already has a BlockGroup
                blockGroup = GetComponentInParent<BlockGroup>();

                //If our parent gameObject has a generic name, it's safe to rename it to tidy up the editor hierarchy
                if( blockGroup.gameObject.name == "GameObject" ) { blockGroup.gameObject.name = "BlockGroup"; }
            }

            //If we have a parent, and it is a BlockView
            else if( transform.parent != null && transform.parent.GetComponent<BlockView>() != null )
            {
                BlockView blockView = transform.parent.GetComponent<BlockView>();
                
                //Add a intermediary BlockGroup in between the BlockView and the Block
                blockGroup = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockGroup ).GetComponent<BlockGroup>();

                //Parent this block to the newly created BlockGroup
                this.transform.SetParent( blockGroup.transform );

                //Parent the newly created BlockGroup to the blockView
                blockGroup.transform.SetParent( blockView.transform );
            }

            //If we have a parent, but it does not contain a BlockGroup
            //And it is not a BlockView
            else if( transform.parent != null && transform.parent.GetComponent<BlockView>() == null )
            {
                //Debug.Log( name + " Using Existing GameObject, adding new BlockGroup to GameObject" );

                blockGroup = transform.parent.gameObject.AddComponent<BlockGroup>();
                blockGroup._PrefabManager = _PrefabManager;

                //Tidy up the hierarchy naming if the gameObject name was generic
                if( blockGroup.gameObject.name == "GameObject" ) { blockGroup.gameObject.name = "BlockGroup"; }
            }

            //Otherwise, create a parent and give it a BlockGroup component
            else
            {
                //Debug.Log( name + " Creating new BlockGroup parent" );

                //Add a BlockGroup to be the parent of this Block
                blockGroup = PrefabManager.InstantiatePrefab( PrefabFactory.Prefabs.bxr_BlockGroup ).GetComponent<BlockGroup>();
                
                //If this component already has a parent, then set the newly created block to be a child of that gameObject
                if( transform.parent != null )
                {
                    blockGroup.transform.parent = transform.parent;
                }

                //Add this Block to be the child of this new BlockGroup
                transform.SetParent( blockGroup.transform );
                
                //Tidy up the editor hierarchy naming if needed
                if( blockGroup.gameObject.name == "GameObject" ) { blockGroup.gameObject.name = "BlockGroup"; }
            }

            //Check if we should perform a command on Start()
            if( sendCommandOnStart )
            {
                SendCommand( commandOnStart );
            }

        } //END Start