Skip to content

Instantly share code, notes, and snippets.

@muzudho
Last active January 27, 2017 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muzudho/8e54f75c1dfbbb20567975f802471f9a to your computer and use it in GitHub Desktop.
Save muzudho/8e54f75c1dfbbb20567975f802471f9a to your computer and use it in GitHub Desktop.
UnityEditorを使って2D格闘(2D Fighting game)作るときのモーション遷移図作成の半自動化に挑戦しよう<その4> ref: http://qiita.com/muzudho1/items/baf4b06cdcda96ca9a11
TRANSITION ADD
FROM "Base Layer.SMove"
TO "Base Layer.SAtkLP"
TRANSITION ADD
FROM "Base Layer.SMove"
TO ATTR (BusyX Block)
(
[ ( Stand Punch ) ( Stand Kick ) ] { H } )
(
[
( Stand Punch ) ( Stand Kick ) ] { H } )
(
[
(
Stand Punch ) ( Stand Kick ) ] { H } )
(
[
(
Stand
Punch ) ( Stand Kick ) ] { H } )
(
[
(
Stand
Punch
) ( Stand Kick ) ] { H } )
# あっ、) だ! 戻ろう!
(
[
(
Stand
--> Punch
) ( Stand Kick ) ] { H } )
(
[
(
--> Stand
Punch
) ( Stand Kick ) ] { H } )
(
[
--> (
Stand
Punch
) ( Stand Kick ) ] { H } )
# あっ、) に対応する ( を見つけた! じゃあ Stand & Punch で検索しよう!
(
[
--> 1 ( Stand Kick ) ] { H } )
# 計算結果は、部室のロッカーの 1 番に入れておいた。計算を続ける。
(
[
1
( Stand Kick ) ] { H } )
( L Punch )
(
[
1
(
Stand Kick ) ] { H } )
(
[
1
(
Stand
Kick ) ] { H } )
(
[
1
(
Stand
Kick
) ] { H } )
# あっ、) だ! 戻ろう!
(
[
1
(
Stand
--> Kick
) ] { H } )
(
[
1
(
--> Stand
Kick
) ] { H } )
(
[
1
--> (
Stand
Kick
) ] { H } )
# あっ、) に対応する ( を見つけた! じゃあ Stand & Kick で検索しよう!
(
[
1
--> 2 ] { H } )
# 計算結果は、部室のロッカーの 2 番に入れておいた。計算を続ける。
(
[
1
2
] { H } )
# あっ、] だ! 戻ろう!
(
[
1
--> 2
] { H } )
(
[
--> 1
2
] { H } )
[ ( Stand Punch ) ( Stand Kick ) ]
(
--> [
1
2
] { H } )
# あっ、] に対応する [ を見つけた! じゃあ 部室のロッカーの 1 と 2 に入っている靴は
# いっしょに混ぜて 重複は trancate(捨てる)しよう。
# その結果は 部室のロッカーの 3 に入れる。
(
--> 3 { H } )
(
3
{
H
} )
# あっ、} だ! 戻ろう!
(
3
{
--> H
} )
(
3
--> {
H
} )
# あっ、} に対応する { を見つけた! じゃあ H & ……、1個だけか。1個で検索しよう!
# そして、その結果に当てはまらなかったものは 全部 部室のロッカーの 4 番に入れておこう。
# 計算を続ける。
(
3
4
)
# あっ、) だ! 戻ろう!
( [ ( Stand Punch ) ( Stand Kick ) ] { H } )
--> (
3
4
)
# あっ、) に対応する ( を見つけた! じゃあ 部室のロッカーの 3 と 4 に入っている靴は
# 全部のロッカーに重複している靴だけ残して、そうでない靴は trancate(捨てる)しよう。
# その結果は 部室のロッカーの 5 に入れる。
5
# (^▽^)あっ、計算が終わってるぜ。答えは 部室のロッカーの 5 番に入ってるからな。
TRANSITION INSERT
SET Duration 0 ExitTime 1
FROM “Base Layer.SMove”
TO ATTR (BusyX Block)
TRANSITION UPDATE
SET Duration 0.25 ExitTime 0.75
FROM “Base Layer.SMove”
TO ATTR (BusyX Block)
TRANSITION DELETE
FROM “Base Layer.SMove”
TO ATTR (BusyX Block)
TRANSITION SELECT
FROM “Base Layer.SMove”
TO ATTR (BusyX Block)
string expression = "( [ ( Alpha Cee ) ( Beta Dee ) ] { Eee } )";
List<int> result = Util_StellaQL.Execute(expression);
( [ ( Alpha Cee ) ( Beta Dee ) ] { Eee } )
[ ( Stand Punch ) ( Stand Kick ) { H } ]
List<int> result = Util_StellaQL.Execute(expression, typeof(AstateIndex));
public static List<int> Execute(string expression, Type enumration)
object enumElement = Enum.Parse(enumration, "Num"); // 変換できなかったら例外を投げる
Debug.Log("enumElement = " + enumElement.ToString() + " typeof = " + enumElement.GetType());
[Flags]
public enum Attr
{
Zero = 0, // (0) 最初の要素は 0 であることが必要。あとで計算に使う。
Alpha = 1, // (1)
Beta = 1 << 1, // (2)
Cee = 1 << 2, // (4)
Dee = 1 << 3, // (8)
Eee = 1 << 4, // (16)
}
/// <summary>
/// 補集合
/// </summary>
public static List<int> Complement(List<int> set, Type enumration)
{
List<int> complement = new List<int>();
{
// 列挙型の中身をリストに移動。
foreach (int elem in Enum.GetValues(enumration)) { complement.Add(elem); }
// 後ろから指定の要素を削除する。
for (int iComp = complement.Count - 1; -1 < iComp; iComp--)
{
if (set.Contains(complement[iComp]))
{
Debug.Log("Remove[" + iComp + "] ("+ complement[iComp]+")");
complement.RemoveAt(iComp);
}
else
{
Debug.Log("Tick[" + iComp + "] (" + complement[iComp] + ")");
}
}
}
return complement;
}
/// <summary>
/// ( ) 演算をテスト
/// </summary>
[Test]
public void OperationKeyword()
{
List<int> set = new List<int>() { (int)AstateDatabase.Attr.Beta, (int)AstateDatabase.Attr.Dee };
List<int> result = StellaQLScanner.Keyword_to_locker(set, typeof(AstateDatabase.Attr));
int i = 0;
foreach (int attr in result) { Debug.Log("Attr[" + i + "]: " + (AstateDatabase.Attr)attr + " (" + attr + ")"); i++; }
Assert.AreEqual(1, result.Count);
if (1 == result.Count)
{
Assert.AreEqual((int)AstateDatabase.Attr.Beta | (int)AstateDatabase.Attr.Dee, result[0]);
}
}
/// <summary>
/// [ ] 演算をテスト
/// </summary>
[Test]
public void OperationKeywordList()
{
List<int> set = new List<int>() { (int)AstateDatabase.Attr.Beta, (int)AstateDatabase.Attr.Dee };
List<int> result = StellaQLScanner.KeywordList_to_locker(set, typeof(AstateDatabase.Attr));
int i = 0;
foreach (int attr in result) { Debug.Log("Attr[" + i + "]: " + (AstateDatabase.Attr)attr + " (" + attr + ")"); i++; }
Assert.AreEqual(2, result.Count);
if (2 == result.Count)
{
Assert.AreEqual((int)AstateDatabase.Attr.Beta, result[0]);
Assert.AreEqual((int)AstateDatabase.Attr.Dee, result[1]);
}
}
/// <summary>
/// { } 演算をテスト
/// </summary>
[Test]
public void OperationNGKeywordList()
{
List<int> set = new List<int>() { (int)AstateDatabase.Attr.Beta, (int)AstateDatabase.Attr.Dee };
List<int> result = StellaQLScanner.NGKeywordList_to_locker(set, typeof(AstateDatabase.Attr));
int i = 0;
foreach (int attr in result) { Debug.Log("Attr[" + i + "]: " + (AstateDatabase.Attr)attr + " (" + attr + ")"); i++; }
Assert.AreEqual(4, result.Count);
if (4 == result.Count)
{
Assert.AreEqual((int)AstateDatabase.Attr.Zero, result[0]);
Assert.AreEqual((int)AstateDatabase.Attr.Alpha, result[1]);
Assert.AreEqual((int)AstateDatabase.Attr.Cee, result[2]);
Assert.AreEqual((int)AstateDatabase.Attr.Eee, result[3]);
}
}
public static List<int> Keyword_to_locker(List<int> set, Type enumration)
{ // 列挙型要素を OR 結合して持つ。
List<int> attrs = new List<int>();
int sum = (int)Enum.GetValues(enumration).GetValue(0);//最初の要素は 0 にしておくこと。 列挙型だが、int 型に変換。
foreach (object elem in set) { sum |= (int)elem; }// OR結合
attrs.Add(sum); // 列挙型の要素を結合したものを int型として入れておく。
return attrs;
}
public static List<int> KeywordList_to_locker(List<int> set, Type enumration)
{ // 列挙型要素を 1つ1つ ばらばらに持つ。
List<int> attrs = new List<int>();
foreach (int elem in set) { attrs.Add(elem); }// 列挙型の要素を1つ1つ入れていく。
return attrs;
}
public static List<int> NGKeywordList_to_locker(List<int> set, Type enumration)
{
return Complement(set, enumration); // 補集合を返すだけ☆
}
([(Alpaca Bear)(Cat Dog)]{Elephant})
# [ ( Stand Punch ) ( Stand Kick ) ] { H }
(
[
(
Alpaca
Bear
)
(
Cat
Dog
)
]
{
Elephant
}
)
0: () Bear Alpaca
1: () Dog Cat
2: [] 1 0
3: {} Elephant
4: () 3 2
([(Alpha Cee)(Beta)]{Eee})
List<List<string>> tokenLockers = new List<List<string>>(){ // 元は "([(Alpha Cee)(Beta)]{Eee})"
new List<string>() { "Cee", "Alpha", },
new List<string>() { "Beta", },
new List<string>() { "1","0",},
new List<string>() { "Eee", },
new List<string>() { "3","2",},
};
List<string> tokenLockersOperation = new List<string>() { "(", "(", "[", "{", "(", };
Alpaca
Cat
Rabbit
STATE SELECT
WHERE ATTR ([(Alpha Cee)(Beta)]{Eee})
Alpaca
Cat
Rabbit
TRANSITION SELECT
FROM "Base Layer.Zebra"
TO ATTR ([(Alpha Cee)(Beta)]{Eee})
# FROM
Zebra
# TO
Alpaca
Cat
Rabbit
# コメントA
STATE SELECT
# コメントB
WHERE ATTR ([(Alpha Cee)(Beta)]{Eee})
# コメントC
( [ ( Stand Punch ) ( Stand Kick ) ] { H } )
# No! ダメ
STATE SELECT # no comment. ここにコメントは書けない
WHERE ATTR ([(Alpha Cee)(Beta)]{Eee})
# No!
Set name1 -0.1 name2 -2 name3 --Ho! Ho!
1.5 name4 10
# No!
{alpaca/* bear*/ cat}
TRANSITION ADD
FROM "Base Layer.SMove"
TO ATTR ( [ ( Stand Punch ) ( Stand Kick ) ] { H } )
( [ ( Stand Punch ) ( Stand Kick ) ] { H } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment