本文整理汇总了C#中BaseObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# BaseObject.GetComponent方法的具体用法?C# BaseObject.GetComponent怎么用?C# BaseObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseObject
的用法示例。
在下文中一共展示了BaseObject.GetComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadContent
public override void LoadContent(ContentManager content)
{
_managerMap.LoadContent();
var player = new BaseObject {Id = "player"};
player.AddComponent(new Sprite(content.Load<Texture2D>("link_full"), 16, 16, new Vector2(50, 50)));
player.AddComponent(new PlayerInput(ManagerScreen,_managerPlayer));
player.AddComponent(new Animation(16, 16,2));
player.AddComponent(new Collision(_managerMap,_entities));
player.AddComponent(new Camera(_managerCamera));
player.AddComponent(new Equipment(content,_managerMap,_managerCamera,_entities));
player.GetComponent<Equipment>(ComponentType.Equipment).AddItem(new Boomerang());
player.GetComponent<Equipment>(ComponentType.Equipment).AddItem(new Sword(_entities));
player.GetComponent<Equipment>(ComponentType.Equipment).EquipItemInSlot(1,ItemSlot.A);
player.GetComponent<Equipment>(ComponentType.Equipment).EquipItemInSlot(2, ItemSlot.B);
player.AddComponent(new Damage(_entities,true));
player.AddComponent(FactoryStats.GetStats("Link"));
player.AddComponent(new GUI());
player.GetComponent<GUI>(ComponentType.GUI).LoadContent(content);
//var testNPC = new BaseObject();
//testNPC.AddComponent(new Sprite(content.Load<Texture2D>("Marin"), 16, 16, new Vector2(50, 50)));
//testNPC.AddComponent(new AIMovementRandom(200));
//testNPC.AddComponent(new Animation(16, 16));
//testNPC.AddComponent(new Collision(_managerMap));
//testNPC.AddComponent(new Camera(_managerCamera));
_entities.AddEntity(player);
//for (int n = 0; n < 3; n++)
//{
// var testEnemy = new BaseObject {Id = string.Format("enemy_{0}", n)};
// testEnemy.AddComponent(new Sprite(content.Load<Texture2D>("Octorok"), 16, 16, new Vector2(50 + ManagerFunction.Random(10,20), 50 + ManagerFunction.Random(10,20))));
// testEnemy.AddComponent(new AIMovementRandom(1000, 0.5f));
// testEnemy.AddComponent(new Animation(16, 16, 2));
// testEnemy.AddComponent(new Collision(_managerMap));
// testEnemy.AddComponent(new Octorok(player, content.Load<Texture2D>("Octorok_bullet"), _managerMap));
// testEnemy.AddComponent(new Camera(_managerCamera));
// testEnemy.AddComponent(new Damage(_entities));
// testEnemy.AddComponent(FactoryStats.GetStats("Octorok"));
// _entities.AddEntity(testEnemy);
//}
//_entities.AddEntity(testNPC);
//Script test!
//var testEnemy = new BaseObject { Id = string.Format("enemy_{0}", "script") };
//testEnemy.AddComponent(new Sprite(content.Load<Texture2D>("Octorok"), 16, 16, new Vector2(50 + ManagerFunction.Random(10, 20), 50 + ManagerFunction.Random(10, 20))));
//testEnemy.AddComponent(new AIMovementRandom(1000, 0.5f));
//testEnemy.AddComponent(new Animation(16, 16, 2));
//testEnemy.AddComponent(new Collision(_managerMap,_entities));
//testEnemy.AddComponent(new Octorok(player, content.Load<Texture2D>("Octorok_bullet"), _managerMap,_entities));
//testEnemy.AddComponent(new Camera(_managerCamera));
//testEnemy.AddComponent(new Damage(_entities));
//testEnemy.AddComponent(FactoryStats.GetStats("Octorok"));
//testEnemy.AddComponent(new Script("script_time_test"));
//_entities.AddEntity(testEnemy);
//Just for test
//var window = new WindowMessage("Hello, this is a message! This is a long message",content);
//ManagerWindow.NewWindow("test_message",window);
}
示例2: isReadyToRun
public bool isReadyToRun(BaseObject obj,bool reserve){
// the script is qualified to run, and all the actors it needs are available
if (obj == null) return true;
if (!isReadyFor (obj)) return false;
ObjectInteraction oi = obj.GetComponent<ObjectInteraction>();
if (reserve) oi.NeededFor(this);
if (oi != null && !oi.IsAvailableFor(this))
return false;
bool allAvailable = true;
if (actorObjects != null){
foreach (ObjectInteraction actor in actorObjects){
if (reserve) actor.NeededFor(this);
if (!actor.IsAvailableFor(this)) allAvailable = false;
}
}
return allAvailable;
}
示例3: RegisterObject
public void RegisterObject(BaseObject obj)
{
if (obj == null)
{
UnityEngine.Debug.Log("ObjectManager.RegisterObject() : obj is NULL");
return;
}
if (obj.Name == null)
{
UnityEngine.Debug.Log("ObjectManager.RegisterObject() : obj Name is NULL. using name "+obj.name);
obj.Name = obj.name;
// return;
}
// add to list
if (objects == null)
objects = new List<BaseObject>();
if (objects.Contains (obj)){
// UnityEngine.Debug.LogWarning("object tried to register twice "+obj.name);
return;
}
// don't register objects if their Scripted Object component says not to.
// this is fallout from having ALL base objects register.
if (obj.GetComponent<ScriptedObject>() != null &&
obj.GetComponent<ScriptedObject>().register == false)
return;
objects.Add(obj);
// add to dictionary
if (objectmap == null)
objectmap = new Dictionary<string, BaseObject>();
objectmap[obj.Name.ToLower()] = obj;
#if DEBUG_OBJECT
UnityEngine.Debug.Log("ObjectManager.RegisterObject(" + obj.Name+" "+obj.name + ")"+objectmap.Count);
#endif
Dispatcher.GetInstance().RegisterObject(obj);
}