Linq 自分メモ
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;//これが必要
public class createItemObect_Manager : MonoBehaviour {
public ItemDatabase itemdb;
public GameObject originalItemObject;
private List<Item> AllItemList = new List<Item>();
// Use this for initialization
void Start () {
foreach (Item i in itemdb.itemDB){//
AllItemList.Add(i);
//GameObject copyObj = Instantiate(originalItemObject) as GameObject;
//copyObj.GetComponent<ItemObject>().item = i;
}
var itemList = AllItemList.Where(n => n.itemType ==Item.ItemType.Potion).ToList();
var weaponlist = AllItemList.Where(n => n.itemType ==Item.ItemType.Weapon).Select(n => n.itemAttack*2).ToList();
foreach(var n in weaponlist){
Debug.Log("attack:"+n);
}
}
}
unity fungus シーンの移動
サブルーチンのような使い方
1:呼び出し元にFlow-->Callを追加
2:呼び出すブロックを指定する。(必要に応じてflowchartやlabelを設定する)
3:Callmodeに wait until finishedを指定する。
呼び出しブロックにStopBlockを設定しとくと、そこでそのブロック処理が止まり呼び出し元に戻る。
同様にcallmodeでcontinueを使うと変数計算等のマクロのような使い方ができそう?(要検証)
callmodeにstopだとそのまま終了するようだ。(Jumpとの違いがわからん)
//--fungusにload等のcommandがあったので不要。
using UnityEngine;
using System.Collections;
using Fungus;
using UnityEngine.SceneManagement;
using UnityEditor;
[CommandInfo("Command","reload scene","reload scene")]
public class LoadScene_funguscommand : Command {
// Use this for initialization
public override void OnEnter(){
// do
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
// Continue();
}
}
[CommandInfo("Command","load nextScene","next scene")]
public class nextScene_funguscommand : Command {
// Use this for initialization
public override void OnEnter(){
// do
SceneManager.LoadScene((SceneManager.GetActiveScene().buildIndex+1), LoadSceneMode.Single);
Continue();
}
}
[CommandInfo("Command","goto scenename","goto scene")]
public class gotoScene_funguscommand : Command {
public string sceneName;
// Use this for initialization
public override void OnEnter(){
// do
SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
//SceneManager.LoadScene(sceneName);
// Continue();
}
}
//--------
unity C# 継承とgetcomponentを調べた
unity を勉強中な素人なので記事に保証はありません。
unityでC#を勉強した覚書きを書こうかと思います。
monobehaviourを継承したオブジェクトはnewではなくgetcomponentを使用するようにメッセージがでたのでgetcomponentをテストした。
-------------------------using 省略
testA.C# monobehaviourを継承している
public class testA : MonoBehaviour {
public void attack()
{
Debug.Log("attack A");
}
}
Aを継承したBを作る
testB.C#
public class testB : testA {
public void attack()
{
Debug.Log("attackB");
}
}
●空のgameObjectのTestBを作成しtestBスクリプトをくっつける
testC.C#
public GameObject objB;
void Start () {
testB testb = objB.GetComponent<testB>();
testb.attack();
testA testab = objB.GetComponent<testB>();
testab.attack();
testA testaa = objB.GetComponent<testA>();
testaa.attack();
}
}
●空のgameObjectのTestCを作成してtestCスクリプトをくっつける。
objBにTestBおぶじぇくとを指定する。
実行結果
attackB
attackA
attackA
ちなみにtestB testba = objB.GetComponent<testA>();
testba.attack(); 型の問題でエラーになる
testB testb = objB.GetComponent<testA>() as testB;とすると通るが意味がない
------------------------
全ての結果をattackBと表示させるには?overrideとvartualを使う
testAを書き直す
public virtual void attack()
{
Debug.Log("attack A");
}
testBを書き直す
public override void attack()
{
Debug.Log("attackB");
}
結果は全てattackBと表示する。