예제 #1
0
        /// <summary>
        /// World takes video action to change video effects, the video is a child GameObject below the World GameObject
        /// </summary>
        /// <param name="videoAction">Action tagged as video, which contains the parameters for video setting</param>
        /// <returns>Returns end of the time at which this action is supposed over</returns>
        public float takeVideoAction(Action videoAction)
        {
#if UNITY_STANDALONE || UNITY_EDITOR
            videoBoard.GetComponent <Renderer>().enabled = true;

            MovieTexture movTexture = Resources.Load(FolderStructure.WORLD + FolderStructure.VIDEOS + videoAction.parameters[ScriptKeyword.SRC]) as MovieTexture;
            Debug.CheckResources(videoAction.parameters[ScriptKeyword.SRC], movTexture);
            videoBoard.GetComponent <Renderer>().material.mainTexture = movTexture;
            videoBoard.GetComponent <AudioSource>().clip = movTexture.audioClip;

            //Debug.Log("Video length: " + movTexture.duration);

            movTexture.Play();
            videoBoard.GetComponent <AudioSource>().Play();

            float nextAutoClickTime = Time.realtimeSinceStartup;
            nextAutoClickTime = nextAutoClickTime + movTexture.duration + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;
            return(nextAutoClickTime);
#endif
#if UNITY_ANDROID || UNITY_IPHONE
            string videoURL = FolderStructure.WORLD + FolderStructure.VIDEOS + videoAction.parameters[ScriptKeyword.SRC] + ".mp4";
            Handheld.PlayFullScreenMovie(videoURL, Color.black, FullScreenMovieControlMode.Full);
            Debug.Log("Play video on mobile");
            return(0);
#endif
        }
예제 #2
0
        /// <summary>
        /// World takes bgm action to change sound effects, the bgm is a component on the Background GameObject
        /// </summary>
        /// <param name="bgmAction">Action tagged as bgm, which contains the parameters for bgm setting</param>
        public void takeBgmAction(Action bgmAction)
        {
            worldData.bgmSrc = bgmAction.parameters[ScriptKeyword.SRC];

            //load bgm
            AudioClip bgmAudioClip = Resources.Load(FolderStructure.WORLD + FolderStructure.BGMS + bgmAction.parameters[ScriptKeyword.SRC]) as AudioClip;

            Debug.CheckResources(bgmAction.parameters[ScriptKeyword.SRC], bgmAudioClip);
            //attach bgm audio file on to background GameObject
            background.GetComponent <AudioSource>().clip = bgmAudioClip;
            //check bgm mode
            string mode = "";

            if (bgmAction.parameters.TryGetValue(ScriptKeyword.MODE, out mode))
            {
                if (mode != ScriptKeyword.MODE_LOOP)
                {
                    background.GetComponent <AudioSource>().loop = false;
                }
                else
                {
                    background.GetComponent <AudioSource>().loop = true;
                }
            }
            else
            {
                background.GetComponent <AudioSource>().loop = true;
            }
            background.GetComponent <AudioSource>().Play();
        }
예제 #3
0
        /// <summary>
        /// World takes sound action to change sound effects, the sound is a component on the World GameObject
        /// </summary>
        /// <param name="soundAction">Action tagged as sound, which contains the parameters for sound setting</param>
        public void takeSoundAction(Action soundAction)
        {
            AudioClip soundAudioClip = Resources.Load(FolderStructure.WORLD + FolderStructure.SOUNDS + soundAction.parameters[ScriptKeyword.SRC]) as AudioClip;

            Debug.CheckResources(soundAction.parameters[ScriptKeyword.SRC], soundAudioClip);
            this.GetComponent <AudioSource>().clip = soundAudioClip;
            this.GetComponent <AudioSource>().Play();
        }
예제 #4
0
 public static void CheckResources(string name, Texture2D resource)
 {
     if (!ON)
     {
         return;
     }
     Debug.CheckResources(name, resource, "Texture2D");
 }
예제 #5
0
 public static void CheckResources(string name, MovieTexture resource)
 {
     if (!ON)
     {
         return;
     }
     Debug.CheckResources(name, resource, "MovieTexture");
 }
예제 #6
0
 public static void CheckResources(string name, AudioClip resource)
 {
     if (!ON)
     {
         return;
     }
     Debug.CheckResources(name, resource, "AudioClip");
 }
예제 #7
0
 public static void CheckResources(string name, Sprite resource)
 {
     if (!ON)
     {
         return;
     }
     Debug.CheckResources(name, resource, "Sprite");
 }
예제 #8
0
        /// <summary>
        /// Backgrounds the transition on screen obscured.
        /// </summary>
        private void BackgroundTransitionOnScreenObscured()
        {
            this.worldControl.GetComponent <WorldControl> ().hideCharacters();
            Texture2D texture2D = Resources.Load <Texture2D>(FolderStructure.WORLD + FolderStructure.BACKGROUNDS + worldData.backgroundSrc);
            Sprite    sprite    = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));

            //Sprite sprite = Resources.Load<Sprite>(FolderStructure.WORLD + FolderStructure.BACKGROUNDS + worldData.backgroundSrc);
            Debug.CheckResources(worldData.backgroundSrc, texture2D);
            background.GetComponent <SpriteRenderer>().sprite = sprite;
        }
예제 #9
0
        /// <summary>
        /// Character takes text action to speack something with or without audio, be careful that World GameObject should not speak voice
        /// </summary>
        /// <param name="voiceAction">Action tagged as voice, which contains the parameters for voice setting</param>
        /// <returns>Returns end of the time at which this action is supposed over</returns>
        public float takeVoiceAction(Action voiceAction)
        {
            string voiceSrc = "";

            //Play the voice audio
            float nextAutoClickTimeVoice = Time.realtimeSinceStartup;

            if (voiceAction.parameters.TryGetValue(ScriptKeyword.SRC, out voiceSrc))
            {
                AudioClip voiceAudioClip = Resources.Load(FolderStructure.CHARACTERS + FolderStructure.VOICES + voiceSrc) as AudioClip;
                Debug.CheckResources(voiceSrc, voiceAudioClip);
                this.GetComponent <AudioSource>().clip = voiceAudioClip;
                this.GetComponent <AudioSource>().Play();
                nextAutoClickTimeVoice = nextAutoClickTimeVoice + this.GetComponent <AudioSource>().clip.length + (PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR);
            }

            //Similar to the takeTextAction
            if (dialogContent == null)
            {
                Debug.LogError(ScriptError.NOT_ASSIGN_GAMEOBJECT);
                Application.Quit();
            }

            //dialogContent.GetComponent<Text> ().text = shownName + "\n\n" + textAction.parameters [ScriptKeyword.CONTENT];
            dialogContent.GetComponent <DialogManager>().writeOnDialogBoard(characterData.shownName, voiceAction.parameters[ScriptKeyword.CONTENT], voiceSrc);

            if (this.characterData.roleType == ScriptKeyword.TYPE_CHARACTER && worldControl.GetComponent <WorldControl>().getDialogMode() == GameConstants.BUBBLE)
            {
                this.GetComponentInChildren <BubbleManager>().writeOnBubbleBoard(characterData.shownName
                                                                                 , voiceAction.parameters[ScriptKeyword.CONTENT], voiceSrc
                                                                                 , new Vector2(characterData.positionX, characterData.positionY));
            }
            else
            {
                this.GetComponentInChildren <BubbleManager>().hide();
            }

            float nextAutoClickTimeText = Time.realtimeSinceStartup;

            nextAutoClickTimeText = nextAutoClickTimeText + voiceAction.parameters[ScriptKeyword.CONTENT].Length * (PlayerPrefs.GetFloat(GameConstants.CONFIG_TEXT_SPEED) * GameConstants.TEXT_DELAY_FACTOR) + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;

            //Debug.Log("AudioClip length: " + this.GetComponent<AudioSource>().clip.length);
            return(Mathf.Max(nextAutoClickTimeVoice, nextAutoClickTimeText));
        }
예제 #10
0
        /// <summary>
        /// Character takes posture action to change character appearence, like this character cloth, character face expression, gestures.
        /// Anyway, this action is to change the picture this character shows
        /// </summary>
        /// <param name="postureAction">Action tagged as posture, which contains the parameters for posture setting</param>
        public void takePostureAction(Action postureAction)
        {
            //Check anchor value
            string anchorStringValue = "";

            if (postureAction.parameters.TryGetValue(ScriptKeyword.ANCHOR, out anchorStringValue))
            {
            }
            else
            {
                anchorStringValue = "(0.5, 0.5)";
            }

            anchorStringValue = anchorStringValue.Replace(ScriptKeyword.PARENTHESE_LEFT, string.Empty);
            anchorStringValue = anchorStringValue.Replace(ScriptKeyword.PARENTHESE_RIGHT, string.Empty);
            anchorStringValue = anchorStringValue.Replace(@"\s+", string.Empty);
            string[] anchorStrings = anchorStringValue.Split(ScriptKeyword.COMMA.ToCharArray());
            this.characterData.anchorX = float.Parse(anchorStrings[0]);
            this.characterData.anchorY = float.Parse(anchorStrings[1]);

            //check zoom value
            string zoomValue = "";
            float  zoom      = 1f;

            if (postureAction.parameters.TryGetValue(ScriptKeyword.ZOOM, out zoomValue))
            {
                zoom = float.Parse(zoomValue);
            }
            this.characterData.zoom = zoom;

            string live2dValue = "";

            if (postureAction.parameters.TryGetValue(ScriptKeyword.LIVE2D, out live2dValue))
            {
                this.characterData.postrueSrc    = null;
                this.characterData.postureLive2D = live2dValue;
                //Use live2d posture
                this.GetComponent <SpriteRenderer>().sprite = null;
                //find all live2d file resources
                Live2DSimpleModel live2DSimpleModel = this.GetComponent <Live2DSimpleModel>();
                Debug.Log("live2DSimpleModel=" + live2DSimpleModel.enabled);
                Object[]         live2DFiles  = Resources.LoadAll(FolderStructure.CHARACTERS + FolderStructure.POSTURES + live2dValue);
                TextAsset        mocFile      = null;
                TextAsset        physicsFile  = null;
                List <Texture2D> textureFiles = new List <Texture2D>();
                foreach (Object live2DFile in live2DFiles)
                {
                    Debug.Log("live2DFile=" + live2DFile.name);
                    //scriptNames.Add(Path.GetFileNameWithoutExtension(scriptObject.name));
                    if (live2DFile.name.EndsWith(ScriptKeyword.LIVE2D_MOC_EXTENSION))
                    {
                        mocFile = live2DFile as TextAsset;
                    }
                    else if (live2DFile.name.EndsWith(ScriptKeyword.LIVE2D_PHYSICS_EXTENSION))
                    {
                        physicsFile = live2DFile as TextAsset;
                    }
                    else if (live2DFile.name.Contains(ScriptKeyword.LIVE2D_TEXTURE_EXTENSION))
                    {
                        textureFiles.Add(live2DFile as Texture2D);
                    }
                }
                Debug.CheckResources(live2dValue, mocFile);
                Debug.CheckResources(live2dValue, physicsFile);
                Debug.CheckResources(live2dValue, textureFiles);

                live2DSimpleModel.mocFile      = mocFile;
                live2DSimpleModel.physicsFile  = physicsFile;
                live2DSimpleModel.textureFiles = textureFiles.ToArray();
                live2DSimpleModel.zoom         = this.characterData.zoom;
                live2DSimpleModel.enabled      = true;
            }
            else
            {
                //Use normal image posture
                this.GetComponent <Live2DSimpleModel>().enabled = false;
                this.characterData.postrueSrc    = postureAction.parameters[ScriptKeyword.SRC];
                this.characterData.postureLive2D = null;
                //read pixelsPerUnit from user setting

                /*
                 *              Sprite postureSpriteOriginal = Resources.Load<Sprite>(FolderStructure.CHARACTERS + FolderStructure.POSTURES + postureAction.parameters[ScriptKeyword.SRC]);
                 *              Debug.CheckResources (postureAction.parameters[ScriptKeyword.SRC], postureSpriteOriginal);
                 *              float pixelsPerUnity = postureSpriteOriginal.pixelsPerUnit;
                 */
                float pixelsPerUnity = 100 / characterData.zoom;
                //create the sprite again for setting the pivot from the script
                Texture2D postureTexture2D = Resources.Load <Texture2D>(
                    FolderStructure.CHARACTERS + FolderStructure.POSTURES + postureAction.parameters[ScriptKeyword.SRC]);
                Sprite postureSprite = Sprite.Create(postureTexture2D
                                                     , new Rect(0, 0, postureTexture2D.width, postureTexture2D.height)
                                                     , new Vector2(characterData.anchorX, characterData.anchorY)
                                                     , pixelsPerUnity);
                this.GetComponent <SpriteRenderer>().sprite = postureSprite;
            }
        }