Beispiel #1
0
    // Display custom messages for turning on and off the music box, based on the block's name.
    public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        #region GetActivationText

        PlayerActionsLocal playerInput   = ((EntityPlayerLocal)_entityFocusing).playerInput;
        string             keybindString = playerInput.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain) + playerInput.PermanentActions.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain);
        //string keybindString = UIUtils.GetKeybindString(playerInput.Activate, playerInput.PermanentActions.Activate);
        Block  block     = Block.list[_blockValue.type];
        string blockName = block.GetBlockName();

        string strReturn = string.Format(Localization.Get("pickupPrompt"), Localization.Get(blockName));

        BlockEntityData _ebcd = _world.GetChunkFromWorldPos(_blockPos).GetBlockEntity(_blockPos);
        if (_ebcd != null && _ebcd.transform)
        {
            MusicBoxScript myMusicBoxScript = _ebcd.transform.GetComponent <MusicBoxScript>();
            if (myMusicBoxScript == null)
            {
                myMusicBoxScript         = _ebcd.transform.gameObject.AddComponent <MusicBoxScript>();
                myMusicBoxScript.enabled = false;
            }
            if (myMusicBoxScript)
            {
                if (myMusicBoxScript.enabled)
                {
                    strReturn = string.Format(Localization.Get("musicbox_turnOff") + this.GetBlockName(), keybindString);
                }
                else
                {
                    strReturn = string.Format(Localization.Get("musicbox_turnOn") + this.GetBlockName(), keybindString);
                }
            }
        }
        return(strReturn);

        #endregion
    }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     MusicBoxScript.AddLight(gameObject);
     light            = GetComponent <Light>();
     defaultIntensity = light.intensity;
 }
Beispiel #3
0
    // Play the music when its activated. We stop the sound broadcasting, in case they want to restart it again; otherwise we can get two sounds playing.
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        #region OnBlockActivated

        // If there's no transform, no sense on keeping going for this class.
        BlockEntityData _ebcd = _world.GetChunkFromWorldPos(_blockPos).GetBlockEntity(_blockPos);
        if (_ebcd == null || _ebcd.transform == null)
        {
            return(false);
        }

        MusicBoxScript myMusicBoxScript = _ebcd.transform.GetComponent <MusicBoxScript>();
        if (myMusicBoxScript == null)
        {
            myMusicBoxScript = _ebcd.transform.gameObject.AddComponent <MusicBoxScript>();
        }

        bool bRuntimeSwitch = myMusicBoxScript.enabled;


        // Turn off the music box before we do anything with it.
        myMusicBoxScript.enabled = false;

        if (_indexInBlockActivationCommands != 0)
        {
            if (_indexInBlockActivationCommands == 1)
            {
                base.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
            }

            if (_indexInBlockActivationCommands == 2)
            {
                TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player);
            }
        }
        else
        {
            bRuntimeSwitch = !bRuntimeSwitch;

            // Check if we have an animator and set it
            myMusicBoxScript.anim = _ebcd.transform.GetComponent <Animator>();

            // Check if we have a video player as well.
            myMusicBoxScript.videoPlayer = _ebcd.transform.GetComponent <VideoPlayer>();

            myMusicBoxScript.myBlockPos = _blockPos;
            // If the switch is on, then we want to look in the loot container to find a reference to any potential items,
            // which will over-ride the default audio clip / video clip.
            if (bRuntimeSwitch)
            {
                // We'll try to support getting sounds from multiple sound data nodes, based on all the items in the loot container.
                List <String> mySounds = new List <String>();
                List <String> myVideos = new List <String>();

                TileEntityLootContainer tileLootContainer = (TileEntityLootContainer)_world.GetTileEntity(_cIdx, _blockPos);

                if (tileLootContainer.items != null)
                {
                    ItemStack[] array = tileLootContainer.items;
                    for (int i = 0; i < array.Length; i++)
                    {
                        if (array[i].IsEmpty())
                        {
                            continue;
                        }

                        // Check for a SoundDataNode for a potential sound clip.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("SoundDataNode"))
                        {
                            String strSound = array[i].itemValue.ItemClass.Properties.Values["SoundDataNode"];
                            if (!mySounds.Contains(strSound))
                            {
                                mySounds.Add(strSound);
                            }
                        }
                        // Check for a video Source for a video clip. If we find it, load the asset and add it to the music box script.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("VideoSource"))
                        {
                            // Check if the video source is an asset bundle, and if so, load it directly into the video clip on
                            String strVideo = array[i].itemValue.ItemClass.Properties.Values["VideoSource"];
                            if (strVideo.IndexOf('#') == 0 && strVideo.IndexOf('?') > 0)
                            {
                                if (!myVideos.Contains(strVideo))
                                {
                                    myVideos.Add(strVideo);
                                }
                            }
                        }
                    }
                }

                // Initialize the data with our defaults.
                myMusicBoxScript.strAudioSource = this.strAudioSource;
                myMusicBoxScript.strSoundSource = this.strSoundSource;
                myMusicBoxScript.strVideoSource = this.strVideoSource;
                myMusicBoxScript.myEntity       = _player;

                // List of Videos and Sound clips.
                myMusicBoxScript.VideoGroups = myVideos;
                myMusicBoxScript.SoundGroups = mySounds;

                myMusicBoxScript.myVideoClip = null;
                myMusicBoxScript.enabled     = bRuntimeSwitch;
            }
        }


        return(false);

        #endregion
    }