本文整理汇总了C#中GameObject.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponents方法的具体用法?C# GameObject.GetComponents怎么用?C# GameObject.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponents方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessage
public static void SendMessage(this GameObject sender, GameMessage msg, GameObject target)
{
if (msg == null)
{
Log.Game.WriteWarning("ExtMethodsGameObject: Tried to send a null message.\n{0}", Environment.StackTrace);
return;
}
// if there is already a list on the stack then we have re-entered SendMessage i.e. a HandleMessage method has
// called SendMessage
if (_receiverStack.Count > 0)
_currentReceivers = new List<ICmpHandlesMessages>();
_receiverStack.Push(_currentReceivers);
_currentReceivers.Clear();
if (target != null)
{
if (!target.Active)
{
_currentReceivers = _receiverStack.Pop();
return;
}
target.GetComponents(_currentReceivers);
}
else
{
Scene.Current.FindComponents(_currentReceivers);
}
try
{
for (int i = _currentReceivers.Count - 1; i >= 0; i--)
{
var receiver = _currentReceivers[i];
if (receiver == null || ((Component)receiver).Disposed || ((Component)receiver).Active == false)
continue;
receiver.HandleMessage(sender, msg);
if (i > _currentReceivers.Count)
i = _currentReceivers.Count;
if (msg.Handled)
break;
}
}
finally
{
_receiverStack.Pop();
if (_receiverStack.Count > 0)
_currentReceivers = _receiverStack.Peek();
else
_currentReceivers = _receivers;
}
}
示例2: WeCanFindAllComponentsByItsSubType
public void WeCanFindAllComponentsByItsSubType()
{
GameObject go = new GameObject();
go.AddComponent(typeof(TestComponent));
UnityObject[] uo = go.GetComponents(typeof(Component));
Assert.That(uo, Is.Not.Null);
Assert.That(uo.Length, Is.EqualTo(2));
}
示例3: AddObject
public void AddObject(GameObject gameObject)
{
if (gameObject == null) throw new ArgumentNullException("gameObject");
_addNewObjectsQueue.Enqueue(gameObject);
gameObject.GameObjectManager = this;
var components = gameObject.GetComponents<ColliderComponent>();
foreach (var item in components)
{
QuadTree.Insert(item as ColliderComponent);
}
}
示例4: TheIdMapWillContainAMapOfAllComponents
public void TheIdMapWillContainAMapOfAllComponents()
{
Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>();
GameObject go = new GameObject();
go.AddComponent(typeof(TestComponent));
go.AddComponent(typeof(TestComponent));
go.SetNewId(ids);
Assert.That(ids.Count, Is.EqualTo(4));
foreach (var item in go.GetComponents(typeof(Component)))
{
Assert.That(ids.ContainsValue(item), Is.True);
}
}
示例5: process
public override ExtendedEventArgs process()
{
Debug.Log ("response process--");
g = GameObject.Find("Player_sprite_2(Clone)");
p2 = g.GetComponents<PlayerController2> ();
p2[0].keytype = keytype;
p2 [0].key = key;
ResponseKeyboardEventArgs args = new ResponseKeyboardEventArgs ();
args.keytype = keytype;
args.key = key;
return args;
}
示例6: UpdateComponentEditors
protected void UpdateComponentEditors(GameObject[] values)
{
this.BeginUpdate();
if (!this.Children.Any())
{
this.gameObjEditor.Getter = this.GetValue;
this.gameObjEditor.Setter = this.SetValue;
this.AddPropertyEditor(this.gameObjEditor);
}
Type[] typesInUse = values.GetComponents<Component>().Select(c => c.GetType()).Distinct().ToArray();
// Remove Component editors that aren't needed anymore
var cmpEditorCopy = new Dictionary<Type,PropertyEditor>(this.componentEditors);
foreach (var pair in cmpEditorCopy)
{
if (!typesInUse.Contains(pair.Key))
{
this.RemovePropertyEditor(pair.Value);
this.componentEditors.Remove(pair.Key);
}
}
// Create the ones that are needed now and not added yet
foreach (Type t in typesInUse)
{
if (!this.componentEditors.ContainsKey(t))
{
PropertyEditor e = this.ParentGrid.CreateEditor(t, this);
e.Getter = this.CreateComponentValueGetter(t);
e.Setter = this.CreateComponentValueSetter(t);
e.PropertyName = t.GetTypeCSCodeName(true);
this.ParentGrid.ConfigureEditor(e);
this.AddPropertyEditor(e);
this.componentEditors[t] = e;
}
}
this.EndUpdate();
}
示例7: SetVis
// disable rendering of gameobjects the host should not see. He does not use network bandwidth anyway, so just non rendering is needed
private static void SetVis(GameObject go, bool vis)
{
Renderer[] components = go.GetComponents<Renderer>();
for (int i = 0; i < components.Length; i++)
{
Renderer renderer = components[i];
renderer.set_enabled(vis);
}
for (int j = 0; j < go.get_transform().get_childCount(); j++)
{
Transform child = go.get_transform().GetChild(j);
NetworkProximityChecker.SetVis(child.get_gameObject(), vis);
}
}
示例8: ScanGameObject
protected GameObjectNode ScanGameObject(GameObject obj, bool scanChildren)
{
if (obj == null) return null;
GameObjectNode thisNode = new GameObjectNode(obj, !this.buttonShowComponents.Checked);
foreach (Component c in obj.GetComponents<Component>())
{
ComponentNode compNode = this.ScanComponent(c);
if (compNode != null) this.InsertNodeSorted(compNode, thisNode);
}
if (scanChildren)
{
foreach (GameObject c in obj.Children)
{
GameObjectNode childNode = this.ScanGameObject(c, scanChildren);
if (childNode != null) this.InsertNodeSorted(childNode, thisNode);
}
}
return thisNode;
}
示例9: PackGameObject
public SceneObject PackGameObject(GameObject go)
{
ObjectIdentifier objectIdentifier = go.GetComponent<ObjectIdentifier>();
//Now, we create a new instance of SceneObject, which will hold all the GO's data, including it's components.
SceneObject sceneObject = new SceneObject();
sceneObject.name = go.name;
sceneObject.prefabName = objectIdentifier.prefabName;
sceneObject.id = objectIdentifier.id;
if (go.transform.parent != null && go.transform.parent.GetComponent<ObjectIdentifier>() == true)
{
sceneObject.idParent = go.transform.parent.GetComponent<ObjectIdentifier>().id;
}
else
{
sceneObject.idParent = null;
}
//in this case, we will only store MonoBehavior scripts that are on the GO. The Transform is stored as part of the ScenObject isntance (assigned further down below).
//If you wish to store other component types, you have to find you own ways to do it if the "easy" way that is used for storing components doesn't work for them.
List<string> componentTypesToAdd = new List<string>() {
"UnityEngine.MonoBehaviour"
};
//This list will hold only the components that are actually stored (MonoBehavior scripts, in this case)
List<object> components_filtered = new List<object>();
//Collect all the components that are attached to the GO.
//This includes MonoBehavior scripts, Renderers, Transform, Animator...
//If it
object[] components_raw = go.GetComponents<Component>() as object[];
foreach (object component_raw in components_raw)
{
if (componentTypesToAdd.Contains(component_raw.GetType().BaseType.FullName))
{
components_filtered.Add(component_raw);
}
}
foreach (object component_filtered in components_filtered)
{
sceneObject.objectComponents.Add(PackComponent(component_filtered));
}
//Assign all the GameObject's misc. values
sceneObject.position = go.transform.position;
sceneObject.localScale = go.transform.localScale;
sceneObject.rotation = go.transform.rotation;
sceneObject.active = go.activeSelf;
return sceneObject;
}
示例10: GetComponents
public static Component[] GetComponents(GameObject obj, System.Type t)
{
Component[] comp = null;
if (obj != null && t!=null) comp = obj.GetComponents(t);
return comp;
}
示例11: process
public override ExtendedEventArgs process()
{
Debug.Log ("loationResponse");
ResponseRRPositionEventArgs args = new ResponseRRPositionEventArgs ();
g = GameObject.Find ("GameLogic");
p2 = g.GetComponents<Running> ();
//<<<<<<< HEAD
Debug.Log ("x = "+ x + "\ny = " + y );
// p2[0].player2.transform.position = new Vector3((float)x,(float)y,0f);
//=======
//Debug.Log ("response: x = "+ x + "\ny = " + y );
p2[0].player2.transform.position = new Vector3(x,y,0f);
//>>>>>>> Dong
args.x = x;
args.y = y;
return args;
}
示例12: SetVis
private static void SetVis(GameObject go, bool vis)
{
foreach (Renderer component in go.GetComponents<Renderer>())
component.enabled = vis;
for (int index = 0; index < go.transform.childCount; ++index)
NetworkProximityChecker.SetVis(go.transform.GetChild(index).gameObject, vis);
}