With Flower, you can not only setup your dialogs but also trigger functions (like showing images, playing audios, executing customized C#...) by plain text.
You can create your content in a text file efficiently, easily integrate with your own game logic with default Dialog and Button features.
For extensibility, you can customize your own commands and effects with parameters for objects in Unity.
- Setup Flower
- Writing Content
- Commands
- Dialog
- Button
- UI Stage
- Effects
- Variables
- Stop and Resume System
- Async Commands
- Settings
- Customized Event Functions
- Contribute
-
Setup Flower into your Unity project (Source Code / Unity Package).
-
Create FlowerSystem.
FlowerSystem flowerSys; flowerSys = FlowerManager.Instance.CreateFlowerSystem("FlowerSample", false);
-
Assign your dialog content via plain text file or string list.
Load the "start.txt" file from Resources folder and execute.
flowerSys.ReadTextFromResource("start");
Assign content via a string list, that means you can generate content dynamically.
flowerSys.SetTextList(new List<string>{"This is Flower System![w]"});
You can write your dialog text in the plain text file, and calling keyword commands for visual and auditory purpose and gameplay controlling.
Use brackets [keyword] (by defult) to set the keyword commands.
- If you want to print the brackets (SPECIAL_CHAR_STAR), just repeat it to make the words not a command.
- ex : ( [[w] -> print "[w]" )
1. text: Hello![l]World![w]
result: Hello!(wait for press)
result: Hello!World!(wait for press)
2. text: Hello![r]World![w]
result: Hello!
World!(wait for press)
3. text: Hello![lr]World![w]
result: Hello!(wait for press)
result: Hello!
World!(wait for press)
4. text: Hello![w]World![w]
result: Hello!(wait for press)
result: World!(wait for press)
[audio,bgm,bgm,true,0,audioTransit_1_2000]
[image,fg1,character_r,0,0,10,spFadeIn_1000]
It's raining...
[particle,p1,particle_rain,0,0]
[wait,1000]
[w]
[remove,p1]
It clears up.[w]
[remove,fg1,spFadeOut_1000]
Type | Keywords | Commands |
---|---|---|
💬 | l | Wait for press. |
💬 | r | Change the line. |
💬 | lr | Wait for press, and change the line. |
💬 | w | Wait for press, and erase the text. |
💬 | c | Erase the text. |
👀 | hide | Hide the text panel. |
👀 | show | Show the text panel. |
📌 | stop | Stop the system. |
📌 | resume | Resume the system. |
💬 | #VAR_NAME | Display the variable value. |
⏱ | wait | Waiting. |
🖼 | image | Show the image. |
🔊 | audio | Play the audio. |
⚡️ | effect | Apply the object effect. |
✨ | particle | Spawn a particle object. |
🗑 | remove | Remove the scene object. |
⏱ | wait_audio | Wait until the audio finishes playing. |
🖼 | ui_image | Show the image on the UI Stage. |
The Command Functions should follow the parameters : (List parameters). Parsing parameters and Executing.
private void CustomizedFunction(List<string> _params)
{
// Parse parameters.
var resultValue = int.Parse(_params[0]) + int.Parse(_params[1]);
Debug.Log($"Hi! This is called by CustomizedFunction with the result of parameters : {resultValue}");
}
Register this command and using [UsageCase] to call this customized command.
flowerSys.RegisterCommand("UsageCase", CustomizedFunction);
- DialogPrefab has to contain CanvasGroup component and "DialogPanel/DialogText" object with Unity UI Text component.
- Default will load "DefaultDialogPrefab" in resources folder.
flowerSys.SetupDialog();
flowerSys.RemoveDialog();
flowerSys.Next();
- ButtonGroup is a container to contain Buttons, if you want to setup Buttons, you need to setup ButtonGroup first.
- ButtonGroupPrefab need to contain CanvasGroup component and "ButtonPanel" object.
- Default will load "DefaultButtonGroupPrefab" in resource folder.
flowerSys.SetupButtonGroup();
- Default will load "DefaultButtonPrefab" in resource folder.
- The Button object will be appeneded to "ButtonGroup->ButtonPanel"
flowerSys.SetupButton("Button Demo.",()=>{
// Your code here...
flowerSys.Resume(); // Resume system.
flowerSys.RemoveButtonGroup(); // Remove the button group.
});
- UI Stage is a container to contain Unity UI stuff, if you want to setup UI Elements, you need to setup UI Stage first.
- The default sorting index of UI stage is 1.
- The default sorting index of Dialog is 9, thus, make stage order to 10 will render in front of the dialog panel.
flowerSys.SetupUIStage("default","DefaultUIStagePrefab",10);
Render UI Image on "default" UI Stage.
[ui_image,ui_fg1,character_image,0,0,default,uiImageFadeIn_1000]
Render UI Image...[w]
[remove,ui_fg1,uiImageFadeOut_1000]
Effect Name | Target | Commands |
---|---|---|
spFadeIn | 👾Sprite | Set sprite alpha from 0 to current. |
spFadeOut | 👾Sprite | Set sprite alpha from current to 0. |
moveTo | 🧊GameObject | Move to the position (pixel). |
audioTransit | 🔊AudioSource | Set the volume from current to value. |
canvasGroupTransit | 🖼CanvasGroup | Set the alpha from current to value. |
uiImageFadeIn | 🖼UI-Image | Set the alpha from 0 to current. |
uiImageFadeOut | 🖼UI-Image | Set the alpha from current to 0. |
Define a IEnumerator task for rotating objects.
IEnumerator CustomizedRotationTask(string key, GameObject obj, float endTime){
Vector3 startRotation = obj.transform.eulerAngles;
Vector3 endRotation = obj.transform.eulerAngles + new Vector3(90,0,0);
// Apply default timer Task.
yield return flowerSys.EffectTimerTask(key, endTime, (percent)=>{
// Update function.
obj.transform.eulerAngles = Vector3.Lerp(startRotation, endRotation, percent);
});
}
The Effect Functions should follow the parameters : (string key, List parameters). Parsing parameters, Extracting targets and Executing tasks.
private void EffectCustomizedRotation(string key, List<string> _params){
try{
// Parse parameters.
float endTime;
try{
endTime = float.Parse(_params[0])/1000;
}catch(Exception e){
throw new Exception($"Invalid effect parameters.\n{e}");
}
// Extract targets.
GameObject sceneObj = flowerSys.GetSceneObject(key);
// Apply tasks.
StartCoroutine(CustomizedRotationTask($"CustomizedRotation-{key}", sceneObj, endTime));
}catch(Exception){
}
}
Register this effect and using customizedRotation_endTime as the EffectName.
flowerSys.RegisterEffect("customizedRotation", EffectCustomizedRotation);
You can setup variables and using in dialogs / commands / effects with VAR_CHAR (Default '#')
flowerSys.SetVariable("myInfo", "( ゚д゚)");
flowerSys.SetVariable("myXPosition", "300");
flowerSys.SetVariable("myTransitTime", "2000");
Hello [#myInfo].
[image, img_1, test_image, #myXPosition, 0]
[effect, img_1, spFadeOut_#myTransitTime]
Use [stop] command or .Stop() function to pause the system.
Use .Resume() function to resume the system.
flowerSys.Resume();
Async Commands can be executed asynchronously.
Type | Keywords |
---|---|
🖼 | async_image |
🔊 | async_audio |
⚡️ | async_effect |
🗑 | async_remove |
The center of the screen is (x:0, y:0), and the unit is pixel.
Set the screen setting, your image size and position will follow this setting for built-in commands and effects.
flowerSys.SetScreenReference(1280, 720);
Get the Scene Object that match the key.
flowerSys.GetSceneObject("Scene Object Key")
Query the Scene Objects that match the regular expression pattern.
flowerSys.QuerySceneObject("Regular Expression Pattern")
flowerSys.RegisterToSceneObject("KEY", gameObject)
To apply global settings like Music & Sound Volumes, etc.
You can use Variables to inject the setting values to Commands for New Objects.
You can use Query Scene Objects to query the target scene objects by Key, and apply the settings to Exist Objects.
- Turn on Auto mode.
flowerSys.processMode = ProcessModeType.Auto;
- Turn off Auto mode.
flowerSys.processMode = ProcessModeType.Normal;
You can customized your own text updating function, for example, updating the text to TextMesh.
flowerSys.SetupDialog("DefaultDialogPrefab", false);
flowerSys.textUpdated += (object sender, TextUpdateEventArgs args)=>{
// Your text updating function here...
// print(args.text);
};
You can customized your own log function, for example, only handling error logs and stop the game or storing the logs into log files.
flowerSys.isDefaultLogEnable=false;
flowerSys.logHappened += (object sender, LogEventArgs args)=>{
print($"[{args.type}]{args.message}");
};
Do you want to improve Flower? Welcome :)!
If you find some bugs, have any suggestion for features / improvements, feel free to create issues or send pull requests. (●'◡'●)