Пример #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 game entity load data from saving data (on the disk)
        /// </summary>
        /// <param name="worldData">worldData is the serialized data on the disk</param>
        public void loadData(WorldData worldData)
        {
            this.worldData = worldData;

            Action loadedBackgroundAction = new Action(ScriptKeyword.BACKGROUND, new Dictionary <string, string>()
            {
                { ScriptKeyword.SRC, worldData.backgroundSrc },
                { ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT }
            });

            this.takeBackgroundAction(loadedBackgroundAction);

            Action loadedWeatherAction = new Action(ScriptKeyword.WEATHER, new Dictionary <string, string>()
            {
                { ScriptKeyword.TYPE, worldData.weatherType },
                { ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT }
            });

            this.takeWeatherAction(loadedWeatherAction);

            Action loadedBgmAction = new Action(ScriptKeyword.BGM, new Dictionary <string, string>()
            {
                { ScriptKeyword.SRC, worldData.bgmSrc },
                { ScriptKeyword.MODE, ScriptKeyword.MODE_LOOP }
            });

            this.takeBgmAction(loadedBgmAction);
        }
Пример #4
0
        /// <summary>
        /// Character game entity load data from saving data (on the disk)
        /// </summary>
        /// <param name="characterData">characterData is the serialized data on the disk</param>
        public void loadData(CharacterData characterData)
        {
            this.characterData = characterData;

            Debug.Log("characterData: " + characterData.id + ", " + characterData.postrueSrc + ", " + characterData.roleType + ", " + characterData.shownName);

            Action loadedRoleAction = new Action(ScriptKeyword.ROLE, new Dictionary <string, string>()
            {
                { ScriptKeyword.TYPE, characterData.roleType },
                { ScriptKeyword.NAME, characterData.shownName }
            });

            this.takeRoleAction(loadedRoleAction);
            if (characterData.postrueSrc != null && !characterData.postrueSrc.Equals(""))
            {
                Action loadedPostureAction = new Action(ScriptKeyword.POSTURE, new Dictionary <string, string>()
                {
                    { ScriptKeyword.SRC, characterData.postrueSrc }
                });
                this.takePostureAction(loadedPostureAction);
            }
            Action loadedMoveAction = new Action(ScriptKeyword.MOVE, new Dictionary <string, string>()
            {
                { ScriptKeyword.POSITION, ScriptKeyword.POSITION_CENTER },
                { ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT }
            });

            this.takeMoveAction(loadedMoveAction);
        }
Пример #5
0
        public override Node ExitFlag(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Flag action
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            int count = (node.Values.Count - 1) / 7;

            parameters.Add(ScriptKeyword.COUNT, "" + count);
            for (int i = 0; i < count; i++)
            {
                parameters.Add(ScriptKeyword.OPTION_ + (i + 1), node.Values[i * 7 + 1].ToString());
                parameters.Add(ScriptKeyword.OPTION_ID_ + (i + 1), node.Values[i * 7 + 3].ToString());
                parameters.Add(ScriptKeyword.OPTION_SRC_ + (i + 1), node.Values[i * 7 + 5].ToString());
            }
            Action flagAction = new Action(ScriptKeyword.FLAG, parameters);

            actions.Add(flagAction);

            /*
             * Console.Write ("Flag: ");
             * for (int i = 0; i < node.Values.Count; i++) {
             *      Console.Write ("[" + i + "]" + node.Values[i] + " ");
             * }
             * Console.Write ("\n");
             */

            return(node);
        }
Пример #6
0
        /// <summary>
        /// World takes background action to change weather effects, the weather is a child GameObject below the World GameObject
        /// </summary>
        /// <param name="weatherAction">Action tagged as weather, which contains the parameters for weather setting</param>
        public void takeWeatherAction(Action weatherAction)
        {
            worldData.weatherType = weatherAction.parameters[ScriptKeyword.TYPE];

            if (weatherAction.parameters[ScriptKeyword.TYPE] == ScriptKeyword.TYPE_SNOW)
            {
                weatherSnow.SetActive(true);
                EllipsoidParticleEmitter ellipsoidParticleEmitter = weatherSnow.GetComponent <EllipsoidParticleEmitter>();
                string level = "0.5";
                if (weatherAction.parameters.TryGetValue(ScriptKeyword.LEVEL, out level))
                {
                    ellipsoidParticleEmitter.minEmission = 100 * float.Parse(level);
                    ellipsoidParticleEmitter.maxEmission = 100 * float.Parse(level);
                }
            }
            else
            {
                weatherSnow.SetActive(true);
                EllipsoidParticleEmitter ellipsoidParticleEmitter = weatherSnow.GetComponent <EllipsoidParticleEmitter>();
                ellipsoidParticleEmitter.minEmission = 0;
                ellipsoidParticleEmitter.maxEmission = 0;
            }

            if (weatherAction.parameters[ScriptKeyword.TYPE] == ScriptKeyword.TYPE_RAIN)
            {
                weatherRain.SetActive(true);
            }
            else
            {
                weatherRain.SetActive(false);
            }
        }
Пример #7
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();
        }
Пример #8
0
        /// <summary>
        /// World takes text action to change video effects, text is shown on the dialog board GameObject which is on the UI canvas
        /// </summary>
        /// <param name="textAction">Action tagged as text, which contains the parameters for text setting</param>
        /// <returns>Returns end of the time at which this action is supposed over</returns>
        public float takeTextAction(Action textAction)
        {
            //dialogContent.GetComponent<Text> ().text = textAction.parameters [ScriptKeyword.CONTENT];
            dialogContent.GetComponent <DialogManager>().writeOnDialogBoard("", textAction.parameters[ScriptKeyword.CONTENT], "");
            float nextAutoClickTime = Time.realtimeSinceStartup;

            nextAutoClickTime = nextAutoClickTime + textAction.parameters[ScriptKeyword.CONTENT].Length * PlayerPrefs.GetFloat(GameConstants.CONFIG_TEXT_SPEED) * GameConstants.TEXT_DELAY_FACTOR + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;
            return(nextAutoClickTime);
        }
Пример #9
0
        /// <summary>
        /// World takes background action to change the background effects, the background is a child GameObject below the World GameObject
        /// </summary>
        /// <param name="backgroundAction">Action tagged as background, which contains the parameters for background setting</param>
        public void takeBackgroundAction(Action backgroundAction)
        {
            worldData.backgroundSrc = backgroundAction.parameters[ScriptKeyword.SRC];

            this.worldControl.GetComponent <WorldControl> ().DisablePlayerInput();
            this.worldControl.GetComponent <WorldControl> ().hideInPlayUI();

            string transitionValue;

            if (backgroundAction.parameters.TryGetValue(ScriptKeyword.TRANSITION, out transitionValue))
            {
                string transitionTimeString;
                float  transitionTime = 1f;
                if (backgroundAction.parameters.TryGetValue(ScriptKeyword.TIME, out transitionTimeString))
                {
                    transitionTime = float.Parse(transitionTimeString);
                }
                //Debug.Log ("transitionTime="+transitionTime);
                switch (transitionValue)
                {
                case ScriptKeyword.TRANSITION_INSTANT:
                {
                    this.BackgroundTransitionOnScreenObscured();
                    this.BackgroundTransitionComplete();
                    break;
                }

                case ScriptKeyword.TRANSITION_FADE:
                {
                    var fader = new FadeTransition()
                    {
                        nextScene   = -1,
                        fadedDelay  = transitionTime,
                        fadeToColor = Color.black
                    };
                    TransitionKit.instance.transitionWithDelegate(fader);
                    break;
                }
                }
            }
            else
            {
                var fader = new FadeTransition()
                {
                    nextScene   = -1,
                    fadedDelay  = 1f,
                    fadeToColor = Color.black
                };
                TransitionKit.instance.transitionWithDelegate(fader);
            }
        }
Пример #10
0
        /// <summary>
        /// Character takes text action to show character's psychological descriptions, mainly it is used for first-view character
        /// </summary>
        /// <param name="textAction">Action tagged as text, which contains the parameters for text setting</param>
        /// <returns>Returns end of the time at which this action is supposed over</returns>
        public float takeTextAction(Action textAction)
        {
            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, textAction.parameters[ScriptKeyword.CONTENT], "");
            float nextAutoClickTime = Time.realtimeSinceStartup;

            nextAutoClickTime = nextAutoClickTime + textAction.parameters[ScriptKeyword.CONTENT].Length * (PlayerPrefs.GetFloat(GameConstants.CONFIG_TEXT_SPEED) * GameConstants.TEXT_DELAY_FACTOR) + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;
            return(nextAutoClickTime);
        }
Пример #11
0
 /// <summary>
 /// Character takes role action to change character infomation, like this character type, character name
 /// </summary>
 /// <param name="roleAction">Action tagged as weather, which contains the parameters for weather setting</param>
 public void takeRoleAction(Action roleAction)
 {
     if (roleAction.parameters.TryGetValue(ScriptKeyword.TYPE, out characterData.roleType))
     {
     }
     else
     {
         characterData.roleType = ScriptKeyword.TYPE_CHARACTER;
     }
     if (roleAction.parameters.TryGetValue(ScriptKeyword.NAME, out characterData.shownName))
     {
     }
     else
     {
         characterData.shownName = "???";
     }
 }
Пример #12
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));
        }
Пример #13
0
        public override Node ExitOption(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Option action
            Action optionAction = new Action(ScriptKeyword.OPTION, new Dictionary <string, string>()
            {
                { ScriptKeyword.ID, node.Values[1].ToString() }
            });

            actions.Add(optionAction);

            /*
             * Console.Write ("Option: ");
             * for (int i = 0; i < node.Values.Count; i++) {
             *      Console.Write ("[" + i + "]" + node.Values[i] + " ");
             * }
             * Console.Write ("\n");
             */

            return(node);
        }
Пример #14
0
        public override Node ExitJump(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Jump action
            Action jumpAction = new Action(ScriptKeyword.JUMP, new Dictionary <string, string>()
            {
                { ScriptKeyword.SRC, node.Values[1].ToString() }
            });

            actions.Add(jumpAction);

            /*
             * Console.Write ("Jump: ");
             * for (int i = 0; i < node.Values.Count; i++) {
             *      Console.Write ("[" + i + "]" + node.Values[i] + " ");
             * }
             * Console.Write ("\n");
             */

            return(node);
        }
Пример #15
0
        public override Node ExitBlock(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            /*
             * Console.Write ("Block: ");
             * for (int i = 0; i < node.Values.Count; i++) {
             *      Console.Write ("[" + i + "]" + node.Values[i] + " ");
             * }
             * Console.Write ("\n");
             */

            Action focusAction = new Action(ScriptKeyword.FOCUS, new Dictionary <string, string>()
            {
                { ScriptKeyword.ID, node.Values[0].ToString() }
            });
            int index = actions.IndexOf(emptyFocusAction);

            actions [index] = focusAction;

            return(node);
        }
Пример #16
0
        /// <summary>
        /// World game entity load data from saving data (on the disk)
        /// </summary>
        /// <param name="worldData">worldData is the serialized data on the disk</param>
        public void loadData(WorldData worldData)
        {
            this.worldData = worldData;

            Action loadedBackgroundAction = new Action(ScriptKeyword.BACKGROUND, new Dictionary<string, string>(){
            {ScriptKeyword.SRC, worldData.backgroundSrc},
            {ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT}
            });

            this.takeBackgroundAction(loadedBackgroundAction);

            Action loadedWeatherAction = new Action(ScriptKeyword.WEATHER, new Dictionary<string, string>(){
            {ScriptKeyword.TYPE, worldData.weatherType},
            {ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT}
            });
            this.takeWeatherAction(loadedWeatherAction);

            Action loadedBgmAction = new Action(ScriptKeyword.BGM, new Dictionary<string, string>(){
            {ScriptKeyword.SRC, worldData.bgmSrc},
            {ScriptKeyword.MODE, ScriptKeyword.MODE_LOOP}
            });
            this.takeBgmAction(loadedBgmAction);
        }
Пример #17
0
        /// <summary>
        /// Character game entity load data from saving data (on the disk)
        /// </summary>
        /// <param name="characterData">characterData is the serialized data on the disk</param>
        public void loadData(CharacterData characterData)
        {
            this.characterData = characterData;

            Debug.Log("characterData: " + characterData.id + ", " + characterData.postrueSrc + ", " + characterData.roleType + ", " + characterData.shownName);

            Action loadedRoleAction = new Action(ScriptKeyword.ROLE, new Dictionary<string, string>(){
            {ScriptKeyword.TYPE, characterData.roleType},
            {ScriptKeyword.NAME, characterData.shownName}
            });
            this.takeRoleAction(loadedRoleAction);
            if (characterData.postrueSrc != null && !characterData.postrueSrc.Equals("")) {
                Action loadedPostureAction = new Action(ScriptKeyword.POSTURE, new Dictionary<string, string>(){
                {ScriptKeyword.SRC, characterData.postrueSrc}
                });
                this.takePostureAction(loadedPostureAction);
            }
            Action loadedMoveAction = new Action(ScriptKeyword.MOVE, new Dictionary<string, string>(){
            {ScriptKeyword.POSITION, ScriptKeyword.POSITION_CENTER},
            {ScriptKeyword.TRANSITION, ScriptKeyword.TRANSITION_INSTANT}
            });
            this.takeMoveAction(loadedMoveAction);
        }
Пример #18
0
        /// <summary>
        /// WorldControl takes focus action to change current focusedGameObject that further is the target to distribute actions to
        /// </summary>
        /// <param name="focusAction">Action tagged as focus, which contains the parameters for focus setting</param>
        public void takeFocusAction(Action focusAction)
        {
            worldControlData.FocusedGameObjectId = focusAction.parameters[ScriptKeyword.ID];

            FocusedGameObject = null;
            //focus on object to take further actions
            if (focusAction.parameters[ScriptKeyword.ID] == ScriptKeyword.WORLD) {
                FocusedGameObject = world;
            } else {
                if (!characters.ContainsKey(focusAction.parameters[ScriptKeyword.ID])) {
                    //there is no character on this id, create one
                    characters.Add(focusAction.parameters[ScriptKeyword.ID], createNewCharacter(focusAction.parameters[ScriptKeyword.ID]));
                }
                FocusedGameObject = characters[focusAction.parameters[ScriptKeyword.ID]];
            }
        }
Пример #19
0
        /// <summary>
        /// World takes background action to change weather effects, the weather is a child GameObject below the World GameObject
        /// </summary>
        /// <param name="weatherAction">Action tagged as weather, which contains the parameters for weather setting</param>
        public void takeWeatherAction(Action weatherAction)
        {
            worldData.weatherType = weatherAction.parameters[ScriptKeyword.TYPE];

            if (weatherAction.parameters[ScriptKeyword.TYPE] == ScriptKeyword.TYPE_SNOW) {
                weatherSnow.SetActive(true);
                EllipsoidParticleEmitter ellipsoidParticleEmitter = weatherSnow.GetComponent<EllipsoidParticleEmitter>();
                string level = "0.5";
                if (weatherAction.parameters.TryGetValue(ScriptKeyword.LEVEL, out level)) {

                    ellipsoidParticleEmitter.minEmission = 100 * float.Parse(level);
                    ellipsoidParticleEmitter.maxEmission = 100 * float.Parse(level);
                }
            } else {
                weatherSnow.SetActive(true);
                EllipsoidParticleEmitter ellipsoidParticleEmitter = weatherSnow.GetComponent<EllipsoidParticleEmitter>();
                ellipsoidParticleEmitter.minEmission = 0;
                ellipsoidParticleEmitter.maxEmission = 0;
            }

            if (weatherAction.parameters[ScriptKeyword.TYPE] == ScriptKeyword.TYPE_RAIN) {
                weatherRain.SetActive(true);
            } else {
                weatherRain.SetActive(false);
            }
        }
Пример #20
0
        public override Node ExitOption(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Option action
            Action optionAction = new Action (ScriptKeyword.OPTION, new Dictionary<string, string>(){
                {ScriptKeyword.ID, node.Values[1].ToString()}
            });
            actions.Add (optionAction);

            /*
            Console.Write ("Option: ");
            for (int i = 0; i < node.Values.Count; i++) {
                Console.Write ("[" + i + "]" + node.Values[i] + " ");
            }
            Console.Write ("\n");
            */

            return node;
        }
Пример #21
0
        public override Node ExitFlag(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Flag action
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            int count = (node.Values.Count - 1) / 7;
            parameters.Add (ScriptKeyword.COUNT, ""+count);
            for(int i=0; i<count ;i++){
                parameters.Add(ScriptKeyword.OPTION_+(i+1), node.Values[i*7+1].ToString());
                parameters.Add(ScriptKeyword.OPTION_ID_+(i+1), node.Values[i*7+3].ToString());
                parameters.Add(ScriptKeyword.OPTION_SRC_+(i+1), node.Values[i*7+5].ToString());
            }
            Action flagAction = new Action (ScriptKeyword.FLAG, parameters);
            actions.Add (flagAction);

            /*
            Console.Write ("Flag: ");
            for (int i = 0; i < node.Values.Count; i++) {
                Console.Write ("[" + i + "]" + node.Values[i] + " ");
            }
            Console.Write ("\n");
            */

            return node;
        }
Пример #22
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;
            }
        }
Пример #23
0
        /// <summary>
        /// Step the game, which means distribute a set of actions to World or a Character to take, the last action should be ended with the mouse click.
        /// Also, when needs to jump to another script or take flag action, worldControl itself takes them
        /// </summary>
        public void step()
        {
            if(!this.playerInputIsEnabled){return;}
            //Debug.Log(++count);
            //Check game state first
            if (this.worldControlData.currentGameState == GameConstants.BACKLOG) {
                clickBackLogButton();
                return;
            } else if (this.worldControlData.currentGameState == GameConstants.AUTO) {
                this.worldControlData.nextAutoClickTime = Mathf.Infinity;
            } else if (this.worldControlData.currentGameState == GameConstants.SAVE) {
                clickSaveButton();
                return;
            } else if (this.worldControlData.currentGameState == GameConstants.LOAD) {
                clickLoadButton();
                return;
            } else if (this.worldControlData.currentGameState == GameConstants.HIDE) {
                clickHideButton();
                return;
            } else if (this.worldControlData.currentGameState == GameConstants.FLAG) {
                return;
            }

            //If in NORMAL state, plays the game normally
            if (currentActions == null || currentActions.Count < 1) {
                //To be done
                currentActions = scriptReader.loadNextScript();
                if (currentActions == null) {
                    Debug.Log("Fin");
                    clickExitButton(false);
                    return;
                }
            }
            if(lastAction == null){

            }else if (lastAction.tag == ScriptKeyword.VIDEO) {
                world.GetComponent<World>().skipVideoAction();
                showInPlayUI();
            }

            while (currentActions.Count > 0) {
                Action currentAction = currentActions[0];
                Debug.Log("Action="+currentAction.tag);
                //store last action
                lastAction = currentAction;
                //Save the last text content
                if (currentAction.tag == ScriptKeyword.TEXT
                    || currentAction.tag == ScriptKeyword.VOICE) {
                    worldControlData.textContent = currentAction.parameters[ScriptKeyword.CONTENT];
                    showInPlayUI();
                }
                //remove already completed action
                currentActions.RemoveAt(0);

                if (currentAction.tag == ScriptKeyword.FOCUS) {
                    this.takeFocusAction(currentAction);
                }
                if (FocusedGameObject == null) {
                    Debug.LogError(ScriptError.NOT_FOCUS_OBJECT);
                    return;
                }
                if (currentAction.tag == ScriptKeyword.BACKGROUND) {
                    FocusedGameObject.GetComponent<World>().takeBackgroundAction(currentAction);
                    break;
                } else if (currentAction.tag == ScriptKeyword.WEATHER) {
                    FocusedGameObject.GetComponent<World>().takeWeatherAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.SOUND) {
                    FocusedGameObject.GetComponent<World>().takeSoundAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.BGM) {
                    FocusedGameObject.GetComponent<World>().takeBgmAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.VIDEO) {
                    hideInPlayUI();
                    updateNextAutoClickTime(FocusedGameObject.GetComponent<World>().takeVideoAction(currentAction));
                    //wait next click for video action
                    break;
                } else if (currentAction.tag == ScriptKeyword.TEXT) {
                    if (FocusedGameObject.GetComponent<World>() != null) {
                        updateNextAutoClickTime(FocusedGameObject.GetComponent<World>().takeTextAction(currentAction));
                    } else if (FocusedGameObject.GetComponent<Character>() != null) {
                        updateNextAutoClickTime(FocusedGameObject.GetComponent<Character>().takeTextAction(currentAction));
                    }
                    break;
                } else if (currentAction.tag == ScriptKeyword.MOVE) {
                    FocusedGameObject.GetComponent<Character>().takeMoveAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.POSTURE) {
                    FocusedGameObject.GetComponent<Character>().takePostureAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.VOICE) {
                    updateNextAutoClickTime(FocusedGameObject.GetComponent<Character>().takeVoiceAction(currentAction));
                    break;
                } else if (currentAction.tag == ScriptKeyword.ROLE) {
                    FocusedGameObject.GetComponent<Character>().takeRoleAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.FLAG) {
                    this.takeFlagAction(currentAction);
                    break;
                } else if (currentAction.tag == ScriptKeyword.JUMP) {
                    this.takeJumpAction(currentAction);
                } else if (currentAction.tag == ScriptKeyword.OTHER){
                    if (FocusedGameObject.GetComponent<World>() != null) {
                        FocusedGameObject.GetComponent<World>().takeOtherAction(currentAction);
                    }else if (FocusedGameObject.GetComponent<Character>() != null) {
                        FocusedGameObject.GetComponent<Character>().takeOtherAction(currentAction);
                    }
                }
            }
        }
Пример #24
0
 /// <summary>
 /// World takes text action to change video effects, text is shown on the dialog board GameObject which is on the UI canvas
 /// </summary>
 /// <param name="textAction">Action tagged as text, which contains the parameters for text setting</param>
 /// <returns>Returns end of the time at which this action is supposed over</returns>
 public float takeTextAction(Action textAction)
 {
     //dialogContent.GetComponent<Text> ().text = textAction.parameters [ScriptKeyword.CONTENT];
     dialogContent.GetComponent<DialogManager>().writeOnDialogBoard("", textAction.parameters[ScriptKeyword.CONTENT], "");
     float nextAutoClickTime = Time.realtimeSinceStartup;
     nextAutoClickTime = nextAutoClickTime + textAction.parameters[ScriptKeyword.CONTENT].Length * PlayerPrefs.GetFloat(GameConstants.CONFIG_TEXT_SPEED) * GameConstants.TEXT_DELAY_FACTOR + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;
     return nextAutoClickTime;
 }
Пример #25
0
        /// <summary>
        /// Character takes move action to move arround in the World, exactly arround the background GameObject
        /// </summary>
        /// <param name="moveAction">Action tagged as voice, which contains the parameters for voice setting</param>
        public void takeMoveAction(Action moveAction)
        {
            string positionValue = moveAction.parameters[ScriptKeyword.POSITION];
            if (positionValue == null || positionValue.Equals("")) {
                return;
            }
            if (positionValue.Equals(ScriptKeyword.POSITION_CENTER)) {
                characterData.positionX = 0.5f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            } else if (positionValue.Equals(ScriptKeyword.POSITION_LEFT)) {
                characterData.positionX = 0.2f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            } else if (positionValue.Equals(ScriptKeyword.POSITION_RIGHT)) {
                characterData.positionX = 0.8f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            } else {
                //the position is written in (x.xxx, x.xxx, x.xxx)
                positionValue = positionValue.Replace(ScriptKeyword.PARENTHESE_LEFT, string.Empty);
                positionValue = positionValue.Replace(ScriptKeyword.PARENTHESE_RIGHT, string.Empty);
                positionValue = positionValue.Replace(@"\s+", string.Empty);
                string[] posString = positionValue.Split(ScriptKeyword.COMMA.ToCharArray());
                characterData.positionX = float.Parse(posString[0]);
                characterData.positionY = float.Parse(posString[1]);
                characterData.positionZ = float.Parse(posString[2]);
            }

            if(this.characterData.postureLive2D != null){
                float width = this.GetComponent<Renderer> ().bounds.size.x;
                float height = this.GetComponent<Renderer> ().bounds.size.y;
                Debug.Log ("width="+width);
                Debug.Log ("height="+height);
            }else if(this.characterData.postrueSrc != null){
                //float backgroundWidth = worldControl.GetComponent<WorldControl>().world.GetComponent<World>().background.GetComponent<Renderer>().bounds.extents.x;
                //float backgroundHeight = worldControl.GetComponent<WorldControl>().world.GetComponent<World>().background.GetComponent<Renderer>().bounds.extents.y;
                //Debug.Log("characterData.posX = " + characterData.positionX + ", characterData.posY = " + characterData.positionY + ", characterData.posZ = " + characterData.positionZ);
                Vector3 characterScreenToWorldPoint = Camera.main.ViewportToWorldPoint(new Vector3(characterData.positionX, characterData.positionY
                    , Mathf.Abs(Camera.main.transform.position.z)));

                //Here do the trajectory move
                string type;
                if(!moveAction.parameters.TryGetValue(ScriptKeyword.TYPE, out type)){

                }
                if (type != null) {
                    //string durationString;
                    //if (!moveAction.parameters.TryGetValue(ScriptKeyword.TYPE, out durationString)) {

                    //}
                    movingStartTime = System.DateTime.Now;
                    if (moving != null) {
                        StopCoroutine(moving);
                    }
                    //Vector3 direction = characterScreenToWorldPoint - transform.localPosition;
                    moving = Moving(transform.localPosition, characterScreenToWorldPoint, 1f, type);
                    StartCoroutine(moving);
                } else {
                    this.transform.localPosition = characterScreenToWorldPoint;
                }
            }
        }
Пример #26
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);
        }
Пример #27
0
 /// <summary>
 /// Character takes text action to show character's psychological descriptions, mainly it is used for first-view character
 /// </summary>
 /// <param name="textAction">Action tagged as text, which contains the parameters for text setting</param>
 /// <returns>Returns end of the time at which this action is supposed over</returns>
 public float takeTextAction(Action textAction)
 {
     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, textAction.parameters[ScriptKeyword.CONTENT], "");
     float nextAutoClickTime = Time.realtimeSinceStartup;
     nextAutoClickTime = nextAutoClickTime + textAction.parameters[ScriptKeyword.CONTENT].Length * (PlayerPrefs.GetFloat(GameConstants.CONFIG_TEXT_SPEED) * GameConstants.TEXT_DELAY_FACTOR) + PlayerPrefs.GetFloat(GameConstants.CONFIG_AUTO_SPEED) * GameConstants.AUTO_DELAY_FACTOR;
     return nextAutoClickTime;
 }
Пример #28
0
        /// <summary>
        /// Character takes role action to change character infomation, like this character type, character name
        /// </summary>
        /// <param name="roleAction">Action tagged as weather, which contains the parameters for weather setting</param>
        public void takeRoleAction(Action roleAction)
        {
            if (roleAction.parameters.TryGetValue(ScriptKeyword.TYPE, out characterData.roleType)) {

            } else {
                characterData.roleType = ScriptKeyword.TYPE_CHARACTER;
            }
            if (roleAction.parameters.TryGetValue(ScriptKeyword.NAME, out characterData.shownName)) {

            } else {
                characterData.shownName = "???";
            }
        }
Пример #29
0
 /// <summary>
 /// WorldControl takes jump action to jump to specific scripts
 /// </summary>
 /// <param name="jumpAction">Action tagged as jump, which contains the parameters for jump setting</param>
 public void takeJumpAction(Action jumpAction)
 {
     Debug.Log("Jump to: " + jumpAction.parameters[ScriptKeyword.SRC]);
     currentActions = scriptReader.loadNextScript(jumpAction.parameters[ScriptKeyword.SRC]);
 }
Пример #30
0
        /// <summary>
        /// WorldControl game entity load data from saving data (on the disk)
        /// </summary>
        /// <param name="worldControlData">worldControlData is the serialized data on the disk</param>
        public void loadData(WorldControlData worldControlData)
        {
            //dont load currentGameState
            string currentGameState = this.worldControlData.currentGameState;
            this.worldControlData = worldControlData;
            //replace loaded currentGameState with old currentGameState
            this.worldControlData.currentGameState = currentGameState;

            Action loadedFocusAction = new Action(ScriptKeyword.FOCUS, new Dictionary<string, string>(){
            {ScriptKeyword.ID, worldControlData.FocusedGameObjectId}
            });
            this.takeFocusAction(loadedFocusAction);

            Action loadedTextAction = new Action(ScriptKeyword.TEXT, new Dictionary<string, string>(){
            {ScriptKeyword.CONTENT, worldControlData.textContent},
            {ScriptKeyword.TYPE, ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE}
            });
            if (FocusedGameObject.GetComponent<World>() != null) {
                updateNextAutoClickTime(FocusedGameObject.GetComponent<World>().takeTextAction(loadedTextAction));
            }
            if (FocusedGameObject.GetComponent<Character>() != null) {
                updateNextAutoClickTime(FocusedGameObject.GetComponent<Character>().takeTextAction(loadedTextAction));
            }

            //Load saved script to saved action index
            this.currentActions = scriptReader.loadNextScript(worldControlData.currentScriptName);
            for (int i = 0; i < worldControlData.currentActionIndex + 1; i++) {
                currentActions.RemoveAt(0);
            }
            //Recover history dialogs
            dialogContent.GetComponent<DialogManager>().historyDialogs = worldControlData.historyDialogs;
        }
Пример #31
0
        /// <summary>
        /// Character takes move action to move arround in the World, exactly arround the background GameObject
        /// </summary>
        /// <param name="moveAction">Action tagged as voice, which contains the parameters for voice setting</param>
        public void takeMoveAction(Action moveAction)
        {
            string positionValue = moveAction.parameters[ScriptKeyword.POSITION];

            if (positionValue == null || positionValue.Equals(""))
            {
                return;
            }
            if (positionValue.Equals(ScriptKeyword.POSITION_CENTER))
            {
                characterData.positionX = 0.5f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            }
            else if (positionValue.Equals(ScriptKeyword.POSITION_LEFT))
            {
                characterData.positionX = 0.2f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            }
            else if (positionValue.Equals(ScriptKeyword.POSITION_RIGHT))
            {
                characterData.positionX = 0.8f;
                characterData.positionY = 0f;
                characterData.positionZ = 0f;
            }
            else
            {
                //the position is written in (x.xxx, x.xxx, x.xxx)
                positionValue = positionValue.Replace(ScriptKeyword.PARENTHESE_LEFT, string.Empty);
                positionValue = positionValue.Replace(ScriptKeyword.PARENTHESE_RIGHT, string.Empty);
                positionValue = positionValue.Replace(@"\s+", string.Empty);
                string[] posString = positionValue.Split(ScriptKeyword.COMMA.ToCharArray());
                characterData.positionX = float.Parse(posString[0]);
                characterData.positionY = float.Parse(posString[1]);
                characterData.positionZ = float.Parse(posString[2]);
            }

            if (this.characterData.postureLive2D != null)
            {
                float width  = this.GetComponent <Renderer> ().bounds.size.x;
                float height = this.GetComponent <Renderer> ().bounds.size.y;
                Debug.Log("width=" + width);
                Debug.Log("height=" + height);
            }
            else if (this.characterData.postrueSrc != null)
            {
                //float backgroundWidth = worldControl.GetComponent<WorldControl>().world.GetComponent<World>().background.GetComponent<Renderer>().bounds.extents.x;
                //float backgroundHeight = worldControl.GetComponent<WorldControl>().world.GetComponent<World>().background.GetComponent<Renderer>().bounds.extents.y;
                //Debug.Log("characterData.posX = " + characterData.positionX + ", characterData.posY = " + characterData.positionY + ", characterData.posZ = " + characterData.positionZ);
                Vector3 characterScreenToWorldPoint = Camera.main.ViewportToWorldPoint(new Vector3(characterData.positionX, characterData.positionY
                                                                                                   , Mathf.Abs(Camera.main.transform.position.z)));

                //Here do the trajectory move
                string type;
                if (!moveAction.parameters.TryGetValue(ScriptKeyword.TYPE, out type))
                {
                }
                if (type != null)
                {
                    //string durationString;
                    //if (!moveAction.parameters.TryGetValue(ScriptKeyword.TYPE, out durationString)) {

                    //}
                    movingStartTime = System.DateTime.Now;
                    if (moving != null)
                    {
                        StopCoroutine(moving);
                    }
                    //Vector3 direction = characterScreenToWorldPoint - transform.localPosition;
                    moving = Moving(transform.localPosition, characterScreenToWorldPoint, 1f, type);
                    StartCoroutine(moving);
                }
                else
                {
                    this.transform.localPosition = characterScreenToWorldPoint;
                }
            }
        }
Пример #32
0
        /// <summary>
        /// WorldControl takes flag action to show flagBoard, wait for user to choose
        /// </summary>
        /// <param name="flagAction">Action tagged as flag, which contains the parameters for flag setting</param>
        public void takeFlagAction(Action flagAction)
        {
            if (this.worldControlData.currentGameState == GameConstants.AUTO) {
                clickAutoButton();
            }
            if (this.worldControlData.currentGameState == GameConstants.SKIP) {
                clickSkipButton();
            }
            if (this.worldControlData.currentGameState == GameConstants.NORMAL) {
                this.worldControlData.currentGameState = GameConstants.FLAG;
                flagBoardUI.SetActive(true);

                string count;
                if (flagAction.parameters.TryGetValue(ScriptKeyword.COUNT, out count)) {
                    List<string> texts = new List<string>();
                    for (int i = 0; i < int.Parse(count); i++) {
                        string text = flagAction.parameters[ScriptKeyword.OPTION_ + (i + 1)];
                        texts.Add(text);
                    }
                    List<System.Object> parameters = new List<object>();
                    for (int i = 0; i < int.Parse(count); i++) {
                        List<string> optionParameter = new List<string>();
                        optionParameter.Add("" + (i + 1));
                        optionParameter.Add(flagAction.parameters[ScriptKeyword.OPTION_ + (i + 1)]);
                        optionParameter.Add(flagAction.parameters[ScriptKeyword.OPTION_ID_ + (i + 1)]);
                        optionParameter.Add(flagAction.parameters[ScriptKeyword.OPTION_SRC_ + (i + 1)]);

                        parameters.Add(optionParameter);
                    }

                    setupTextButtonBoard(texts, flagTextPrefab, flagContent, false, onFlagTextButtonClick, parameters);
                }
            }
        }
Пример #33
0
 /// <summary>
 /// Character takes other actions you defined
 /// </summary>
 /// <param name="otherAction">Action tagged as other, which contains the parameters you defined</param>
 public void takeOtherAction(Action otherAction)
 {
 }
Пример #34
0
        public override Node ExitAction(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            if (node.Values.Count <= 1)
            {
                //detect >|>> to set the mode
                string mode = "";
                if (node.Values [0].ToString().Contains(ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE))
                {
                    mode = ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE;
                }
                else if (node.Values [0].ToString().Contains(ScriptKeyword.CLICK))
                {
                    mode = ScriptKeyword.CLICK;
                }
                //remove >|>> from the content
                string content = node.Values [0].ToString();
                content = content.Replace(ScriptKeyword.CLICK, string.Empty);
                //Text Action
                Action textAction = new Action(ScriptKeyword.TEXT, new Dictionary <string, string>()
                {
                    { ScriptKeyword.CONTENT, content },
                    { ScriptKeyword.MODE, mode }
                });
                actions.Add(textAction);
            }
            else if (node.Values[0].Equals(ScriptKeyword.VOICE))
            {
                //Voice Action
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                for (int i = 0; i < (node.Values.Count - 2) / 3; i++)
                {
                    parameters.Add(node.Values[i * 3 + 1].ToString(), node.Values[i * 3 + 3].ToString());
                }

                //detect >|>> to set the mode
                string mode = "";
                if (node.Values[node.Values.Count - 1].ToString().Contains(ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE))
                {
                    mode = ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE;
                }
                else if (node.Values[node.Values.Count - 1].ToString().Contains(ScriptKeyword.CLICK))
                {
                    mode = ScriptKeyword.CLICK;
                }
                //remove >|>> from the content
                string content = node.Values[node.Values.Count - 1].ToString();
                content = content.Replace(ScriptKeyword.CLICK, string.Empty);

                parameters.Add(ScriptKeyword.CONTENT, content);
                parameters.Add(ScriptKeyword.MODE, mode);
                Action voiceAction = new Action(ScriptKeyword.VOICE, parameters);
                actions.Add(voiceAction);
            }
            else
            {
                //Other Action
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                for (int i = 0; i < (node.Values.Count - 2) / 3; i++)
                {
                    parameters.Add(node.Values[i * 3 + 1].ToString(), node.Values[i * 3 + 3].ToString());
                }
                Action otherAction = new Action(node.Values[0].ToString(), parameters);
                actions.Add(otherAction);
            }

            /*
             * Console.Write ("Action: ");
             * for (int i = 0; i < node.Values.Count; i++) {
             *      Console.Write ("[" + i + "]" + node.Values[i] + " ");
             * }
             * Console.Write ("\n");
             */
            //node.PrintTo (Console.Out);

            return(node);
        }
Пример #35
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();
 }
Пример #36
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();
        }
Пример #37
0
        /// <summary>
        /// World takes background action to change the background effects, the background is a child GameObject below the World GameObject
        /// </summary>
        /// <param name="backgroundAction">Action tagged as background, which contains the parameters for background setting</param>
        public void takeBackgroundAction(Action backgroundAction)
        {
            worldData.backgroundSrc = backgroundAction.parameters[ScriptKeyword.SRC];

            this.worldControl.GetComponent<WorldControl> ().DisablePlayerInput ();
            this.worldControl.GetComponent<WorldControl> ().hideInPlayUI ();

            string transitionValue;
            if (backgroundAction.parameters.TryGetValue (ScriptKeyword.TRANSITION, out transitionValue)) {
                string transitionTimeString;
                float transitionTime = 1f;
                if (backgroundAction.parameters.TryGetValue (ScriptKeyword.TIME, out transitionTimeString)) {
                    transitionTime = float.Parse (transitionTimeString);
                }
                //Debug.Log ("transitionTime="+transitionTime);
                switch(transitionValue){
                case ScriptKeyword.TRANSITION_INSTANT:
                    {
                        this.BackgroundTransitionOnScreenObscured ();
                        this.BackgroundTransitionComplete ();
                        break;
                    }
                case ScriptKeyword.TRANSITION_FADE:
                    {
                        var fader = new FadeTransition()
                        {
                            nextScene = -1,
                            fadedDelay = transitionTime,
                            fadeToColor = Color.black
                        };
                        TransitionKit.instance.transitionWithDelegate( fader );
                        break;
                    }
                }
            } else {
                var fader = new FadeTransition()
                {
                    nextScene = -1,
                    fadedDelay = 1f,
                    fadeToColor = Color.black
                };
                TransitionKit.instance.transitionWithDelegate( fader );
            }
        }
Пример #38
0
        public override Node ExitBlock(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            /*
            Console.Write ("Block: ");
            for (int i = 0; i < node.Values.Count; i++) {
                Console.Write ("[" + i + "]" + node.Values[i] + " ");
            }
            Console.Write ("\n");
            */

            Action focusAction = new Action (ScriptKeyword.FOCUS, new Dictionary<string, string>(){
                {ScriptKeyword.ID, node.Values[0].ToString()}
            });
            int index = actions.IndexOf (emptyFocusAction);
            actions [index] = focusAction;

            return node;
        }
Пример #39
0
 /// <summary>
 /// World takes other actions you defined
 /// </summary>
 /// <param name="otherAction">Action tagged as other, which contains the parameters you defined</param>
 public void takeOtherAction(Action otherAction)
 {
 }
Пример #40
0
        public override Node ExitJump(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            //Jump action
            Action jumpAction = new Action (ScriptKeyword.JUMP, new Dictionary<string, string>(){
                {ScriptKeyword.SRC, node.Values[1].ToString()}
            });
            actions.Add (jumpAction);

            /*
            Console.Write ("Jump: ");
            for (int i = 0; i < node.Values.Count; i++) {
                Console.Write ("[" + i + "]" + node.Values[i] + " ");
            }
            Console.Write ("\n");
            */

            return node;
        }
Пример #41
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;
            }
        }
Пример #42
0
        public override Node ExitAction(Production node)
        {
            node.Values.AddRange(GetChildValues(node));

            if(node.Values.Count <= 1){
                //detect >|>> to set the mode
                string mode = "";
                if (node.Values [0].ToString ().Contains (ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE)) {
                    mode = ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE;
                } else if(node.Values [0].ToString ().Contains (ScriptKeyword.CLICK)) {
                    mode = ScriptKeyword.CLICK;
                }
                //remove >|>> from the content
                string content = node.Values [0].ToString ();
                content = content.Replace (ScriptKeyword.CLICK, string.Empty);
                //Text Action
                Action textAction = new Action (ScriptKeyword.TEXT, new Dictionary<string, string>(){
                    {ScriptKeyword.CONTENT, content},
                    {ScriptKeyword.MODE, mode}
                });
                actions.Add (textAction);
            }else if(node.Values[0].Equals(ScriptKeyword.VOICE)){
                //Voice Action
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                for(int i=0; i<(node.Values.Count - 2)/3 ;i++){
                    parameters.Add(node.Values[i*3+1].ToString(), node.Values[i*3+3].ToString());
                }

                //detect >|>> to set the mode
                string mode = "";
                if (node.Values[node.Values.Count-1].ToString().Contains (ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE)) {
                    mode = ScriptKeyword.CLICK_NEXT_DIALOGUE_PAGE;
                } else if(node.Values[node.Values.Count-1].ToString().Contains (ScriptKeyword.CLICK)) {
                    mode = ScriptKeyword.CLICK;
                }
                //remove >|>> from the content
                string content = node.Values[node.Values.Count-1].ToString();
                content = content.Replace (ScriptKeyword.CLICK, string.Empty);

                parameters.Add (ScriptKeyword.CONTENT, content);
                parameters.Add (ScriptKeyword.MODE, mode);
                Action voiceAction = new Action (ScriptKeyword.VOICE, parameters);
                actions.Add (voiceAction);
            }else{
                //Other Action
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                for(int i=0; i<(node.Values.Count - 2)/3 ;i++){
                    parameters.Add(node.Values[i*3+1].ToString(), node.Values[i*3+3].ToString());
                }
                Action otherAction = new Action (node.Values[0].ToString(), parameters);
                actions.Add (otherAction);
            }

            /*
            Console.Write ("Action: ");
            for (int i = 0; i < node.Values.Count; i++) {
                Console.Write ("[" + i + "]" + node.Values[i] + " ");
            }
            Console.Write ("\n");
            */
            //node.PrintTo (Console.Out);

            return node;
        }
Пример #43
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
            return 0;
        }