[Unity combat] story dialogue

Source: Internet
Author: User

On the internet to see a good article, is about the game of the story animation, feel to do a thing is also very fun, so there is this article. The game in the plot (non-CG animation) There are two main, one is automatic playback, the other is a dialogue. Can be in the plot of animation (the animation here not only contains character animation, but also includes displacement, rotation, time waits and so on) as a kind of state (a bit like a state machine), put into a list or queue, whenever a state is completed and then jump to the next state, so it will form a serial animation of the plot.


It is important to note that in the normal state, an action completion will jump to the next action, but in the dialog state, an action will not automatically jump to the next action when it is completed, but each new conversation will trigger the action.


Here you give the core code (an action base class and a class for managing actions):

Using unityengine;using System.collections;public class Command {public    virtual void Execute () {} public    void Ne XT ()     {        CommandManager.instance.Next2 ();    }}

Using unityengine;using system.collections;using system.collections.generic;public class Commandmanager:    Monobehaviour {public static Commandmanager instance;    Private list<command> commands = new list<command> ();    private int nowindex = 0;    public bool Isdialoguemode = FALSE; Cache transform [Serializefield] public list<string> startobj = new list<string> ();//The object that existed at the beginning is public D    ictionary<string,transform> allobj = new dictionary<string,transform> ();    void Awake () {instance = this; } void Start () {for (int i = 0; i < startobj.capacity;i++) Allobj.add (Startobj[i], gameobject .        Find (Startobj[i]). Transform); Commands.        ADD (New Commandmusic ("Taylor swift-red")); Scene a dialogue driven screen commands.        ADD (New Commanddialoguemodeenter ()); Commands.        ADD (New Commanddialogue ("Story1", 0, 0, 1)); Commands.    ADD (New Commandmove ("Main Camera", New Vector3 ( -3.5f, 3.4f, -5.5f), 6f));    Commands.        ADD (New Commanddialogue ("Story1", 1, 1, 2)); Commands.        ADD (New Commandmove ("Main Camera", New Vector3 ( -4.8f, 3.4f, -4.8f), 0f)); Commands.        ADD (New Commandmove ("Main Camera", New Vector3 ( -2.5f, 3.4f, -4.8f), 5f)); Commands.        ADD (New Commanddialogue ("Story1", 2, 2, 3)); Commands.        ADD (New Commandrotate ("Main Camera", New Vector3 (10f, 180f, 0f), 0f)); Commands.        ADD (New Commandmove ("Main Camera", New Vector3 ( -2.5f, 3.4f, -1f), 0f)); Commands.        ADD (New Commandmove ("Main Camera", New Vector3 ( -4.6f, 3.4f, -1f), 5f)); Commands.        ADD (New Commanddialoguemodeexit ()); Scene two auto commands.        ADD (New Commandmove ("Main Camera", New Vector3 ( -20.5f, 5.8f, -7.9f), 0f)); Commands.        ADD (New Commandrotate ("Main Camera", New Vector3 (12f, 180f, 0f), 0f)); Commands.        ADD (new commandwait (2f)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior1", AnimatorManager.instance.run)); Commands. ADD (New Commandplayanim ("Skeleton_warrior2 ", AnimatorManager.instance.run)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior3", AnimatorManager.instance.run)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior4", AnimatorManager.instance.run)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior5", AnimatorManager.instance.run)); Commands.        ADD (new commandwait (2f)); Commands.        ADD (New Commandplayanim ("Magic", AnimatorManager.instance.attack1)); Commands.        ADD (New commandwait (1f)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior1", AnimatorManager.instance.dead)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior2", AnimatorManager.instance.dead)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior3", AnimatorManager.instance.dead)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior4", AnimatorManager.instance.dead)); Commands.        ADD (New Commandplayanim ("Skeleton_warrior5", AnimatorManager.instance.dead)); Commands. ADD (New Commandplayanim ("Magic", AnimatorManager.instance.stand)); Commands.        ADD (New Commanddialogue ("Story1", 3, 5, 0)); Commands.    ADD (New commandwait (1f)); } void Update () {if (Input.getkeydown (KEYCODE.Q)) Commands[nowindex].    Execute ();        }//Dialog mode directly into the next state public void next () {nowindex++; if (Nowindex < commands. Count) Commands[nowindex].    Execute ();        }//Auto mode directly into the next state public void Next2 () {if (Isdialoguemode) return;    else Next (); }}

You just need to write some classes of inherited command to achieve the desired effect. The following are the classes that I extend myself:








Full video link: http://v.youku.com/v_show/id_XOTMxMjIyMDU2.html

About two minutes, it is recommended to play in full-screen mode (because it is not very clear), I think the plot is very good ...

A better approach is to write an editor class that will save the configuration (either in XML or JSON file) and read each time it is run. But here first put, recently good busy AH (because of the course of the relationship, sophomore than before are busy AH), do not know the next time to write a blog when! Hey!

[Unity combat] story dialogue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.