如何在Boo中使用UnityScript中的变量?(How to use variables from UnityScript in Boo?)
我一直试图实现这一点,但没有任何成功。 当我在谷歌上搜索时,我发现这在某种程度上是可能的,但显然我无法达到它。 这是我的文件树:
|-Game |--Assets |---Animacije |---Skripte |----*BlokSistem.js |---Standard Assets |----*UI.boo |---Prefabs |---Sprites |---Game.unity
我想在UI.boo中使用BlokSistem.js中的变量,但没有任何成功。 我想换一个并打印另一个。 这是我现在的代码(UI.boo):
import UnityEngine import System.Collections public class UI(MonoBehaviour): blokSistem as BlokSistem = GetComponent[of BlokSistem]() #this is line 7 which produces error def OnGUI() as void: GUI.Box(Rect(0,0,200,50), "Blocks") if GUI.Button(Rect(0,60,200,25), "Dirt = "+blokSistem.dirtAmount): blokSistem.selectedBlock = blokSistem.dirtBlock elif GUI.Button(Rect(0,60,200,25), "Grass = "+blokSistem.grassAmount): blokSistem.selectedBlock = blokSistem.grassBlock
我在第7行得到此错误(在上面的代码中注释):
The name 'BlokSistem' does not denote a valid type ('not found').
这是我在BlokSistem.js中声明我的变量的方式:
public var dirtAmount : int; public var grassAmount : int; public var selectedBlock : GameObject;
在此先感谢您的帮助。
I've been trying to implement this but without any success. While I was googling around I saw that this is somehow possible but I can't reach it by myself obviously. This my file tree:
|-Game |--Assets |---Animacije |---Skripte |----*BlokSistem.js |---Standard Assets |----*UI.boo |---Prefabs |---Sprites |---Game.unity
I want to use variable from BlokSistem.js in UI.boo, but without any success. I want to change one and print another. Here is my code for now (UI.boo):
import UnityEngine import System.Collections public class UI(MonoBehaviour): blokSistem as BlokSistem = GetComponent[of BlokSistem]() #this is line 7 which produces error def OnGUI() as void: GUI.Box(Rect(0,0,200,50), "Blocks") if GUI.Button(Rect(0,60,200,25), "Dirt = "+blokSistem.dirtAmount): blokSistem.selectedBlock = blokSistem.dirtBlock elif GUI.Button(Rect(0,60,200,25), "Grass = "+blokSistem.grassAmount): blokSistem.selectedBlock = blokSistem.grassBlock
I get this error on line 7 (commented it in code above):
The name 'BlokSistem' does not denote a valid type ('not found').
This is how I declared my variables in BlokSistem.js:
public var dirtAmount : int; public var grassAmount : int; public var selectedBlock : GameObject;
Thanks in advance for help.
原文:https://stackoverflow.com/questions/28274895
最满意答案
是否与下面的查询相同?
是
如果我想使用OR(||)运算符获取数据,该怎么办?
它的资源成本远低于此:
IQueryable<Ad> list1 = db.Ads.Where(x=>x.isModerated); IQueryable<Ad> list2; if(something == true) { list2 = list1.Where(x=>x.TypeId == 2) } else { list2 = db.Ads.Where(x=>x.isModerated || x.TypeId == 2) }
但如果由于某种原因你不想这样做,你可以这样做:
list2 = list1.Union(db.Ads.Where(x=> x.TypeId == 2))
会给你相同的结果集
is it going to be the same as query below?
Yes
and what if I would like to get a data using OR (||) operator is the same scenario.
Its going to be far less resource expensive to do it like:
IQueryable<Ad> list1 = db.Ads.Where(x=>x.isModerated); IQueryable<Ad> list2; if(something == true) { list2 = list1.Where(x=>x.TypeId == 2) } else { list2 = db.Ads.Where(x=>x.isModerated || x.TypeId == 2) }
But if for some reason you do not want to do it that way you could do it:
list2 = list1.Union(db.Ads.Where(x=> x.TypeId == 2))
will give you the same result set
相关问答
更多-
C#到F# - EF代码优先(C# to F# - EF Code First)[2022-03-21]
更改 let mutable cars = List() :> ICollection 至 let mutable cars = Unchecked.defaultof > 和 let mutable dealer = Dealer() 至 let mutable dealer = Unchecked.defaultof Change let mutable cars = List () :> ICollection< ... -
您可以像这样访问通用的Set方法: var entities = (from e in myContext.Set
()); 更新:您需要向方法添加泛型类型约束,以确保泛型类型T将匹配已应用于方法DbContext.Set 的约束。 更新2:您不需要投射您的实体; 它已经是typeof(T) 。 public T GetEntity (Guid entityId, string connectionString) where T : class { using (RContex ... -
是否与下面的查询相同? 是 如果我想使用OR(||)运算符获取数据,该怎么办? 它的资源成本远低于此: IQueryable
list1 = db.Ads.Where(x=>x.isModerated); IQueryable list2; if(something == true) { list2 = list1.Where(x=>x.TypeId == 2) } else { list2 = db.Ads.Where(x=>x.isModerated || x.T ... -
是。 千条条款可以影响绩效。 如果可以,我建议使用值创建一个临时表,并使用逻辑连接。 您应该在临时表上创建索引。 注意:您可以在主表上使用技巧,方法是添加一个将列值连接在一起的计算列。 然后用于: alter table t add ab as (a + ':' + b); create index idx_t_ab on t(ab); 然后将查询修改为: where ab in ('1:2', . . . ) 这对所有应用程序都不适用,但它可能适合您的性能需求。 Yes. A thousand wh ...
-
使用Max和过滤器进行EF6查询(EF6 query with Max and filters)[2022-05-16]
你把Where放在第一位然后Max就像这样 int max = DbContext.myTable.Where(it=>it.columnB>5 && it.ColumnC=1).Max(t => t.ColumnA); You put Where first and then Max later like this int max = DbContext.myTable.Where(it=>it.columnB>5 && it.ColumnC=1).Max(t => t.ColumnA); -
对我来说,它看起来像userName , roles和applications是查询的参数,即数据来自您的应用程序而不是来自数据库。 在这种情况下,我会写这样的查询: IQueryable
query = cnt.Users; if(userName != null) query = query.Where(x => x.name == userName) if(roles.Any()) query = query.Where(x => roles.Contains(x.role ... -
您可以使用Sql方法在Migration中创建视图: public partial class Migration : DbMigration { public override void Up() { this.Sql("CREATE VIEW dbo.MyView AS (etc)"); } public override void Down() { this.Sql("DROP VIEW dbo.MyView"); } ...
-
在查询期间,您无法比较RavenDB中的两个值。 您无法做到这一点的原因是,这需要数据库引擎扫描所有文档以查找匹配项。 相反,创建一个索引,在索引时进行比较,并查询结果。 You cannot compare two values in RavenDB during query. The reason you cannot do that is that this requires the database engine to scan through all the documents to find m ...
-
使用SelectMany而不是Select project.ProjectDoc .SelectMany(c => c.Comment.Select(i => i.UserID)) .Distinct() .Count() Use SelectMany instead of Select project.ProjectDoc .SelectMany(c => c.Comment.Select(i => i.UserID)) . ...
-
Linq和EF on .Any()(Linq and EF on .Any())[2023-03-22]
Any()根本不返回值 - 它返回一个布尔值,表示集合中是否有值。 它只显示两个值,因为您只查询CmsContents,它有两行,并且两行至少有一个类别,所以两行都在结果中。 看起来你真的喜欢: var contents = from cnt in context.CmsContents from category in cnt.CmsCategories select cnt; Any() doesn't return values at al ...