public GetComponents ( |
||
type | ||
return | UnityEngine.Component[] |
void enablePlayer(GameObject player) { foreach (MonoBehaviour obj in player.GetComponents<MonoBehaviour>()) obj.enabled = true; foreach (CharacterController obj in player.GetComponents<CharacterController>()) obj.enabled = true; }
private ItemData CreateItemDataFromGameObject(GameObject gameObject) { ValidateGameObject (gameObject); ItemData itemData = new ItemData (); itemData.transformData.position = gameObject.transform.position; itemData.transformData.rotation = gameObject.transform.eulerAngles; itemData.transformData.scale = gameObject.transform.localScale; itemData.name = gameObject.name; foreach (IPersistable persistable in gameObject.GetComponents<IPersistable>()) { SerializableDictionary<string, object> componentConfiguration = new SerializableDictionary<string, object> (); foreach (FieldInfo field in persistable.GetType().GetFields()) { componentConfiguration.Add (field.Name, field.GetValue (persistable)); } string componentName = persistable.GetType ().FullName; itemData.componentData.configurations.Add (componentName, componentConfiguration); } foreach (Transform child in gameObject.transform) { if (child.GetComponents<IPersistable> ().Length > 0) { itemData.children.Add (CreateItemDataFromGameObject (child.gameObject)); } } return itemData; }
/// <summary> /// This adds a new target game object. /// </summary> /// <param name="gameObject"> /// The game object to target. /// </param> public void AddGameObject(GameObject gameObject) { //make sure this game object is not null and is not already in the list if (gameObject != null && targetGameObjects.Contains(gameObject) == false) { //warn if the game object being added is the parent of this component if (gameObject == this) { Debug.LogWarning("You are adding a game object to a modifier that is the parent of this modifier. This may have unexpected results."); } //add the game object targetGameObjects.Add(gameObject); //get all MonoBehavior components on this target game object MonoBehaviour[] behaviours = gameObject.GetComponents<MonoBehaviour>(); for (int j = 0; j < behaviours.Length; j++) { //make sure the found behavior is not this behavior, and it is a IVisModifierTarget if (behaviours[j] != this && behaviours[j] is IVisModifierTarget) { //get the modifier target and add to the ValueUpdate event IVisModifierTarget modifierTarget = behaviours[j] as IVisModifierTarget; if (modifierTarget != null) ValueUpdated += modifierTarget.OnValueUpdated; } } } }
public SIHJR_PVFS_Grid(GameObject _boundary, float influenceWidth) { Collider2D collider = _boundary.GetComponents<Collider2D> () [0]; _bounds = collider.bounds; _left = collider.bounds.min.x; _bottom = collider.bounds.min.y; _right = collider.bounds.max.x; _top = collider.bounds.max.y; _influenceWidth = influenceWidth; //create new grid _gridWidthCellCount = (int)Mathf.Ceil (collider.bounds.size.x / _influenceWidth); _gridHeightCellCount = (int)Mathf.Ceil (collider.bounds.size.y / _influenceWidth); //Debug.Log ("gridW: " + _gridWidthCellCount + " -- gridH: " + _gridHeightCellCount); //Debug.Log ("grid L: " + _left + " -- grid R: " + _right); //Debug.Log ("grid Cell Width: " + _influenceWidth); _gridArray = new IList[_gridWidthCellCount + 1, _gridHeightCellCount + 1]; /* _particles = new LinkedList<List<List<SIHJR_PVFS_Particle>>>(xCount); for (int i = 0; i < xCount; i++) { //create list _particles[i] = new LinkedList<List<SIHJR_PVFS_Particle>>(yCount); for (int j = 0; j < yCount; j++) { _particles[j] = new LinkedList<SIHJR_PVFS_Particle>(); } //create nested lists } */ }
public static string GetGameObjectBehaviors(GameObject gameObject) { if (gameObject == null) { return "GameObject is null"; } var components = gameObject.GetComponents<Component>(); string list = ""; foreach (var component in components) { string behaviorString = ""; UnityEngine.Behaviour behavior = component as UnityEngine.Behaviour; if (behavior != null) { behaviorString = " (Behavior)"; if (!behavior.enabled) { behaviorString += " (disabled)"; } } list += "Type: " + component.GetType() + behaviorString + "\n"; } return list; }
// NOTE: This method will not return components that are within a GameObjectContext public static IEnumerable<Component> GetInjectableComponentsBottomUp( GameObject gameObject, bool recursive) { var context = gameObject.GetComponent<GameObjectContext>(); if (context != null) { yield return context; yield break; } if (recursive) { foreach (Transform child in gameObject.transform) { foreach (var component in GetInjectableComponentsBottomUp(child.gameObject, recursive)) { yield return component; } } } foreach (var component in gameObject.GetComponents<Component>()) { yield return component; } }
private void ApplyRecursive(GameObject go) { foreach(Graphic graphic in go.GetComponents<Graphic>()) style.Apply(graphic); foreach(Selectable selectable in go.GetComponents<Selectable>()) style.Apply(selectable); foreach(Transform t in go.transform) { if(t.gameObject.GetComponent<pb_GUIStyleApplier>() != null) continue; ApplyRecursive(t.gameObject); } }
//Beware: This assumes that it's safe to just play sounds using free audio sources. // It's a replacement for NGUITools.PlaySound public static AudioSource PlaySoundOn(AudioClip clip, GameObject go, float volume = 1.0f) { if (clip == null || go == null) { return null; } AudioSource[] sources = go.GetComponents<AudioSource>(); AudioSource source = null; for (int i=0; i<sources.Length; ++i) { source = sources[i]; if (!source.isPlaying || source.clip == clip) { source.PlayClip(clip, volume); return source; } } source = go.AddComponent<AudioSource>(); source.playOnAwake = false; source.PlayClip(clip, volume); return source; }
void SetVisiible(GameObject obj, bool visible) { foreach (Renderer component in obj.GetComponents<Renderer>()) { component.enabled = visible; } }
private static XmlElement GameObjectToXmlElement(GameObject gameObject, XmlDocument document) { XmlElement entityElement = document.CreateElement("entity"); entityElement.SetAttribute("name",gameObject.name); Object[] outputComponents = gameObject.GetComponents(typeof(OutputComponent)); for (int j = 0; j < outputComponents.Length; j++) { OutputComponent oc = (OutputComponent)outputComponents[j]; XmlElement outputElement = oc.ToXmlElement(document); entityElement.AppendChild(outputElement); outputElement.SetAttribute("uid","" + oc.uid); } for (int i = 0; i < gameObject.transform.GetChildCount(); i++) { GameObject child = gameObject.transform.GetChild(i).gameObject; int childOutputComponents = child.GetComponents(typeof(OutputComponent)).Length; if (childOutputComponents > 0) { XmlElement childXmlElement = GameObjectToXmlElement(child, document); entityElement.AppendChild(childXmlElement); } } return entityElement; }
public static void InjectGameObject(DiContainer container, GameObject gameObj) { foreach (var monoBehaviour in gameObj.GetComponents<MonoBehaviour>()) { InjectMonoBehaviour(container, monoBehaviour); } }
private static void FindInGO(GameObject g) { go_count++; Component[] components = g.GetComponents<Component>(); for (int i = 0; i < components.Length; i++) { components_count++; if (components[i] == null) { missing_count++; string s = g.name; Transform t = g.transform; while (t.parent != null) { s = t.parent.name +"/"+s; t = t.parent; } Debug.Log (s + " has an empty script attached in position: " + i, g); } } // Now recurse through each child GO (if there are any): foreach (Transform childT in g.transform) { //Debug.Log("Searching " + childT.name + " " ); FindInGO(childT.gameObject); } }
// Use this for initialization void Start () { ConsoleLog.SLog ("PlayerGameManager Start()"); anim = GetComponent<Animator> (); cardboardCamera = GameObject.FindGameObjectWithTag("PlayerHead"); cardboardHead = cardboardCamera.GetComponent<CardboardHead> (); headPos = GameObject.FindGameObjectWithTag ("CameraPos").transform; gun = GameObject.FindGameObjectWithTag ("MyGun"); gunProperties = gun.GetComponent<GunProperties> (); gunAudio = gun.GetComponents<AudioSource> (); gunLight = GameObject.FindGameObjectWithTag ("GunLight"); gunFlashEmitter = GameObject.FindGameObjectWithTag ("GunFlash").GetComponent<EllipsoidParticleEmitter>(); gunFlashEmitter.emit = false; footstepsAudio = GetComponent<AudioSource> (); bulletHoleArray = new ArrayList (bulletHoleMaxAmount); //HUD HUD = GameObject.FindGameObjectWithTag("HUD"); healthBar = HUD.transform.GetChild (0) as Transform; bulletText = HUD.transform.GetChild (1).GetComponent<TextMesh>(); reloadText = HUD.transform.GetChild (2).GetComponent<TextMesh>(); grenadeText = HUD.transform.GetChild (3).GetComponent<TextMesh>(); HUDCanvas = HUD.transform.GetChild (4).gameObject; deadText = HUDCanvas.transform.GetChild (0).gameObject; endRoundText = HUDCanvas.transform.GetChild (1).gameObject; endGameText = HUDCanvas.transform.GetChild (2).gameObject; bulletText.text = gunProperties.bulletLoadCurrent + "/" + gunProperties.bulletStoreCurrent; grenadeText.text = grenadeStore + ""; }
public void Setup(GameObject targetType, int inputNumber) { if (playerShip != null) { Destroy(playerShip); playerShip = null; } playerShip = (GameObject)Instantiate(targetType, Vector3.zero, Quaternion.identity); var scripts = playerShip.GetComponents<MonoBehaviour>(); for (int i = 0; i < scripts.Length; i++) { MonoBehaviour data = scripts[i]; Controller controller = data as Controller; if (controller != null) { controller.horizontalAxis = "Horizontal"+inputNumber; controller.verticalAxis = "Vertical"+inputNumber; controller.accelerate = "Accelerate" + inputNumber; controller.otherAxis = "Other"+inputNumber; controller.AssignCamera(GetComponent<Camera>()); } } }
private void CacheMethodsForGameObject(GameObject go, System.Type parameterType) { List<string> cachedMethods = new List<string>(); cache[go].Add( parameterType, cachedMethods ); List<System.Type> addedTypes = new List<System.Type>(); MonoBehaviour[] behaviours = go.GetComponents<MonoBehaviour>(); foreach (MonoBehaviour beh in behaviours) { System.Type type = beh.GetType(); if (addedTypes.IndexOf(type) == -1) { System.Reflection.MethodInfo[] methods = type.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); foreach (System.Reflection.MethodInfo method in methods) { // Only add variables added by user, i.e. we don't want functions from the base UnityEngine baseclasses or lower string moduleName = method.DeclaringType.Assembly.ManifestModule.Name; if (!moduleName.Contains("UnityEngine") && !moduleName.Contains("mscorlib") && !method.ContainsGenericParameters && System.Array.IndexOf(ignoredMethodNames, method.Name) == -1) { System.Reflection.ParameterInfo[] paramInfo = method.GetParameters(); if (paramInfo.Length == 0) { cachedMethods.Add(method.Name); } else if (paramInfo.Length == 1 && paramInfo[0].ParameterType == parameterType) { cachedMethods.Add(method.Name); } } } } } }
/// <summary> /// Collects a list of usable routed events from the specified target game object. /// </summary> /// <param name="target">Game object to get all usable routes events of.</param> /// <returns>Usable routed events from the specified target game object.</returns> protected override List<Entry> GetApplicableMembers(GameObject target) { MonoBehaviour[] components = target.GetComponents<MonoBehaviour>(); List<Entry> list = new List<Entry>(); foreach (MonoBehaviour monoBehaviour in components) { if (monoBehaviour == null) { continue; } FieldInfo[] fields = monoBehaviour.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo info in fields) { if (info.FieldType != typeof(ViewEvent)) { continue; } Entry entry = new Entry { Target = monoBehaviour, MemberName = info.Name }; list.Add(entry); } } return list; }
public void SetAllCollidersStatus(bool active, GameObject box) { foreach (Collider2D c in box.GetComponents<Collider2D>()) { c.enabled = active; } }
// Use this for initialization void Start() { audio = GameObject.FindWithTag("Audio"); a = audio.GetComponents<AudioSource>(); m = GameObject.FindWithTag("Contador"); marcador = m.GetComponent<GUIText>(); }
public void GrabThis(int id) { Debug.Log("client grab this " + id.ToString()); if (id != 0) { if (RHClone != null) { networkView.RPC("DoppelgangerDestroyThis", RPCMode.AllBuffered, RHClone.networkView.viewID); //Network.Destroy(RHClone); } Jitika = GetComponent<GameInv>().gInv[id]; RHClone = Network.Instantiate(Jitika, RightHand.transform.position, RightHand.transform.rotation, 0) as GameObject; Debug.Log("Grabbing " + RHClone.name); RHClone.transform.parent = RightHand.transform; RHClone.transform.localPosition = Vector3.zero; Debug.Log("Grabbed at " + RightHand.transform.position); MonoBehaviour[] scriptComps = RHClone.GetComponents<MonoBehaviour>(); foreach (MonoBehaviour script in scriptComps) { script.enabled = true; } networkView.RPC("DoppelgangerGrabThis", RPCMode.AllBuffered, gameObject.networkView.viewID, RHClone.networkView.viewID); } else { if (RHClone != null) { networkView.RPC("DoppelgangerDestroyThis", RPCMode.AllBuffered, RHClone.networkView.viewID); //Network.Destroy(RHClone); } } }
/// <summary> /// Collect a list of usable delegates from the specified target game object. /// The delegates must be of type "void Delegate()". /// </summary> static List<Entry> GetMethods (GameObject target) { MonoBehaviour[] comps = target.GetComponents<MonoBehaviour>(); List<Entry> list = new List<Entry>(); for (int i = 0, imax = comps.Length; i < imax; ++i) { MonoBehaviour mb = comps[i]; if (mb == null) continue; MethodInfo[] methods = mb.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int b = 0; b < methods.Length; ++b) { MethodInfo mi = methods[b]; if (mi.GetParameters().Length == 0 && mi.ReturnType == typeof(void)) { if (mi.Name != "StopAllCoroutines" && mi.Name != "CancelInvoke") { Entry ent = new Entry(); ent.target = mb; ent.method = mi; list.Add(ent); } } } } return list; }
private string ShowComponents(SerializedObject objTarget, GameObject gameObject) { var targetComponentAssemblyName = objTarget.FindProperty("targetComponentAssemblyName"); var targetComponentFullname = objTarget.FindProperty("targetComponentFullname"); var targetComponentText = objTarget.FindProperty("targetComponentText"); var objComponents = gameObject.GetComponents<Component>(); var objTypesAssemblynames = (from objComp in objComponents select objComp.GetType().AssemblyQualifiedName).ToList(); var objTypesName = (from objComp in objComponents select objComp.GetType().Name).ToList(); int index = objTypesAssemblynames.IndexOf(targetComponentAssemblyName.stringValue); index = EditorGUILayout.Popup("Target Component", index, objTypesName.ToArray()); if (index != -1) { targetComponentAssemblyName.stringValue = objTypesAssemblynames[index]; targetComponentFullname.stringValue = objComponents.GetType().FullName; targetComponentText.stringValue = objTypesName[index]; } else { targetComponentAssemblyName.stringValue = null; } objTarget.ApplyModifiedProperties(); return targetComponentAssemblyName.stringValue; }
private string[] GetMethod(GameObject obj) { List<string> methodName = new List<string>(); Component[] allComponents = obj.GetComponents<Component>(); if (allComponents.Length>0){ foreach( Component comp in allComponents){ if (comp!=null){ if (comp.GetType().IsSubclassOf( typeof(MonoBehaviour))){ MethodInfo[] methodInfos = comp.GetType().GetMethods(); foreach( MethodInfo methodInfo in methodInfos){ if ((methodInfo.DeclaringType.Namespace == null) || (!methodInfo.DeclaringType.Namespace.Contains("Unity") && !methodInfo.DeclaringType.Namespace.Contains("System"))){ if (methodInfo.IsPublic){ methodName.Add( methodInfo.Name ); } } } } } } } // return methodName.ToArray(); }
public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect, Rect curRect) { bool foundCustomComponent = false; if (ignoreUnityMonobehaviour) { Component[] components = gameObject.GetComponents<MonoBehaviour>(); for (int i = components.Length - 1; i >= 0; i--) { if (components[i] != null && !components[i].GetType().FullName.Contains("UnityEngine")) { foundCustomComponent = true; break; } } } else { foundCustomComponent = gameObject.GetComponent<MonoBehaviour>() != null; } if (foundCustomComponent) { int ident = Mathf.FloorToInt(selectionRect.x / TREE_STEP_WIDTH) - 1; curRect.x = 1 + ident * TREE_STEP_WIDTH; curRect.y = selectionRect.y; curRect.width = TREE_STEP_WIDTH; curRect.height = selectionRect.height; GUI.DrawTexture(curRect, gameObject.transform.childCount > 0 ? monoBehaviourIconParentTexture : monoBehaviourIconTexture); } }
// Pause public void PauseParticle(GameObject PSGO) { ParticleSystem[] ParticleSys; ParticleSys = PSGO.GetComponents<ParticleSystem>(); foreach(ParticleSystem temp in ParticleSys) temp.Pause(); }
public static void FillMethodsList(List<string> methodsList, GameObject go) { methodsList.Clear(); MonoBehaviour[] components = go.GetComponents<MonoBehaviour>(); foreach (MonoBehaviour mb in components) { Type t = mb.GetType(); MethodInfo[] mis = t.GetMethods(); foreach (MethodInfo mi in mis) { if (mi.ReturnType == typeof(TaskStatus)) { ParameterInfo[] pis = mi.GetParameters(); if (pis.Length == 1) { if (pis[0].ParameterType == typeof(GameObject)) { string type = t.ToString(); string methodName = mi.Name; string newMethod = type + "." + methodName; methodsList.Add(newMethod); } } } } } }
void RecursiveCopy(GameObject src, GameObject dst) { Debug.Log("Copying from " + src.name + " to " + dst.name); Component[] src_components = src.GetComponents(typeof(Component)); foreach (Component comp in src_components) { if (comp is Transform || comp is Renderer || comp is Animation) continue; //Debug.Log("Adding " + comp.GetType().Name + " to " + dst.name); Component dst_comp = dst.AddComponent(comp.GetType()); SerializedObject src_ser_obj = new SerializedObject(comp); SerializedObject dst_ser_obj = new SerializedObject(dst_comp); src_ser_obj.Update(); dst_ser_obj.Update(); SerializedProperty ser_prop = src_ser_obj.GetIterator(); bool enterChildren = true; while (ser_prop.Next(enterChildren)) { enterChildren = true; string path = ser_prop.propertyPath; bool skip = false; foreach (string blacklisted_path in propertyBlacklist) { if (path.EndsWith(blacklisted_path)) { skip = true; break; } } if (skip) { enterChildren = false; continue; } //Debug.Log(path); SerializedProperty dst_ser_prop = dst_ser_obj.FindProperty(path); AssignSerializedProperty(ser_prop, dst_ser_prop); } dst_ser_obj.ApplyModifiedProperties(); } foreach (Transform child_transform in src.transform) { GameObject child = child_transform.gameObject; string dst_object_name = namePrefix + child.name; GameObject dst_object = findChildWithName(dst, dst_object_name); if (dst_object == null) { Debug.LogWarning("Didn't find matching GameObject for " + child.name); continue; } RecursiveCopy(child, dst_object); } }
void SetCollidable( GameObject obj, bool collidable ) { foreach( Collider component in obj.GetComponents<Collider>() ) component.enabled = collidable; foreach( Collider child in obj.GetComponentsInChildren<Collider>() ) child.enabled = collidable; }
public void PlayClip( AudioClip clip) { SoundManager = GameObject.Find ("SoundManager"); Audio = SoundManager.GetComponents<AudioSource> (); SFX = Audio [1]; SFX.clip = clip; SFX.Play (); }
// Disables all scripts in the child objects void disableAll(GameObject cam) { // Disable the object cam.SetActive(false); foreach (Behaviour comp in cam.GetComponents<Behaviour>()) { comp.enabled = false; } }
/// <summary> /// Check if a component as a missing script /// </summary> /// <param name="obj">Object to check</param> /// <returns>True if there is at least one missing component</returns> private bool CheckForMissingScripts(GameObject obj) { if (obj == null) return false; Component[] components = obj.GetComponents<Component>(); return components != null ? components.Any(c => c == null) : false; }