/// <summary> /// This is will use the normal GetComponents but will also check for Linkers /// </summary> /// <typeparam name="T">Type to find</typeparam> /// <param name="GO">Object to look on</param> /// <returns>The first found Component, or null if none exist</returns> public static T[] GetComponentsInParentAdvanced <T>(this GameObject GO) where T : class { var list = new List <T>(GO.GetComponentsInParent <T>()); list.AddRange(GO.GetComponentsInParent <ComponentLinker <T> >().Select(t => t.Link)); return(list.ToArray()); }
public static IEnumerable <BindableMember <PropertyInfo> > GetViewModelProperties(GameObject rGo, Type rViewPropType, Type rViewModelType, bool bIsList) { IEnumerable <BindableMember <PropertyInfo> > rBindableMembers = null; if (bIsList) { rBindableMembers = rGo.GetComponentsInParent <ViewModelDataSourceTemplate>(true) .Where(ds => ds != null && !string.IsNullOrEmpty(ds.ViewModelPath) && !string.IsNullOrEmpty(ds.TemplatePath)) .SelectMany(ds => { var rType = TypeResolveManager.Instance.GetType(ds.TemplatePath); return(rType? .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Select(prop => new BindableMember <PropertyInfo>(ds, prop, rType))); }) .Where(prop => prop != null && prop.Member.PropertyType.Equals(rViewPropType) && ((prop.Member.GetSetMethod(false) != null && prop.Member.GetGetMethod(false) != null && prop.Member.GetCustomAttributes(typeof(DataBindingAttribute), true).Any() ) || (prop.Member.GetGetMethod(false) != null && prop.Member.GetCustomAttributes(typeof(DataBindingRelatedAttribute), true).Any() ) ) ); } else { rBindableMembers = rGo.GetComponentsInParent <ViewModelDataSource>(true) .Where(ds => ds != null && !string.IsNullOrEmpty(ds.ViewModelPath)) .SelectMany(ds => { var rType = TypeResolveManager.Instance.GetType(ds.ViewModelPath); return(rType? .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Select(prop => new BindableMember <PropertyInfo>(ds, prop, rType))); }) .Where(prop => prop != null && prop.Member.PropertyType.Equals(rViewPropType) && ((prop.Member.GetSetMethod(false) != null && prop.Member.GetGetMethod(false) != null && prop.Member.GetCustomAttributes(typeof(DataBindingAttribute), true).Any() ) || (prop.Member.GetGetMethod(false) != null && prop.Member.GetCustomAttributes(typeof(DataBindingRelatedAttribute), true).Any() ) ) ); } return(rBindableMembers); }
/// <summary> /// Returns an enum detailing if the given <see cref="GameObject"/> will be converted and how. /// </summary> /// <param name="gameObject">The <see cref="GameObject"/> to be converted.</param> /// <returns>A <see cref="GameObjectConversionResultStatus"/> code detailing how the <see cref="GameObject"/> will be converted.</returns> public static GameObjectConversionResultStatus GetGameObjectConversionResultStatus(GameObject gameObject) { if (null == gameObject || !gameObject) { return(GameObjectConversionResultStatus.NotConverted); } if (gameObject.scene.isSubScene) { // Any gameObject in a sub-scene will ignore special conversion components and always result in a converted entity. return(GameObjectConversionResultStatus.ConvertedBySubScene); } s_StopConvertToEntity.Clear(); gameObject.GetComponentsInParent(true, s_StopConvertToEntity); if (s_StopConvertToEntity.Count > 0) { // This gameObject or an ancestor has the StopConvertToEntity component. // This means all of its children (including itself) are not converted. return(GameObjectConversionResultStatus.NotConvertedByStopConvertToEntityComponent); } s_ConvertToEntity.Clear(); gameObject.GetComponentsInParent(true, s_ConvertToEntity); foreach (var convertToEntity in s_ConvertToEntity) { if (convertToEntity.gameObject != gameObject && convertToEntity.ConversionMode == ConvertToEntity.Mode.ConvertAndInjectGameObject) { // An ancestor is being converted and injected. // This means all of its children are not converted. return(GameObjectConversionResultStatus.NotConvertedByConvertAndInjectMode); } } foreach (var convertToEntity in s_ConvertToEntity) { if (convertToEntity.gameObject != gameObject && convertToEntity.ConversionMode == ConvertToEntity.Mode.ConvertAndDestroy) { // An ancestor is being converted and destroyed. // This means all of its children are converted. return(GameObjectConversionResultStatus.ConvertedByAncestor); } } var convertToEntityOnCurrentGO = gameObject.GetComponent <ConvertToEntity>(); return((convertToEntityOnCurrentGO && convertToEntityOnCurrentGO.enabled) ? GameObjectConversionResultStatus.ConvertedByConvertToEntity : GameObjectConversionResultStatus.NotConverted); }
public static bool IsChildObject(GameObject p_possibleParent, GameObject p_child, bool p_includeSelf = false) { bool v_isChild = false; if (p_child != null && p_possibleParent != null) { if (p_includeSelf && p_possibleParent == p_child) { v_isChild = true; } if (!v_isChild) { MaterialFocusGroup[] v_focusContainares = p_child.GetComponentsInParent <MaterialFocusGroup>(); foreach (MaterialFocusGroup v_cont in v_focusContainares) { if (v_cont != null && v_cont.gameObject == p_possibleParent) { v_isChild = true; break; } } } } return(v_isChild); }
private static int GetComponentsInParent(IntPtr L) { int result; try { int num = LuaDLL.lua_gettop(L); if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(GameObject), typeof(Type))) { GameObject gameObject = (GameObject)ToLua.ToObject(L, 1); Type type = (Type)ToLua.ToObject(L, 2); Component[] componentsInParent = gameObject.GetComponentsInParent(type); ToLua.Push(L, componentsInParent); result = 1; } else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(GameObject), typeof(Type), typeof(bool))) { GameObject gameObject2 = (GameObject)ToLua.ToObject(L, 1); Type type2 = (Type)ToLua.ToObject(L, 2); bool includeInactive = LuaDLL.lua_toboolean(L, 3); Component[] componentsInParent2 = gameObject2.GetComponentsInParent(type2, includeInactive); ToLua.Push(L, componentsInParent2); result = 1; } else { result = LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.GameObject.GetComponentsInParent"); } } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
static int GetComponentsInParent(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { GameObject obj = (GameObject)L.ChkUnityObjectSelf(1, "GameObject"); Type arg0 = L.ChkTypeObject(2); Component[] o = obj.GetComponentsInParent(arg0); L.PushUData(o); return(1); } else if (count == 3) { GameObject obj = (GameObject)L.ChkUnityObjectSelf(1, "GameObject"); Type arg0 = L.ChkTypeObject(2); var arg1 = L.ChkBoolean(3); Component[] o = obj.GetComponentsInParent(arg0, arg1); L.PushUData(o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponentsInParent"); } return(0); }
public static int GetStencilID(GameObject obj) { int count = 0; m_maskComponents = obj.GetComponentsInParent <Mask>(); for (int i = 0; i < m_maskComponents.Length; i++) { if (m_maskComponents[i].MaskEnabled()) { count += 1; } } switch (count) { case 0: return(0); case 1: return(1); case 2: return(3); case 3: return(11); } return(0); }
void AddHorse(GameObject horse) { Horses dad = horse.GetComponentsInParent <Horses>()[0]; // Build the respawn position based off of the first // SubHorse to collide with us if (horsesSaved == 0) { respawnPos = new Vector2( RespawnX.position.x, horse.transform.position.y ); } // Remove horse that hit us dad.GetComponent <ChildrenList>().RemoveFromList(horse.GetComponent <SubHorse>()); GameObject.Destroy(horse); // Spawn new horses once we get enough horses if (dad.controlledSubUnits.Count == 0) { // Horse controller should be in limbo dad.inLimbo = true; StartCoroutine(SpawnHorseAfter()); } horsesSaved++; }
void CheckAndHandleAttack(GameObject source) { if (invincibleTime > 0f) { return; } List <Attack> attacks = new List <Attack>(); foreach (Attack atk in source.GetComponents <Attack>()) { attacks.Add(atk); } foreach (Attack atk in source.GetComponentsInParent <Attack>()) { attacks.Add(atk); } if (attacks.Count == 0) { return; } var attack = attacks[0]; if (attack != null && attack.isAttacking && source.tag == "Dangerous") { ReceiveDamage(attack.attackDamage, attack.attackType); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Multi-editing isnt supportedd if (property.serializedObject.isEditingMultipleObjects) { return; } ParentComponentAttribute attrib = (ParentComponentAttribute)this.attribute; // Type check var self = property.serializedObject.targetObject; GameObject go = null; var value = property.objectReferenceValue; if (!(self is Component)) { var goProp = attrib.gameObjectOverrideField; if (string.IsNullOrEmpty(goProp)) { Debug.LogError("Parent component attribute used on an object that doesnt drive from Component and hasnt specified"); return; } else { go = property.serializedObject.FindProperty(goProp).objectReferenceValue as GameObject; } } else { go = (self as Component).gameObject; } if (Essentials.UnityIsNull(go)) { Debug.LogError("Cannot retrieve a gameobject for the property " + property); return; } // Gather info var valueComponent = value as Component; var availableComponents = go.GetComponentsInParent(attrib.targetType, true).Concat(go.GetComponents(attrib.targetType)).Distinct().Where((c) => !object.ReferenceEquals(self, c)).ToArray(); var availableComponentsStr = new string[] { "NULL", }.Concat(availableComponents.Select((c) => c.ToString())).ToArray(); var currentlySelected = property.objectReferenceValue; int currentlySelectedIndex = System.Array.IndexOf(availableComponents, valueComponent) + 1; int newIndex = EditorGUI.Popup(position, property.name, currentlySelectedIndex, availableComponentsStr); if (newIndex != currentlySelectedIndex) { if (newIndex == 0) { property.objectReferenceValue = null; } else { property.objectReferenceValue = availableComponents[newIndex - 1]; } } }
// Use this for initialization void Start() { updateMovable(); totalDistance = movable.GetComponentsInParent <SpriteRenderer>()[1].bounds.size.x - 2 * offset; position = -totalDistance / 2; movable.GetComponent <Transform> ().localPosition = new Vector3(position, GetComponentInChildren <Transform> ().localPosition.y); }
public static PanelStateEnum GetContainerVisibilityInHierarchy(GameObject p_object) { if (p_object != null) { if (!p_object.activeInHierarchy) { return(PanelStateEnum.Closed); } else { TweenContainer[] v_componentsInParent = p_object.GetComponentsInParent <TweenContainer>(); PanelStateEnum v_return = PanelStateEnum.Opened; foreach (TweenContainer v_cont in v_componentsInParent) { if (v_cont != null && v_cont.enabled && (v_cont.PanelState == PanelStateEnum.Closed || v_cont.PanelState == PanelStateEnum.Closing)) { v_return = v_cont.PanelState; } } if (v_return != PanelStateEnum.Closed && v_return != PanelStateEnum.Closing) { v_return = GetContainerVisibility(p_object); } return(v_return); } } return(PanelStateEnum.Closed); }
void OnCollisionStay(Collision collision) { if (hit) { return; } GameObject other = collision.gameObject; Character[] characters = other.GetComponentsInParent <Character>(); if (characters.Length == 0) { return; } Character character = characters[0]; if (!character.InStateGroup("rolling") || !character.InStateGroup("ground")) { return; } if (Mathf.Abs(character.groundSpeedPrev) < 4.5F) { return; } character.groundSpeed = character.groundSpeedPrev; BeginBreak(character.position.x < transform.position.x ? -1 : 1); }
static int GetComponentsInParent(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { GameObject obj = LuaScriptMgr.GetNetObject <GameObject>(L, 1); Type arg0 = LuaScriptMgr.GetTypeObject(L, 2); Component[] o = obj.GetComponentsInParent(arg0); LuaScriptMgr.PushArray(L, o); return(1); } else if (count == 3) { GameObject obj = LuaScriptMgr.GetNetObject <GameObject>(L, 1); Type arg0 = LuaScriptMgr.GetTypeObject(L, 2); bool arg1 = LuaScriptMgr.GetBoolean(L, 3); Component[] o = obj.GetComponentsInParent(arg0, arg1); LuaScriptMgr.PushArray(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponentsInParent"); } return(0); }
public static void CreateMaterialIcon(MenuCommand menuCommand) { GameObject parent = menuCommand.context as GameObject; if ((parent == null) || (parent.GetComponentsInParent <Canvas>(true).Length == 0)) { GameObject canvas = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster)); canvas.layer = LayerMask.NameToLayer("UI"); canvas.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; GameObjectUtility.SetParentAndAlign(canvas, parent); Undo.RegisterCreatedObjectUndo(canvas, "Create " + canvas.name); if (GameObject.FindObjectOfType <EventSystem>() == null) { GameObject eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule)); GameObjectUtility.SetParentAndAlign(eventSystem, parent); Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name); } parent = canvas; } GameObject gameObject = new GameObject("MaterialIcon", typeof(MaterialIcon)); gameObject.layer = LayerMask.NameToLayer("UI"); GameObjectUtility.SetParentAndAlign(gameObject, parent); Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name); Selection.activeObject = gameObject; }
public static IEnumerable <BindableMember <PropertyInfo> > GetListItemViewModelProperties(GameObject rGo, Type rViewPropType) { var rBindableMembers = rGo.GetComponentsInParent <ViewModelDataSourceTemplate>(true) .Where(ds => ds != null && !string.IsNullOrEmpty(ds.TemplatePath)) .DefaultIfEmpty() .SelectMany(ds => { var rType = TypeResolveManager.Instance.GetType(ds.TemplatePath); if (rType == null) { return(new BindableMember <PropertyInfo> [0]); } return(rType .GetProperties(BindingFlags.Instance | BindingFlags.Public) .DefaultIfEmpty() .Select(prop => new BindableMember <PropertyInfo>(ds, prop, rType))); }) .DefaultIfEmpty() .Where(prop => prop != null && prop.Member.PropertyType.Equals(rViewPropType) && prop.Member.GetSetMethod(false) != null && prop.Member.GetGetMethod(false) != null && !ViewComponentBlackList.Contains(prop.ViewModelType) && prop.Member.GetCustomAttributes(typeof(DataBindingAttribute), true).Any() ) .DefaultIfEmpty(); return(rBindableMembers); }
static int GetComponentsInParent(IntPtr l) { int count = LuaDLL.lua_gettop(l); if (count == 2) { GameObject obj = (GameObject)luaMgr.GetNetObject(1); Type arg0 = (Type)luaMgr.GetNetObject(2); Component[] o = obj.GetComponentsInParent(arg0); luaMgr.PushResult(o); return(1); } else if (count == 3) { GameObject obj = (GameObject)luaMgr.GetNetObject(1); Type arg0 = (Type)luaMgr.GetNetObject(2); bool arg1 = luaMgr.GetBoolean(3); Component[] o = obj.GetComponentsInParent(arg0, arg1); luaMgr.PushResult(o); return(1); } else { LuaDLL.luaL_error(l, "The best overloaded method match for 'GameObject.GetComponentsInParent' has some invalid arguments"); } return(0); }
public static JSValue _js_game_object_get_components_in_parent(JSContext ctx, JSValue ctor, GameObject gameObject, Type type, bool includeInactive) { if (JSApi.JS_IsConstructor(ctx, ctor) == 1) { var header = JSApi.jsb_get_payload_header(ctor); if (header.type_id == BridgeObjectType.None) // it's a plain js value { if (type == typeof(MonoBehaviour)) { var array = JSApi.JS_NewArray(ctx); var length = 0; var allBridges = gameObject.GetComponentsInParent <JSBehaviour>(includeInactive); for (int i = 0, size = allBridges.Length; i < size; i++) { var bridge = allBridges[i]; var instanceOf = bridge.IsInstanceOf(ctor); if (instanceOf == 1) { JSApi.JS_SetPropertyUint32(ctx, array, (uint)length, bridge.CloneValue()); length++; } if (instanceOf == -1) { ctx.print_exception(); } } return(array); // or return an empty array? } } } return(JSApi.JS_UNDEFINED); }
void ReScan() { // currentChildState=false; if (Selection.activeGameObject == null) { return; } else { //if (Selection.activeGameObject.GetComponent<ChildrenHide>() == null && chList = new List <ChildrenHide>(); foreach (object o in Selection.objects) { GameObject game = o as GameObject; if (game != null) { ChildrenHide[] chs = game.GetComponentsInParent <ChildrenHide>(); chList.AddRange(chs); } } // bool showing=true; for (int i = 0; i < chList.Count; i++) { if (chList[i].childrenVisbility == ChildrenHide.ChildVis.HIDE) { EditorGUIUtility.PingObject(chList[i]); i = chList.Count; } } } Repaint(); }
public static TempList <T> GetComponentsInParentNonAlloc <T>(this GameObject go, bool includeInactive) { var buffer = Allocators.GetBuffer <T>(); go.GetComponentsInParent(includeInactive, buffer.list); return(buffer); }
public static int GetStencilID(GameObject obj) { int num = 0; MaterialManager.m_maskComponents = obj.GetComponentsInParent <Mask>(); for (int i = 0; i < MaterialManager.m_maskComponents.Length; i++) { if (MaterialManager.m_maskComponents[i].MaskEnabled()) { num++; } } switch (num) { case 0: return(0); case 1: return(1); case 2: return(3); case 3: return(11); default: return(0); } }
/// <summary> /// Returns a cached component references for the specified type. /// </summary> /// <param name="gameObject">The GameObject (or child GameObject) to get the component reference of.</param> /// <param name="type">The type of component to get.</param> /// <returns>The cached component references.</returns> public static T[] GetCachedParentComponents <T>(this GameObject gameObject) { Dictionary <Type, object[]> typeComponentMap; // Return the cached component if it exists. if (s_GameObjectParentComponentsMap.TryGetValue(gameObject, out typeComponentMap)) { object[] targetObject; if (typeComponentMap.TryGetValue(typeof(T), out targetObject)) { return(targetObject as T[]); } } else { // The cached component doesn't exist for the specified type. typeComponentMap = new Dictionary <Type, object[]>(); s_GameObjectParentComponentsMap.Add(gameObject, typeComponentMap); } // Find the component references and cache the results. var targetComponents = gameObject.GetComponentsInParent <T>() as T[]; typeComponentMap.Add(typeof(T), targetComponents as object[]); return(targetComponents); }
/// <summary> /// Function to get the Stencil ID /// </summary> /// <param name="obj"></param> /// <returns></returns> public static int GetStencilID(GameObject obj) { int count = 0; var maskComponents = TMP_ListPool <Mask> .Get(); obj.GetComponentsInParent <Mask>(false, maskComponents); for (int i = 0; i < maskComponents.Count; i++) { #if UNITY_5_2 || UNITY_5_3_OR_NEWER if (maskComponents[i].IsActive()) { count += 1; } #else if (maskComponents[i].MaskEnabled()) { count += 1; } #endif } TMP_ListPool <Mask> .Release(maskComponents); return(Mathf.Min((1 << count) - 1, 255)); }
// Use this for initialization void Start() { Cube cube = target.GetComponent <Cube>(); Transform t = target.GetComponent <Transform>(); Debug.Log(cube); Debug.Log(t); Debug.Log("------------------------------"); Cube[] cubes = target.GetComponents <Cube>(); Debug.Log(cubes.Length); Debug.Log("------------------------------"); cubes = target.GetComponentsInChildren <Cube>(); foreach (Cube c in cubes) { Debug.Log(c); } Debug.Log("------------------------------"); cubes = target.GetComponentsInParent <Cube>(); foreach (Cube c in cubes) { Debug.Log(c); } }
public void EndCommit() { if (generatedBrushes == null) return; var bounds = BoundsUtilities.GetBounds(generatedBrushes); if (!bounds.IsEmpty()) {/* var center = bounds.Center - operationGameObject.transform.position; GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center); SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center); operationGameObject.transform.position += center;*/ ControlMeshUtility.RebuildShapes(generatedBrushes); var models = operationGameObject.GetComponentsInParent<CSGModel>(includeInactive: true); var model = models.Length == 0 ? null : models[0]; model.forceUpdate = true; InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); Undo.CollapseUndoOperations(undoGroupIndex); Cleanup(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) Selection.objects = generatedGameObjects; Reset(); } if (shapeCommitted != null) shapeCommitted(); }
public static bool GameObject_GetComponentInParentT1(JSVCall vc, int count) { help_getGoAndType(vc); if (_typeInfo.IsCSMonoBehaviour) { var com = _curGo.GetComponentInParent(_type); JSMgr.datax.setObject((int)JSApi.SetType.Rval, com); } else { var com = _curGo.GetComponentsInParent <JSComponent>(); help_searchAndRetCom(vc, com, _typeString); } return(true); }
// Returns true if the given game object is part of a Robot private bool IsRobot(GameObject gObject){ if (gObject.tag.Equals("Circle")){ return false; } if (gObject.tag.Equals("Robot")){ return true; } else { foreach (Transform childTrans in gObject.GetComponentsInChildren<Transform>()){ if (childTrans.gameObject.tag.Equals("Robot")){ return true; } } foreach (Transform parentTrans in gObject.GetComponentsInParent<Transform>()){ if (parentTrans.gameObject.tag.Equals("Robot")){ return true; } } } return false; }
public static T GetNonMarkedComponentInParent <T>(this GameObject p_object, bool p_includeInactive = false, bool p_includeSelf = true, bool p_checkGameobject = false) where T : Component { ArrayList <T> v_components = new ArrayList <T>(p_object.GetComponentsInParent <T>(p_includeInactive)); ArrayList <T> v_selfComponents = new ArrayList <T>(p_object.GetComponents <T>()); if (p_includeSelf) { v_components.MergeList(v_selfComponents); } else { v_components.UnmergeList(v_selfComponents); } T v_return = null; foreach (T v_component in v_components) { if (!IsMarkedToDestroy(v_component, p_checkGameobject)) { v_return = v_component; break; } } return(v_return); }
private static int GetComponentsInParent(IntPtr L) { switch (LuaDLL.lua_gettop(L)) { case 2: { GameObject obj2 = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject"); System.Type typeObject = LuaScriptMgr.GetTypeObject(L, 2); Component[] componentsInParent = obj2.GetComponentsInParent(typeObject); LuaScriptMgr.PushArray(L, componentsInParent); return(1); } case 3: { GameObject obj3 = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject"); System.Type type = LuaScriptMgr.GetTypeObject(L, 2); bool boolean = LuaScriptMgr.GetBoolean(L, 3); Component[] o = obj3.GetComponentsInParent(type, boolean); LuaScriptMgr.PushArray(L, o); return(1); } } LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponentsInParent"); return(0); }
private TVarListener[] GetComponents <TVarListener>(GameObject gameObject) where TVarListener : VarListener { TVarListener[] list; switch (Placed) { case ComponentPlace.Child: list = gameObject.GetComponentsInChildren <TVarListener>(); break; case ComponentPlace.Parent: list = gameObject.GetComponentsInParent <TVarListener>(); break; case ComponentPlace.Self: list = gameObject.GetComponents <TVarListener>(); break; default: list = gameObject.GetComponents <TVarListener>(); break; } list = list.ToList().FindAll(x => ListenerID.Value == 0 || x.ID == ListenerID.Value).ToArray(); return(list); }
public static IEnumerable <T> All <T>(this GameObject go, Search where = Search.InObjectOnly) where T : class { switch (where) { case Search.InObjectOnly: return(go.GetComponents <T>()); case Search.InParents: return(go.GetComponentsInParent <T>()); case Search.InChildren: return(go.GetComponentsInChildren <T>()); case Search.InWholeHierarchy: var parentSearch = go.transform.parent != null ? go.transform.parent.gameObject.GetComponentsInParent <T>() : new T[] { }; return(parentSearch.AndAlso(go.GetComponentsInChildren <T>())); default: throw new UnsupportedSearchException(where); } }
private GameObject FindGameObjectWithTagInParents(GameObject start, string tag) { Transform[] parents = start.GetComponentsInParent<Transform>(); foreach (Transform parent in parents) { if (parent.gameObject.CompareTag (tag)) return parent.gameObject; } return null; }
public static FocusContainer GetDirectFocusContainerComponent(GameObject p_child) { if(p_child != null) { FocusContainer[] v_parentsFocus = p_child.GetComponentsInParent<FocusContainer>(); FocusContainer v_directParentFocus = null; foreach(FocusContainer v_parentFocus in v_parentsFocus) { if(v_parentFocus != null && v_parentFocus.enabled) { v_directParentFocus = v_parentFocus; break; } } return v_directParentFocus; } return null; }
private void trapOther(GameObject thing) { if (thing.rigidbody) { thing.rigidbody.velocity = Vector3.zero; thing.rigidbody.useGravity = false; trappedRigidbodies.Add(thing.rigidbody); } if (thing.GetComponentsInChildren<Rigidbody>().Length > 0) { foreach (Rigidbody body in thing.GetComponentsInChildren<Rigidbody>()) { body.velocity = Vector3.zero; body.useGravity = false; trappedRigidbodies.Add(body); } } if (thing.GetComponentsInParent<Rigidbody>().Length > 0) { foreach (Rigidbody body in thing.GetComponentsInParent<Rigidbody>()) { body.velocity = Vector3.zero; body.useGravity = false; trappedRigidbodies.Add(body); } } trappedThings.Add(thing); }