Commit 691abf8c authored by 18김민수's avatar 18김민수

Choice works fine now.

parent 56513006
......@@ -63,12 +63,12 @@ namespace ISEKAI_Model
public bool IsFirstVisible() // if this returns true, event is set to Visible. (or ForcedVisible)
{
bool result;
result = exclusiveCondition() && seasonCheck();
result = exclusiveCondition() && SeasonCheck();
if (result) _seasonMadeIn = game.turn.season;
return result && !isRemovedLastTurn;
}
public bool seasonCheck()
public bool SeasonCheck()
{
bool seasonCheck;
if (availableSeason == Season.None)
......
......@@ -19,7 +19,9 @@ namespace ISEKAI_Model
public Turn turn {get; private set; } // indicating season, turn number, etc. see Turn class.
public bool isIronActivated = false;
public bool isHorseActivated = false;
public bool isRangedWeaponActivated = false;
public bool isArrowWeaponActivated = false;
public bool isBowActivated = false;
public bool isRifleActivated = false;
public Dictionary<string, List<(int, int)>> choiceHistories = new Dictionary<string, List<(int, int)>>(); // <item1>th choice, selected <item2>th branch. (0-based)
public List<EventCore> allEventsList = new List<EventCore>();
public List<EventCore> forcedVisibleEventList { get
......@@ -131,7 +133,7 @@ namespace ISEKAI_Model
result = toChange - f;
return result;
default:
throw new InvalidOperationException("Error on ApplyChoiceEffect()");
throw new InvalidOperationException(toChange.ToString() + " " + type.ToString() + " " + f.ToString());
}
}
......@@ -180,7 +182,7 @@ namespace ISEKAI_Model
}
else if (e.isActivatedAlready)
{
if (e.seasonCheck() && e.turnsLeft > 0)
if (e.SeasonCheck() && e.turnsLeft > 0)
e.status = EventStatus.Visible;
else
e.status = EventStatus.Ready;
......@@ -190,9 +192,9 @@ namespace ISEKAI_Model
private void _InitEvents() // should add EVERY events when new event plan comes.
{
allEventsList.Add(new ExampleEvent1(this));
allEventsList.Add(new Prolog_1(this));
allEventsList.Add(new Prolog_2(this));
//allEventsList.Add(new ExampleEvent1(this));
//allEventsList.Add(new Prolog_1(this));
//allEventsList.Add(new Prolog_2(this));
allEventsList.Add(new Farming_1(this));
allEventsList.Add(new Farming_2(this));
}
......
......@@ -8,12 +8,12 @@ namespace ISEKAI_Model
{
public abstract int commandNumber {get;}
public (int, int) choiceDependency {get; set;} // (0, 0) if there is no choice dependency. (0, n) if there is dependency on recent choice, which resulted 'n'.
public (int, int) choiceDependency {get; set;} // (-1, -1) if there is no choice dependency. (-1, n) if there is dependency on recent choice, which resulted 'n'.
// (n, m) if there is dependency on n'th choice, which resulted 'm'.
public Command()
{
choiceDependency = (0, 0);
choiceDependency = (-1, -1);
}
}
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ namespace ISEKAI_Model
@"^(\d?)\-?\-?(\d?) ?Load Minigame ""(.*)""$", //13
@"^(\d?)\-?\-?(\d?) ?Load Video ""(.*)""$", //14
@"^(\d?)\-?\-?(\d?) ?Choice$", //15
@"-- ""(.*)""( \-(\w+) \(([\+\-\*])(\d+)\))*$", // 16
@"-- ""(.*)""( \-(\w+) \(([\+\-\*])(\d+)\))*", // 16
@"^(\d?)\-?\-?(\d?) ?VFXTransition$", //17
@"^(\d?)\-?\-?(\d?) ?VFXPause \-(.*)$"}; //18
private static SpriteLocation _ParseSpriteLocation(string location)
......@@ -60,13 +60,13 @@ namespace ISEKAI_Model
private static ChoiceEffectType _ParseChoiceEffectType(string type)
{
if (type.Equals("Add"))
if (type.Equals("+"))
return ChoiceEffectType.Add;
else if (type.Equals("Divide"))
else if (type.Equals("/"))
return ChoiceEffectType.Divide;
else if (type.Equals("Substract"))
else if (type.Equals("-"))
return ChoiceEffectType.Subtract;
else if (type.Equals("Multiply"))
else if (type.Equals("*"))
return ChoiceEffectType.Multiply;
else
return ChoiceEffectType.None;
......@@ -79,7 +79,7 @@ namespace ISEKAI_Model
int cNumber;
int cResult = int.Parse(choiceResult);
if (choiceNumber == "")
cNumber = 0;
cNumber = -1;
else
cNumber = int.Parse(choiceNumber);
command.choiceDependency = (cNumber,cResult);
......@@ -213,9 +213,9 @@ namespace ISEKAI_Model
string choiceName = match.Groups[1].Value;
for (int _counter = 0; _counter < match.Groups[3].Captures.Count; _counter++)
{
var choiceEffectKind = _ParseChoiceEffectKind(match.Groups[3].Captures[_counter].Value);
var choiceEffectType = _ParseChoiceEffectType(match.Groups[4].Captures[_counter].Value);
float choiceEffectAmount = float.Parse(match.Groups[5].Captures[_counter].Value);
var choiceEffectKind = _ParseChoiceEffectKind(match.Groups[3].Captures[_counter].Value.Trim());
var choiceEffectType = _ParseChoiceEffectType(match.Groups[4].Captures[_counter].Value.Trim());
float choiceEffectAmount = float.Parse(match.Groups[5].Captures[_counter].Value.Trim());
effectList.Add((choiceEffectKind, choiceEffectType, choiceEffectAmount));
}
var choiceEffect = new ChoiceEffect(choiceBranchNumber, choiceName, effectList);
......
Load Background "Backgrounds\fields.png"
Load Background "Backgrounds\fields"
# "선녀가 가르켜 준대로 마을 바깥으로 나오자, 다시 그 이상한 작물이 잔뜩 심겨진 드넓은 밭이 보였다."
# "내가 가야할 곳이 어딘지를 찾는건 어렵지 않았다. 저 멀리서 선녀와 일행이 팔을 흔드며 나에게 인사를 해오고 있었기 때문이다. 나도 인사를 하며 그쪽으로 걸어갔다."
Load Character "Sprites\Heroine\b\normal.png" -left
Load Character "Sprites\Rancher\b\normal.png" -right
Load Character "Character\Heroine\b\normal" -left
Load Character "Character\Rancher\b\normal" -right
## "선녀" "야, 쟝 동무, 무사히 길을 찾아왔기래." -left
# "선녀는 밝은 미소를 지으며 나에게 먼저 말을 걸어왔다. 옆에 있던 다른 사내는 반면 그렇게 좋은 기분인 듯은 아니어 보였다."
## "???" "흠, 이름이 쟝 동무라고 했소." -right
......@@ -17,7 +17,7 @@ Load Character "Sprites\Rancher\b\normal.png" -right
# "설명은 한동안 계속 됬고, 나는 내용을 숙지 했다."
Unload Character -right
Unload Character -left
Load Character "Sprites\Heroine\b\normal.png" -center
Load Character "Character\Heroine\b\normal" -center
## "선녀" "하하....통계원 동지는 원래 조금 까칠하긴 할수다." -center
## "선녀" "하지만 그래도 마을을 위해 진심으로 걱정하는 동지니, 너무 험하게 생각하지 말시오다." -center
Unload Character -center
......@@ -36,10 +36,10 @@ Choice
-- "귀리를 재배한다." -FoodP (+5) -Food (+5) -Morale (-10)
-- "호밀을 재배한다." -FoodP (+5) -Food (+10) -Morale (-20)
-#
--1 # "보리는 분명 지력을 깍아 먹긴 하지만, 마을에는 지금 당장 음식이 필요하다. "
--1 # "땅이 힘들어 하면 내년에는 휴경지로 해서 복구를 하면 될테이니, 보리를 기르자."
--2 # "귀리는 비록 수확량이 적기는 하지만, 이세계에 떨어진 이상 장기적으로 생각을 해야 한다. "
--2 # "땅의 지력을 최대한 빨리 회복시키는 것이 불안정한 내년의 기후에 기대는 것보단 더 안전할 테니, 귀리를 기르자."
--3 # "호밀은 비록 맛이 되게 없긴 하지만, 귀리의 수확량 만으로는 마을 사람들에게 나를 증명하지 못할 지도 모른다. "
--3 # "지력도 회복시키고 적당한 수확량을 기대할수 있는 호밀을 기르자."
--0 # "보리는 분명 지력을 깍아 먹긴 하지만, 마을에는 지금 당장 음식이 필요하다. "
--0 # "땅이 힘들어 하면 내년에는 휴경지로 해서 복구를 하면 될테이니, 보리를 기르자."
--1 # "귀리는 비록 수확량이 적기는 하지만, 이세계에 떨어진 이상 장기적으로 생각을 해야 한다. "
--1 # "땅의 지력을 최대한 빨리 회복시키는 것이 불안정한 내년의 기후에 기대는 것보단 더 안전할 테니, 귀리를 기르자."
--2 # "호밀은 비록 맛이 되게 없긴 하지만, 귀리의 수확량 만으로는 마을 사람들에게 나를 증명하지 못할 지도 모른다. "
--2 # "지력도 회복시키고 적당한 수확량을 기대할수 있는 호밀을 기르자."
# "그렇게 마음을 정한 나는 세 달 동안 뼈 빠지게 밭을 갈구며 농사를 했다."
\ No newline at end of file
Load Background "Background\fields.png"
Load Character "Character\farmer\a\normal.png" -center
Load Background "Background\fields"
Load Character "Character\farmer\a\normal" -center
## "마을 사람" "아이고~ 우린 이제 망했다~" -center
# "수확할 시기가 되자 내 우려는 현실이 됬다."
# "마을의 밭에는 시들어 가거나 제대로 자라지 못한 작물들로 가득했다."
......@@ -7,8 +7,8 @@ Load Character "Character\farmer\a\normal.png" -center
# "물론 내가 담당한 밭의 일부는 풍성하게 자라 있었다."
# "분명 이번 년 마을 사람들은 음식을 아끼며 배고프게 지내야 하겠지만, 적어도 풍요로운 내 밭의 모습은 그들에게 조금이 나마 안심이 되겠지, 라던지의 생각을 나는 했다."
Unload Character -center
Load Character "Character\Heroine\b\sad.png" -left
Load Character "Character\Father\b\sad.png" -right
Load Character "Character\Heroine\b\sad" -left
Load Character "Character\Father\b\sad" -right
## "작업반장 동지" "흠......쟝 동무, 뭐라 할 말이 없구먼 그래." -right
## "작업반장 동지" "그저 의심해서 미안하고, 이해해 줬으면 부탁한다 할 수 밖에 없다네." -right
## "작업반장 동지" "우리가 자네 말을 들었더라면 당이랑 연락이 복귀될 때까지 조금을 버텨봤을수도 있겠지만......" -right
......@@ -62,7 +62,7 @@ Choice
-- "휴경지에 토끼풀을 심는다" -FoodP (+80) -Food (+10) -Morale (-20)
-- "휴경지에 콩과 순무를 심는다" -FoodP (+30) -Food (+50) -Morale (-10)
-#
--1 # "그래, 안전하게 가는 것이 좋다. 뭔가를 옮겨 심을 필요 없으니 마을 사람들도 덜 힘들 것이다."
--2 # "실험적이지만, 장기적으로나 단기적으로 지금 당장 지력을 회복시키지 않으면 위험했다."
--2 # "토끼풀을 심게 하자."
--3 # "단기적으로 지력을 깍아 먹겠지만, 적어도 콩과 순무가 수확되면 이를 어느 정도 상쇄해줄지도 모른다. 게다가 장기적으론 이 방법이 제일 확실했다."
\ No newline at end of file
--0 # "그래, 안전하게 가는 것이 좋다. 뭔가를 옮겨 심을 필요 없으니 마을 사람들도 덜 힘들 것이다."
--1 # "실험적이지만, 장기적으로나 단기적으로 지금 당장 지력을 회복시키지 않으면 위험했다."
--1 # "토끼풀을 심게 하자."
--2 # "단기적으로 지력을 깍아 먹겠지만, 적어도 콩과 순무가 수확되면 이를 어느 정도 상쇄해줄지도 모른다. 게다가 장기적으론 이 방법이 제일 확실했다."
\ No newline at end of file
This diff is collapsed.
using UnityEngine;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class FuriganaText : MonoBehaviour
{
public string text;
public Rect position;
public GUISkin skin;
public string textStyle = "Label";
public string furiStyle = "Furigana";
public float yOffset = 10;
static Regex furiRegex;
void OnGUI()
{
GUI.skin = skin;
if (furiRegex == null)
{
furiRegex = new Regex("\\[(.*?):(.*?)\\]");
}
string cleanText; // base text, without any furigana or markup
List<int> furiCharIndex = new List<int>(); // char index (in base text) where furigana appears
List<int> furiCharLen = new List<int>(); // length of base text the furigana is over
List<string> furiText = new List<string>(); // actual text of the furigana
cleanText = text;
while (true)
{
Match match = furiRegex.Match(cleanText);
if (!match.Success) break;
furiCharIndex.Add(match.Index);
furiText.Add(match.Groups[2].ToString());
furiCharLen.Add(match.Groups[1].Length);
cleanText = cleanText.Substring(0, match.Index) + match.Groups[1]
+ cleanText.Substring(match.Index + match.Length);
}
GUIStyle textGUIStyle = skin.GetStyle(textStyle);
GUIContent cleanContent = new GUIContent(cleanText);
GUI.Label(position, cleanContent, textGUIStyle);
GUIStyle furiGUIStyle = skin.GetStyle(furiStyle);
for (int i = 0; i < furiCharIndex.Count; i++)
{
Vector2 leftPos = textGUIStyle.GetCursorPixelPosition(position, cleanContent, furiCharIndex[i]);
Vector2 rightPos = textGUIStyle.GetCursorPixelPosition(position, cleanContent,
furiCharIndex[i] + furiCharLen[i]);
Rect r = new Rect(leftPos.x, leftPos.y - yOffset - 20, rightPos.x - leftPos.x, 20);
GUI.Label(r, furiText[i], furiGUIStyle);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: fcf27e1f3d1676946890d2b3b68c8b3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -105,7 +105,7 @@ public class GameManager : MonoBehaviour
if (sd == null)
return;
EventCore e = GetEventCoreFromEventSd(sd);
if (e.seasonCheck())
if (e.SeasonCheck())
sd.gameObject.SetActive(true);
else
sd.gameObject.SetActive(false);
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EndingGameCamera : MonoBehaviour
{
int width = Screen.width;
int boundary = 50;
int speed = 10;
// Update is called once per frame
void Update()
{
if (Camera.main.transform.position.x >= -15 && Input.mousePosition.x < boundary)
Camera.main.transform.Translate(-speed * Time.deltaTime, 0, 0);
if (Camera.main.transform.position.x <= 15 && Input.mousePosition.x > width - boundary)
Camera.main.transform.Translate(speed * Time.deltaTime, 0, 0);
}
}
fileFormatVersion: 2
guid: 591ac3f201cab494294cc9d47d10ab36
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,14 +2,106 @@
using System.Collections.Generic;
using UnityEngine;
using ISEKAI_Model;
using System.Linq;
public class EndingGameUnit : MonoBehaviour
public abstract class EndingGameUnit : MonoBehaviour
{
public string unitName;
public abstract int unitNumber { get; }
public abstract string unitName { get; }
public int hp;
public int attackPower;
public int attackSpeed;
public int attackRange;
public int productionTime;
public int speed;
public abstract int attackPower { get; }
public abstract int attackSpeed { get; }
public abstract int attackRange { get; }
public const int speed = 2;
public bool isInBattleState = false;
public abstract bool isAllyUnit { get; }
public EndingGameUnit frontUnit;
public EndingGameManager endingGame;
public EndingGameUnit attackTarget { get
{
GameObject potentialTarget; //= endingGame.deployedEnemyUnits.FirstOrDefault();
if (isAllyUnit) potentialTarget = endingGame.deployedEnemyUnits.FirstOrDefault();
else potentialTarget = endingGame.deployedAllyUnits.FirstOrDefault();
if (potentialTarget == null)
return null;
else if (Mathf.Abs(potentialTarget.transform.position.x - transform.position.x) <= attackRange)
return potentialTarget.GetComponent<EndingGameUnit>();
else
return null;
}
}
public virtual void Update()
{
if (attackTarget != null && !isInBattleState)
{
InvokeRepeating("Attack", 0.5f, attackSpeed);
isInBattleState = true;
}
if (attackTarget == null)
{
isInBattleState = false;
CancelInvoke("Attack");
}
if (!isInBattleState)
transform.Translate(speed * Time.deltaTime, 0, 0);
}
public void Attack()
{
if (attackTarget == null)
return;
attackTarget.hp -= attackPower;
attackTarget.transform.GetChild(0).GetComponent<TextMesh>().text = "HP: " + attackTarget.hp;
if (attackTarget.hp <= 0)
{
if (isAllyUnit)
endingGame.deployedEnemyUnits.Dequeue();
else
endingGame.deployedAllyUnits.Dequeue();
Destroy(attackTarget);
}
}
/*public void TryEnterBattleState()
{
isInBattleState = true;
if (attackTarget == null)
{
isInBattleState = false;
return;
}
StartCoroutine(StartBattle());
}
public virtual IEnumerator StartBattle()
{
while(attackTarget != null)
{
attackTarget.hp -= attackPower;
if (attackTarget.hp <= 0)
{
if (isAllyUnit)
endingGame.deployedEnemyUnits.Dequeue();
else
endingGame.deployedAllyUnits.Dequeue();
Destroy(attackTarget.gameObject);
ExitBattleState();
yield break;
}
yield return new WaitForSeconds(attackSpeed);
}
}
public void ExitBattleState()
{
isInBattleState = false;
}*/
}
fileFormatVersion: 2
guid: e9a1d00ea9d76e34a99f2f26c95fcddc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Archer : EndingGameUnit
{
public override int unitNumber => 3;
public override string unitName { get { return "궁병"; } }
public override int attackPower { get { return 6; } }
public override int attackSpeed { get { return 1; } }
public override int attackRange { get { return 20; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: bdfec5ebf583e24488cd5c91adaebdfb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Crossbowman : EndingGameUnit
{
public override int unitNumber => 4;
public override string unitName { get { return "석궁병"; } }
public override int attackPower { get { return 10; } }
public override int attackSpeed { get { return 3; } }
public override int attackRange { get { return 5; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: 38f27e2f6af0c6e4b8b4594f12815bd4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class Farmer : EndingGameUnit
{
public override int unitNumber => 0;
public override string unitName { get { return "농민"; } }
public override int attackPower { get { return 5; } }
public override int attackSpeed { get { return 2; } }
public override int attackRange { get { return 1; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: c87edfaef174f0743a9d72ff87f5bce2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IronCrossbowman : EndingGameUnit
{
public override int unitNumber => 5;
public override string unitName { get { return "석궁병(철)"; } }
public override int attackPower { get { return 20; } }
public override int attackSpeed { get { return 4; } }
public override int attackRange { get { return 15; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: bd5828989b7e26a4abf18227c1442abb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class IronRifleman : EndingGameUnit
{
public override int unitNumber => 7;
public override string unitName { get { return "소총병(철)"; } }
public override int attackPower { get { return 20; } }
public override int attackSpeed { get { return 3; } }
public override int attackRange { get { return 20; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: 50209c85b5796c64d81cc77ef008689b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class Knight : EndingGameUnit
{
public override int unitNumber => 8;
public override string unitName { get { return "기사"; } }
public override int attackPower { get { return 25; } }
public override int attackSpeed { get { return 2; } }
public override int attackRange { get { return 1; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: 207e4c2da994a5a4db8417fbb7882a3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class Pikeman : EndingGameUnit
{
public override int unitNumber => 2;
public override string unitName { get { return "파이크병"; } }
public override int attackPower { get { return 25; } }
public override int attackSpeed { get { return 2; } }
public override int attackRange { get { return 1; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: 413a96063715a1b4f902d16d4ec537b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class Rifleman : EndingGameUnit
{
public override int unitNumber => 6;
public override string unitName { get { return "소총병"; } }
public override int attackPower { get { return 20; } }
public override int attackSpeed { get { return 3; } }
public override int attackRange { get { return 20; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: 4e0f51bf7f4b42e469cd8b0adfcc699e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spearman : EndingGameUnit
{
public override int unitNumber => 1;
public override string unitName { get { return "창병"; } }
public override int attackPower { get { return 10; } }
public override int attackSpeed { get { return 2; } }
public override int attackRange { get { return 1; } }
public override bool isAllyUnit => true;
}
fileFormatVersion: 2
guid: a87e57f34de0ceb4ab4ef8bad072008c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2017 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
/*
* *注意*
* 改行の処理はしてない.ルビを必要とする部分が途中で改行されないよう処理する必要がある.
* http://dskjal.com/unity/detect-unity-ugui-break-pos.html を参照.
*/
/*
* 設定方法
* uGUI の Text にこのスクリプトをつける.
* テキストのセンタリング設定をした uGUI の Text のプレハブを作り TextPrefab にセット
* プレハブのフォントサイズをテキストのフォントサイズの 1/2 ぐらいにする
*/
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Text), typeof(RectTransform))]
public class RubyText : MonoBehaviour
{
Text text;
RectTransform rt;
public GameObject TextPrefab; // テキストはセンタリングしておくこと
class RubyPos
{
public int start; // ルビの開始インデックス
public int end; // ルビの終了インデックス
public string ruby; // ルビ
public RubyPos(int start, int end, string ruby)
{
this.start = start;
this.end = end;
this.ruby = ruby;
}
}
void Awake()
{
text = GetComponent<Text>();
rt = GetComponent<RectTransform>();
text.text = "ルビが必要な例文章です.";
RubyPos[] rubyPos = new RubyPos[] {
new RubyPos(3, 4, "ひつよう"),
new RubyPos(6, 8, "れいぶんしょう")
};
var generator = new TextGenerator();
// テキストのレンダリング位置の計算
generator.Populate(text.text, text.GetGenerationSettings(rt.sizeDelta));
// 各文字のレンダリング位置を記録した文字配列の取得
var charArray = generator.GetCharactersArray();
foreach (var ruby in rubyPos)
{
var start = charArray[ruby.start].cursorPos;
var end = charArray[ruby.end].cursorPos;
end.x += charArray[ruby.end].charWidth;
PlaceRuby(start.x + (end.x - start.x) / 2f, start.y, ruby.ruby);
}
}
// TextPrefab をインスタンス化して配置する
void PlaceRuby(float x, float y, string text)
{
var o = GameObject.Instantiate(TextPrefab);
o.name = text;
o.transform.SetParent(this.transform);
var prt = o.GetComponent<RectTransform>();
prt.localPosition = new Vector3(x, y + 20f, 0f);
o.GetComponent<Text>().text = text;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: e2f1c6fe0d997ed4ebdbeca66a07a4c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -46,9 +46,4 @@ public class UIEventManager : MonoBehaviour
{
eventManager.ExecuteOneScript();
}
public void OnClickChoiceButton()
{
eventManager.ExecuteOneScript();
}
}
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7599768825830375945
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 1395348124393148831, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
m_PrefabInstance: {fileID: 4355193619288105378}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1042470071441416713}
- component: {fileID: 8718288063956100455}
- component: {fileID: 1462120732831734092}
m_Layer: 0
m_Name: EndingGameUnitPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1042470071441416713
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
m_PrefabInstance: {fileID: 4355193619288105378}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7599768825830375945}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2.85, y: -5.06, z: -9.61}
m_LocalScale: {x: 1.266, y: 1.266, z: 1.266}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &8718288063956100455
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7599768825830375945}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 436c64015c134dc4596ec2137226da42, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 6, y: 6}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &1462120732831734092
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7599768825830375945}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cee9d627ee32e8e439d8a3ce006946f3, type: 3}
m_Name:
m_EditorClassIdentifier:
unitName:
hp: 0
attackPower: 0
attackSpeed: 0
attackRange: 0
productionTime: 0
--- !u!1001 &4355193619288105378
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1395348124393148831, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_Name
value: EndingGameUnitPrefab
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalPosition.x
value: -2.85
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalPosition.y
value: -5.06
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalPosition.z
value: -9.61
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalScale.x
value: 1.266
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalScale.y
value: 1.266
objectReference: {fileID: 0}
- target: {fileID: 8384877610517066143, guid: 31aae915f842bcb48a5193fa531b810a,
type: 3}
propertyPath: m_LocalScale.z
value: 1.266
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 31aae915f842bcb48a5193fa531b810a, type: 3}
fileFormatVersion: 2
guid: c5fafe1f2bc0fe148a113cf6773da03f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: d4b22d2babab44e408248dfe374167ce
guid: 87c1b8fbb9598274580c2adb668471f7
PrefabImporter:
externalObjects: {}
userData:
......
fileFormatVersion: 2
guid: 70165d275e9c5b146ae5597effe88589
guid: 3933c48a515112e4a898e1c7a0cbf8cc
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
fileFormatVersion: 2
guid: 1002aaa1852230049bbe345fd2ef0d14
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5a98bb810d5b3024293909747aa89de8
guid: 7ff174ce45504ed41896d73a3ecb9918
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
......@@ -75,7 +75,7 @@ TextureImporter:
outline: []
physicsShape: []
bones: []
spriteID: 929dd0dc2a3050341b218dde8d8b50ea
spriteID: f8520216e0f9af54e8df0785f2dffba3
vertices: []
indices:
edges: []
......
fileFormatVersion: 2
guid: 58a394f9f5bd0cc409a80e43953a10a1
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 7
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: ab756f0e181edfb4b83f4b4d39c011f6
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
fileFormatVersion: 2
guid: 29b18fce701789f4dbd7113ad9d5008a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment