/// <summary> /// 获取非Shader的内置资源引用 /// </summary> /// <param name="asset"></param> /// <returns></returns> private List <UnityEngine.Object> getReferenceBuildInResourceExcludeShader(UnityEngine.GameObject asset) { // 主要提起以下几种资源: // 1. 内置Texture // 2. 内置材质 // 人物模型和粒子特效 var assetlist = new List <UnityEngine.Object>(); var allrenders = asset.GetComponentsInChildren <Renderer>(); foreach (var render in allrenders) { if (render.sharedMaterial != null && EditorResourceUtilities.isBuildInResource(render.sharedMaterial)) { assetlist.Add(render.sharedMaterial); } } // UI组件 var allgraphics = asset.GetComponentsInChildren <Graphic>(); foreach (var graphic in allgraphics) { if (graphic.material != null && EditorResourceUtilities.isBuildInResource(graphic.material)) { assetlist.Add(graphic.material); } if (graphic.mainTexture != null && EditorResourceUtilities.isBuildInResource(graphic.mainTexture)) { assetlist.Add(graphic.mainTexture); } } return(assetlist); }
void Awake(){ thisObj=gameObject; thisT=transform; thisObj.layer=LayerManager.LayerShootObject(); if(autoSearchLineRenderer){ LineRenderer[] lines = thisObj.GetComponentsInChildren<LineRenderer>(true); for(int i=0; i<lines.Length; i++) lineList.Add(lines[i]); } TrailRenderer[] trails = thisObj.GetComponentsInChildren<TrailRenderer>(true); for(int i=0; i<trails.Length; i++) trailList.Add(trails[i]); if(type==_ShootObjectType.FPSProjectile){ SphereCollider sphereCol=GetComponent<SphereCollider>(); if(sphereCol==null){ sphereCol=thisObj.AddComponent<SphereCollider>(); sphereCol.radius=0.15f; } hitRadius=sphereCol.radius; } if(shootEffect!=null) ObjectPoolManager.New(shootEffect); if(hitEffect!=null) ObjectPoolManager.New(hitEffect); }
void OnMouseDown() { if (!GameObject.Find ("Popup(Clone)") && !GameObject.Find ("Map(Clone)") && !GameObject.Find ("EncounterBox(Clone)") && !GameObject.Find ("gradList(Clone)") && !GameObject.Find ("gratzPop(Clone)") && !GameObject.Find ("TutorialBox(Clone)")) { mainVar.selectedStudent = this.name; Debug.Log (this); studentData = this.GetComponent<StudentData> (); if (mainVar.gameState) { newPopup = Instantiate (Resources.Load ("Popup"))as GameObject; newPopup.GetComponentsInChildren<TextMesh> () [1].text = studentData.name; newPopup.GetComponentsInChildren<TextMesh> () [2].text = studentData.major; newPopup.GetComponentsInChildren<TextMesh> () [0].text = "'" + studentData.tagline + "'"; // cgpaBar = studentData.CGPA; // cgpaBar = (cgpaBar - 0) / (12 - 0) * (3 - 0) + 0; // newPopup.GetComponentsInChildren<Transform> () [10].localScale = new Vector3 (cgpaBar, 3f, 3f); // newPopup.AddComponent<BoxCollider2D> (); // newPopup.layer = 5; // newPopup.GetComponent<BoxCollider2D> ().isTrigger = true; // newPopup.GetComponent<BoxCollider2D> ().size = new Vector2 (5, 3); AudioSource[] audioSources = GameObject.Find ("Main Camera").GetComponents<AudioSource> (); audioSources [1].Play (); // newPopup.AddComponent<AudioSource>(); // newPopup.GetComponent<AudioSource>().clip = Resources.Load("Audio/blip") as AudioClip; // newPopup.GetComponent<AudioSource>().Play (); newPopup.AddComponent<DestoryPopup> (); mainVar.gameState = false; } } // Debug.Log (this.name); }
/// <summary> /// Enables the ragdool. /// </summary> /// <remarks> /// The GameObject must have a Collider and a Rigidbody. /// </remarks> /// <param name="enable">If set to <c>true</c> enable.</param> public static void EnableRagdoll(GameObject gameObject, bool enable) { var bones = gameObject.GetComponentsInChildren<Rigidbody>(); for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++) { var bone = bones[boneIndex]; var collider = bone.GetComponent<Collider>(); if (collider != null) { collider.enabled = enable; } bone.isKinematic = !enable; bone.mass = (enable ? 0.1f : 0.01f); } gameObject.GetComponent<Collider>().enabled = !enable; var rigidbody = gameObject.GetComponent<Rigidbody>(); if (enable) { rigidbody.useGravity = false; rigidbody.isKinematic = true; } else { rigidbody.mass = 1.0f; rigidbody.useGravity = true; rigidbody.isKinematic = false; } var animators = gameObject.GetComponentsInChildren<Animator>(); for (var animatorIndex = 0; animatorIndex < animators.Length; animatorIndex++) { animators[animatorIndex].enabled = !enable; } }
public void initialise(ASPPainter painter) { _painter = painter; ScreenMessages.PostScreenMessage("Paint Pointer - RMB or Escape to exit", 5, ScreenMessageStyle.UPPER_CENTER); if (_pointer == null) { GameObject modelObject = GameDatabase.Instance.GetModel(_pointerModel).gameObject; _pointer = Instantiate(modelObject) as GameObject; Collider[] colliders = _pointer.GetComponentsInChildren<Collider>(true); foreach (Collider collider in colliders) { Destroy(collider); } _meshRenderers = _pointer.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer mesh in _meshRenderers) { mesh.material = new Material(Shader.Find("Transparent/Diffuse")); } _pointer.SetActive(true); } GameEvents.onVesselChange.Add(new EventData<Vessel>.OnEvent(this.OnVesselChange)); }
void Start() { if (particle != null) { GO = Instantiate(particle) as GameObject; GO.transform.SetParent(transform, false); if (autoStart) { foreach (ParticleSystem ps in GO.GetComponentsInChildren<ParticleSystem>()) { ps.loop = true; ps.playOnAwake = true; GO.SetActive(false); GO.SetActive(true); } } else { foreach (ParticleSystem ps in GO.GetComponentsInChildren<ParticleSystem>()) { ps.loop = false; ps.playOnAwake = false; GO.SetActive(false); GO.SetActive(true); } } } }
public Mesh FindMesh1(GameObject go, out GameObject obj) { if ( go ) { MeshFilter[] filters = (MeshFilter[])go.GetComponentsInChildren<MeshFilter>(true); if ( filters.Length > 0 ) { if ( filters[0].gameObject != go ) obj = filters[0].gameObject; else obj = null; return filters[0].mesh; } SkinnedMeshRenderer[] skins = (SkinnedMeshRenderer[])go.GetComponentsInChildren<SkinnedMeshRenderer>(true); if ( skins.Length > 0 ) { if ( skins[0].gameObject != go ) obj = skins[0].gameObject; else obj = null; return skins[0].sharedMesh; } } obj = null; return null; }
void OnPostprocessModel(GameObject go) { MeshRenderer[] meshComponents = go.GetComponentsInChildren<MeshRenderer>(); SkinnedMeshRenderer[] skinMeshComponents = go.GetComponentsInChildren<SkinnedMeshRenderer>(); bool isAnim = false; if(meshComponents.Length == 0 && skinMeshComponents.Length == 0) { isAnim = true; } ModelImporter importer = assetImporter as ModelImporter; if(isAnim) { importer.optimizeMesh = false; importer.importMaterials = false; importer.normalImportMode = ModelImporterTangentSpaceMode.None; importer.tangentImportMode = ModelImporterTangentSpaceMode.None; importer.splitTangentsAcrossSeams = false; } // importer.importAnimation = isAnim; go.tag = isAnim ? EAssetType.Anim.ToString() : EAssetType.Model.ToString(); }
protected override void InitializeDialoguePanel() { m_currentState = DialogueTreeStates.RUNNING; m_dialoguePanel = Instantiate((GameObject)Resources.Load("DialoguePanel", typeof(GameObject))); Text[] messages = m_dialoguePanel.GetComponentsInChildren<Text>(); for(int i=0; i<messages.Length;i++) { if(messages[i].gameObject.name == "Message") { messages[i].text = m_singleMessage; break; } } Button[] buttons = m_dialoguePanel.GetComponentsInChildren<Button>(); for (int i = 0; i < buttons.Length; i++) { if (buttons[i].gameObject.name == "ButtonOptionA") { buttons[i].onClick.AddListener(() => OnOptionClicked()); } else if (buttons[i].gameObject.name == "ButtonOptionB") { buttons[i].onClick.AddListener(() => OnOptionClicked()); } } }
public void ClearTextsAndSprite(GameObject _targ) { new OTTween(DarkBG, 1f).Tween("alpha", 0f); if (_targ.GetComponentsInChildren<OTSprite>() != null) { foreach (OTSprite _spr in _targ.GetComponentsInChildren<OTSprite>()) { _spr.alpha = 0f; } } if (_targ.GetComponentsInChildren<TextUI>() != null) { foreach (TextUI _txt in _targ.GetComponentsInChildren<TextUI>()) { _txt.makeFadeOut(); } } if (_targ.GetComponentsInChildren<UIBtn>() != null) { foreach (UIBtn _btn in _targ.GetComponentsInChildren<UIBtn>()) { _btn.reDisable(); } } }
void Start () { shadowRoot = (GameObject)Instantiate(gameObject); if (hideShadow) shadowRoot.hideFlags = HideFlags.HideInHierarchy; shadowRoot.transform.parent = transform.root; shadowTable = new Dictionary<Transform, Transform>(); Destroy(shadowRoot.GetComponent<SkeletonUtilityKinematicShadow>()); shadowRoot.transform.position = transform.position; shadowRoot.transform.rotation = transform.rotation; Vector3 scaleRef = transform.TransformPoint(Vector3.right); float scale = Vector3.Distance(transform.position, scaleRef); shadowRoot.transform.localScale = Vector3.one; var shadowJoints = shadowRoot.GetComponentsInChildren<Joint>(); foreach (Joint j in shadowJoints) { j.connectedAnchor *= scale; } var joints = GetComponentsInChildren<Joint>(); foreach (var j in joints) Destroy(j); var rbs = GetComponentsInChildren<Rigidbody>(); foreach (var rb in rbs) Destroy(rb); var colliders = GetComponentsInChildren<Collider>(); foreach (var c in colliders) Destroy(c); //match by bone name var shadowBones = shadowRoot.GetComponentsInChildren<SkeletonUtilityBone>(); var bones = GetComponentsInChildren<SkeletonUtilityBone>(); //build bone lookup foreach (var b in bones) { if (b.gameObject == gameObject) continue; foreach (var sb in shadowBones) { if (sb.rigidbody == null) continue; if (sb.boneName == b.boneName) { shadowTable.Add(sb.transform, b.transform); break; } } } foreach (var b in shadowBones) Destroy(b); }
private void GridSetUp(GameObject gridObject, GameObject spriteObject) { for (int i = 0; i < gridObject.GetComponentsInChildren<Image>().Length; i++) { if (gridObject.GetComponentsInChildren<Image>()[i].tag == "Sprite") { gridObject.GetComponentsInChildren<Image>()[i].sprite = spriteObject.GetComponent<Image>().sprite; } } }
void Start() { hinweis = GameObject.Find ("Hinweis"); hinweisText = hinweis.GetComponentsInChildren<Text> (); hinweisBild = hinweis.GetComponentsInChildren<Image> (); showHinweis(false, ""); showtime = 0; }
private void SetEnabledForGameObject(GameObject go, bool enabled) { go.GetComponent<Movement>().enabled = enabled; go.GetComponent<PlayerController>().enabled = enabled; go.GetComponent<Rigidbody>().useGravity = enabled; go.GetComponentsInChildren<MeshRenderer>().SetEnabled(enabled); go.GetComponentsInChildren<Collider>().SetEnabled(enabled); }
// InputManagerSetup internal static void InputRegister( GameObject gameObject ) { controllers = gameObject.GetComponentsInChildren<ControllerBase>(); controllersCount = controllers.Length; buttons = gameObject.GetComponentsInChildren<ButtonBase>(); buttonsCount = buttons.Length; }
void Start () { // Duplicate this gameObject as the "shadow" with a different parent. shadowRoot = Instantiate<GameObject>(this.gameObject); Destroy(shadowRoot.GetComponent<SkeletonUtilityKinematicShadow>()); // Prepare shadow gameObject's properties. var shadowRootTransform = shadowRoot.transform; shadowRootTransform.position = transform.position; shadowRootTransform.rotation = transform.rotation; Vector3 scaleRef = transform.TransformPoint(Vector3.right); float scale = Vector3.Distance(transform.position, scaleRef); shadowRootTransform.localScale = Vector3.one; if (!detachedShadow) { // Do not change to null coalescing operator (??). Unity overloads null checks for UnityEngine.Objects but not the ?? operator. if (parent == null) shadowRootTransform.parent = transform.root; else shadowRootTransform.parent = parent; } if (hideShadow) shadowRoot.hideFlags = HideFlags.HideInHierarchy; var shadowJoints = shadowRoot.GetComponentsInChildren<Joint>(); foreach (Joint j in shadowJoints) j.connectedAnchor *= scale; // Build list of bone pairs (matches shadow transforms with bone transforms) var bones = GetComponentsInChildren<SkeletonUtilityBone>(); var shadowBones = shadowRoot.GetComponentsInChildren<SkeletonUtilityBone>(); foreach (var b in bones) { if (b.gameObject == this.gameObject) continue; foreach (var sb in shadowBones) { if (sb.GetComponent<Rigidbody>() != null && sb.boneName == b.boneName) { shadowTable.Add(new TransformPair { dest = b.transform, src = sb.transform }); break; } } } // Destroy conflicting and unneeded components DestroyComponents(shadowBones); DestroyComponents(GetComponentsInChildren<Joint>()); DestroyComponents(GetComponentsInChildren<Rigidbody>()); DestroyComponents(GetComponentsInChildren<Collider>()); }
public ParticleCacheData(GameObject _particleSystemGameObject) { //Cache variables instantiatedGameObject = _particleSystemGameObject; cachedTransform = instantiatedGameObject.transform; cachedParticleSystem = instantiatedGameObject.GetComponentsInChildren<ParticleSystem>(); burstQuantity = instantiatedGameObject.GetComponentsInChildren<ParticleBurstQuantity>(); if (cachedParticleSystem.Length != burstQuantity.Length) Debug.LogWarning("You have forgot to add the ParticleBurstQuantity sript on the particleSystem: " + _particleSystemGameObject.name +" you should only use Emit"); }
/// <summary> /// 将制定GameObject存在的UITexture和UISprite去色,变灰 /// </summary> /// <param name="targetObj"> 目标物体</param> /// <param name="gray"> 是否变灰</param> /// <param name="atlasName"> 制定图集</param> public void ChangeObjectsToGray(GameObject targetObj, bool gray, AtlasName atlasName = AtlasName.EM_AtlasName_None) { UISprite[] sprites = targetObj.GetComponentsInChildren<UISprite>(); UITexture[] textures = targetObj.GetComponentsInChildren<UITexture>(); for (int i = 0; i < sprites.Length; i++) ChangeUISpriteToGray(sprites[i], gray, atlasName); for (int i = 0; i < textures.Length; i++) ChangeUITextureToGary(textures[i], gray); }
void FadeTexts(GameObject panel, float alphaTarget, float time = 0.5f) { Text[] array = panel.GetComponentsInChildren<Text>(); for (int i = 0; i < array.Length; i++) { array[i].CrossFadeAlpha(alphaTarget, time, false); } Button[] arrayButton = panel.GetComponentsInChildren<Button>(); for (int i = 0; i < arrayButton.Length; i++) { if (alphaTarget == 0) arrayButton[i].interactable = false; else arrayButton[i].interactable = true; } }
public void FadeChoice(GameObject choice) { // Choice1.SetActive(false); Image[] imgs = choice.GetComponentsInChildren<Image>(); Text[] texts = choice.GetComponentsInChildren<Text>(); dealChoice = choice; foreach(Image img in imgs ) img.DOFade(0, 1f).OnComplete( CloseChoice ); foreach(Text text in texts ) text.DOFade(0, 1f); }
// TODO: GS cache with gameobjecttopinfo public static bool HasColliderDeep(UnityEngine.GameObject obj, bool collider3d) { Component[] components = null; if (collider3d) { components = obj.GetComponentsInChildren <Collider>(true); } else { components = obj.GetComponentsInChildren <Collider2D>(true); } return(components.Length != 0); }
IEnumerator Respwan(GameObject player, GameObject spawn) { player.GetComponent<BoxCollider> ().enabled = false; player.GetComponent<Controls> ().enabled = false; player.GetComponent<PhisicalObject> ().enabled = false; foreach (Light l in player.GetComponentsInChildren<Light> ()) { l.enabled = false; } foreach (PlayerParticle p in player.GetComponentsInChildren<PlayerParticle>()) { p.GetComponentInChildren<Light>().enabled = true; p.scatter(); } for (float f = 1f; f >= 0.1; f -= 0.05f) { yield return null; } Vector3 oldPosition = player.transform.position; player.transform.position = spawn.transform.position; foreach (Light l in player.GetComponentsInChildren<Light> ()) { l.enabled = true; } foreach (PlayerParticle p in player.GetComponentsInChildren<PlayerParticle>()) { p.transform.position = p.transform.position + (oldPosition - player.transform.position); p.startReform(); } for (float f = 0f; f <= 1; f += 0.05f) { foreach (PlayerParticle p in player.GetComponentsInChildren<PlayerParticle>()) { p.ReformLerp(f); } yield return null; } foreach (PlayerParticle p in player.GetComponentsInChildren<PlayerParticle>()) { p.ReformLerp(1); } player.GetComponent<PhisicalObject> ().enabled = true; player.GetComponent<BoxCollider> ().enabled = true; player.GetComponent<Controls> ().enabled = true; foreach (PlayerParticle p in player.GetComponentsInChildren<PlayerParticle>()) { p.GetComponentInChildren<Light>().enabled = false; } }
void window_onShowWindow(bool isShow, bool isStart) { if (isShow) { if (dummy == null) { GameObject pageDown = ControlView.Instance.m_currentPageDown; if (pageDown == null) return; WRPageQuestionDown qDown = pageDown.GetComponent<WRPageQuestionDown>(); target = qDown.m_defaultUI.gameObject; dummy = GameObject.Instantiate(target) as GameObject; dummy.transform.parent = transform; dummy.transform.localPosition = target.transform.localPosition; dummy.transform.localScale = target.transform.localScale; // 팝업 위에오도록 depth 조절 UIPanel[] panels = dummy.GetComponentsInChildren<UIPanel>(); for (int i = 0; i < panels.Length; i++) { panels[i].depth = 80; } GameObject pageUp = ControlView.Instance.m_currentPageUp; if (pageUp == null) return; //ControlQuestionPage qUp = pageUp.GetComponent<ControlQuestionPage>(); // 정답인 collider 제거 InitToggle[] collider = dummy.GetComponentsInChildren<InitToggle>(); for (int i = collider.Length - 1; i >= 0; i--) { Destroy(collider[i]); Destroy(collider[i].GetComponent<UIToggle>()); Destroy(collider[i].GetComponent<BoxCollider>()); } } } else if (!isShow && !isStart) { if (dummy != null) { Destroy(dummy); } } }
public void EnableButtons(GameObject go) { foreach(Button b in go.GetComponentsInChildren<Button>() ) { b.enabled = true; } foreach (Text t in go.GetComponentsInChildren<Text>()) { Debug.Log(t.name); foreach (Button b in t.GetComponentsInChildren<Button>()) { b.enabled = true; } } }
/// <summary> /// Clean up the incoming model if there's a bunk transform /// </summary> /// <param name="go"> /// A <see cref="GameObject"/> /// </param> void OnPostprocessModel(GameObject go) { Component[] skins = go.GetComponentsInChildren<SkinnedMeshRenderer>(); Component[] transforms = go.GetComponentsInChildren<Transform>(); // check for an empty transform corresponding to each skinned mesh name and remove it foreach (SkinnedMeshRenderer skin in skins) { string name = skin.sharedMesh.name; Transform candidate = TransformHelpers.GetTransformInHierarchy(transforms, name); if (candidate == null) continue; if (candidate.GetComponent<SkinnedMeshRenderer>() != null) continue; GameObject.DestroyImmediate(candidate.gameObject, true); } }
public void DisableButtons(GameObject go) { foreach (Button b in go.GetComponentsInChildren<Button>()) { b.enabled = false; } foreach (Text t in go.GetComponentsInChildren<Text>()) { foreach (Button b in t.GetComponentsInChildren<Button>()) { b.enabled = true; } } }
public void OnLoad() { RemoveEvents(); m_panel = m_gameObject.GetComponent <Canvas>(); if (m_panel == null) { m_panel = m_gameObject.AddComponent <Canvas>(); } if (m_gameObject.GetComponent <GraphicRaycaster>() == null) { m_gameObject.AddComponent <GraphicRaycaster>(); } m_panel.overrideSorting = true; //todo //m_gameObject.transform.SetParent(SimpleFramework.LuaHelper.GetPanelManager().parent); m_gameObject.transform.localScale = Vector3.one; m_gameObject.transform.localPosition = new Vector3(0, 0, 0); if (m_isInit == false) { OnInit(); m_isInit = true; } m_isLoad = true; //if (m_sortingOrder == 0) //{ // //} if (m_sortingOrder == 0) { m_sortingOrder = WindowManager.instance.CurrentOrder; } m_panel = m_gameObject.GetComponent <Canvas>(); //if (m_panel.sortingOrder == 0) //{ // m_panel.overrideSorting = true; // m_panel.sortingOrder = m_sortingOrder; //} m_panel.overrideSorting = true; m_panel.sortingOrder = m_sortingOrder; Canvas[] m_panel_array = m_gameObject.GetComponentsInChildren <Canvas>(); foreach (Transform t in m_gameObject.transform) { Canvas tmp = t.GetComponent <Canvas>(); if (tmp == null) { continue; } if (tmp == m_panel) { continue; } tmp.overrideSorting = true; tmp.sortingOrder = tmp.sortingOrder + m_panel.sortingOrder; } }
public static void DumpObject(UnityEngine.GameObject player) { UnityEngine.Component[] comps = player.GetComponents <Component>(); UnityEngine.Component[] Ccomps = player.GetComponentsInChildren <Component>(); UnityEngine.Component[] Pcomps = player.GetComponentsInParent <Component>(); foreach (var entry in comps) { WriteLine($"Name: {entry.name}"); WriteLine($"\tType: {entry.GetType()}"); WriteLine($"\tTag: {entry.tag}"); } WriteLine($"--- {comps.Length} ---", true); foreach (var entry in Ccomps) { WriteLine($"Name: {entry.name}"); WriteLine($"\tType: {entry.GetType()}"); WriteLine($"\tTag: {entry.tag}"); } WriteLine($"--- {Ccomps.Length} ---", true); foreach (var entry in Pcomps) { WriteLine($"Name: {entry.name}"); WriteLine($"\tType: {entry.GetType()}"); WriteLine($"\tTag: {entry.tag}"); } WriteLine($"--- {Pcomps.Length} ---", true); }
//TODO: check if needed? /// <summary> /// Performs SetActive operation for this object and all it's children, which have Comp<T> /// </summary> public static void ChangeActiveDescending <T>(this GameObject obj, bool state) { foreach (var comp in obj.GetComponentsInChildren <T>(true)) { (comp as Behaviour).gameObject.SetActive(state); } }
/// <summary> /// Set enabled property of the Comp<T> for this object and all it's children /// </summary> public static void ChangeEnabledDescending <T>(this GameObject obj, bool state) { foreach (var comp in obj.GetComponentsInChildren <T>(true)) { (comp as Behaviour).enabled = state; } }
static public int GetComponentsInChildren(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); var ret = self.GetComponentsInChildren(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); var ret = self.GetComponentsInChildren(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
/* * 如果Scaley>=1024 =>y=1280 * */ public static bool HandleYScale(UnityEngine.GameObject obj) { // string strCurPath = AssetDatabase.GetAssetPath(obj); bool ret = false; if(obj != null) { Component[] childcomponentls = obj.GetComponentsInChildren(typeof(Transform), true); if(childcomponentls != null) { if(childcomponentls.Length>0) { foreach (Component co in childcomponentls) { Transform tr = co as Transform; if(tr != null) { //y>=1024 =>y=1280 if(tr.localScale.y> 1023f && tr.localScale.y<1280f) { Debug.Log ("$$ localScale y="+tr.localScale.y+" y=1280f "); tr.localScale = new Vector3(tr.localScale.x, 1280f, tr.localScale.z); ret = true; } } } } } } return ret; }
public void OnClick(float distance = Mathf.Infinity) { if (distance > availableDistance) return; m_itemInfoPanel = GameObject.FindGameObjectWithTag("viewable item info"); if (m_itemInfoPanel == null) { _CreateItemInfoPanel(); } m_itemInfoPanel.transform.position = Vector3.zero; CanvasGroup canvasGroup = m_itemInfoPanel.GetComponent<CanvasGroup>(); Text[] texts = m_itemInfoPanel.GetComponentsInChildren<Text>(); texts[0].text = m_itemInfo.name; texts[1].text = m_itemInfo.info; Sequence seq = DOTween.Sequence(); seq.Append(m_itemInfoPanel.transform.GetChild(0).DOScale(1, 0.2f)) .Join(canvasGroup.DOFade(1, 0.2f)) .AppendCallback(delegate { canvasGroup.interactable = true; }); }
static public int GetComponentsInChildren(IntPtr l) { try{ if (matchType(l, 2, typeof(System.Type))) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); UnityEngine.Component[] ret = self.GetComponentsInChildren(a1); pushValue(l, ret); return(1); } else if (matchType(l, 2, typeof(System.Type), typeof(System.Boolean))) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); UnityEngine.Component[] ret = self.GetComponentsInChildren(a1, a2); pushValue(l, ret); return(1); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static int GetComponentsInChildren(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.GameObject), typeof(System.Type))) { UnityEngine.GameObject obj = (UnityEngine.GameObject)ToLua.ToObject(L, 1); System.Type arg0 = (System.Type)ToLua.ToObject(L, 2); UnityEngine.Component[] o = obj.GetComponentsInChildren(arg0); ToLua.Push(L, o); return(1); } else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.GameObject), typeof(System.Type), typeof(bool))) { UnityEngine.GameObject obj = (UnityEngine.GameObject)ToLua.ToObject(L, 1); System.Type arg0 = (System.Type)ToLua.ToObject(L, 2); bool arg1 = LuaDLL.lua_toboolean(L, 3); UnityEngine.Component[] o = obj.GetComponentsInChildren(arg0, arg1); ToLua.Push(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.GameObject.GetComponentsInChildren")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void SetSlot(GameObject slotObject, ShipComponentDatablock target, bool setBackgroundtexture = true) { var itemSlot = slotObject.GetComponent<UIItemSlot>(); if (target == null) { if (itemSlot == null) return; itemSlot.Assign(container.SlotEmptyTexture); return; } PlayMakerFSM.FindFsmOnGameObject(slotObject, "FSM").FsmVariables.FindFsmObject("ComponentObject").Value = target; var slotImages = slotObject.GetComponentsInChildren<Image>(); slotImages[1].sprite = Sprite.Create(target.Icon, new Rect(0, 0, target.Icon.width, target.Icon.height), new Vector2(0.5f, 0.5f)); slotImages[1].color = Color.white; if(setBackgroundtexture) slotImages[0].sprite = container.SlotFilledTexture; slotImages[0].color = Color.white; if (itemSlot == null) return; itemSlot.hoverNormalColor = Color.white; itemSlot.hoverHighlightColor = container.SlotFilledHoverColor; itemSlot.SetIcon(container.SlotFilledTexture); itemSlot.hoverTargetGraphic.color = Color.white; itemSlot.OnPointerExit(null); }
/* * 粒子中,renderer里面maxParticleSize 设为100 * */ public static bool HandleParticleSystem(UnityEngine.GameObject obj) { bool ret = false; if(obj != null) { Component[] childcomponentls = obj.GetComponentsInChildren(typeof(ParticleSystem), true); if(childcomponentls != null) { if(childcomponentls.Length>0) { foreach (Component co in childcomponentls) { ParticleSystem panel = co as ParticleSystem ; if(panel != null) { ParticleSystemRenderer[] renderers = panel.GetComponents<ParticleSystemRenderer>(); foreach (ParticleSystemRenderer re in renderers) { if(re.maxParticleSize < 100) { re.maxParticleSize = 100; ret = true; Debug.Log ("$$ ParticleSystemRenderer maxParticleSize = 100 "); } } } } } } } return ret; }
static void OnSetState(GameObject gameObject, byte prevState, byte currState) { switch (currState) { case 0: // Begin fire. { //gameObject.GetComponent<Collider>().enabled = true; ParticleSystem[] particleSystems = gameObject.GetComponentsInChildren<ParticleSystem>(); foreach (ParticleSystem particleSystem in particleSystems) particleSystem.Play(); gameObject.GetComponent<CFireHazard>().burning_internal = true; gameObject.GetComponent<CActorAtmosphericConsumer>().SetAtmosphereConsumption(true); } break; case 2: // End fire. { //gameObject.GetComponent<Collider>().enabled = false; ParticleSystem[] particleSystems = gameObject.GetComponentsInChildren<ParticleSystem>(); foreach (ParticleSystem particleSystem in particleSystems) particleSystem.Stop(); gameObject.GetComponent<CFireHazard>().burning_internal = false; gameObject.GetComponent<CActorAtmosphericConsumer>().SetAtmosphereConsumption(false); } break; } }
void SetTag(GameObject parent) { if (parent == null) { return; } if (string.IsNullOrEmpty(filterByComponent.Value)) // do all children { foreach (Transform child in parent.transform) { child.gameObject.tag = tag.Value; } } else { UpdateComponentFilter(); if (componentFilter != null) // filter by component { var root = parent.GetComponentsInChildren(componentFilter); foreach (var child in root) { child.gameObject.tag = tag.Value; } } } Finish(); }
/* * 如果BoxCollid的Y大于960,一律调整到1280 * */ public static bool HandlePanel(UnityEngine.GameObject obj) { bool ret = false; if(obj != null) { Component[] childcomponentls = obj.GetComponentsInChildren(typeof(UIPanel), true); if(childcomponentls != null) { if(childcomponentls.Length>0) { foreach (Component co in childcomponentls) { UIPanel panel = co as UIPanel; if(panel != null) { // #define NGUI_OLD_VERSION #if NGUI_OLD_VERSION if(panel.depthPass == true) { Debug.Log ("$$ panel.depthPass change to false "); panel.depthPass = false; ret = true; } #endif } } } } } return ret; }
//Should be its own Class! public void GenerateCloud() { //Creates Cloud GameObject GameObject cloud = new GameObject(); cloud.transform.position = new Vector3(0,0,0); cloud.name = "Cloud"; //Create Platforms platformGen.GeneratePlatforms(grid,cloud); //Add Plants collectibleGen.GenerateCollectibles (grid, cloud); //Shift Cloud Vector3 bottomLeft = Camera.main.ScreenToWorldPoint (new Vector3 (0f, 0f, 0f)); Vector3 topRight = Camera.main.ScreenToWorldPoint (new Vector3 (Camera.main.pixelWidth, Camera.main.pixelHeight, 0f)); bottomLeft.y = Camera.main.GetComponent<FixedHeight> ().height - (topRight.y - bottomLeft.y)/2f; cloud.transform.position = new Vector3(topRight.x,bottomLeft.y, cloud.transform.position.z); cloud.AddComponent<Cloud>(); Transform[] children = cloud.GetComponentsInChildren<Transform>(); float tempx = 0f; for(int i = 0; i < children.Length; i++) { if(children[i].position.x > tempx) { cloud.GetComponent<Cloud>().farthestPlatform = children[i].gameObject; tempx = children[i].position.x; } } //Debug.Log (children.); //cloud.GetComponent<Cloud>().farthestPlatform = }
/* * 如果BoxCollid的Y大于960,一律调整到1280 * */ public static bool HandleBoxCol(UnityEngine.GameObject obj) { bool ret = false; if(obj != null) { Component[] childcomponentls = obj.GetComponentsInChildren(typeof(BoxCollider), true); if(childcomponentls != null) { if(childcomponentls.Length>0) { foreach (Component col in childcomponentls) { BoxCollider box = col as BoxCollider; //高度大于960的一律改成1280 if(box.size.y > 959f && box.size.y< 1280f) { Debug.Log ("$$ box.size.y="+box.size.y+" => y=1280f "); box.size = new Vector3(box.size.x, 1280f, box.size.z); ret = true; } } } } } return ret; }
// 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 void StaticBatching(UnityEngine.GameObject go) { MeshRenderer[] mrs = go.GetComponentsInChildren <MeshRenderer>(); _BatchInfos.Clear(); foreach (MeshRenderer mr in mrs) { var mat = mr.material; if (mat != null) { BatchItem o; if (!_BatchInfos.TryGetValue(mat.name, out o)) { o = new BatchItem() { MeshList = new List <MeshRenderer>() }; _BatchInfos.Add(mat.name, o); } o.MeshList.Add(mr); } } int index = 0; var e = _BatchInfos.GetEnumerator(); while (e.MoveNext()) { BatchItem pb = e.Current.Value; if (pb.MeshList.Count <= 1) { continue; } var root = new GameObject(HobaText.Format("Batch{0}", index++)); var mt = pb.MeshList[0].sharedMaterial; var goArray = new GameObject[pb.MeshList.Count]; var rootTrans = root.transform; for (int i = 0; i < pb.MeshList.Count; i++) { var cc = pb.MeshList[i]; var g = cc.gameObject; g.transform.parent = rootTrans; if (i != 0) { cc.sharedMaterial = mt; } goArray[i] = g; } StaticBatchingUtility.Combine(goArray, root); rootTrans.parent = go.transform; } e.Dispose(); }
private void OnEnable() { _target = target as SortingLayer; _rootGameObj = _target.gameObject; Renderer renderer = _rootGameObj.renderer; if (!renderer) { Renderer[] renderers = _rootGameObj.GetComponentsInChildren <Renderer>(true); if (renderers.Length > 0) { renderer = renderers[0]; } } Renderer tmpRenderer = null; if (!renderer) { tmpRenderer = _rootGameObj.AddComponent <SpriteRenderer>(); renderer = tmpRenderer; } int origLayerId = renderer.sortingLayerID; for (int i = 0; i < 100; ++i) { renderer.sortingLayerID = i; string name = renderer.sortingLayerName; if (i == 0 && name == "") // this is default { name = "Default"; } if (name != "") { _layerNames.Add(name); _layerIds.Add(renderer.sortingLayerID); } } renderer.sortingLayerID = origLayerId; if (_target.IsDefaultSet) { _oldSortingLayerIdx = _layerIds.FindIndex(x => x == _target.DefaultSortingLayerId); _oldSortingOrder = _target.DefaultSortingOrder; } else { _oldSortingLayerIdx = _layerIds.FindIndex(x => x == renderer.sortingLayerID); _oldSortingOrder = _rootGameObj.renderer ? _rootGameObj.renderer.sortingOrder : renderer.sortingOrder - 1; } if (tmpRenderer) { DestroyImmediate(tmpRenderer); } }
private void SetVisible(UnityEngine.GameObject go, bool visible) { UnityEngine.Renderer[] renderers = go.GetComponentsInChildren <UnityEngine.Renderer>(); for (int i = 0; i < renderers.Length; ++i) { renderers[i].enabled = visible; } }
public static void ResetUITween(UnityEngine.GameObject gameObj) { // 重置出现 移动动画 foreach (UITweener tween in gameObj.GetComponentsInChildren <UITweener>()) { tween.ResetToBeginning(); tween.PlayForward(); } }
public static void UF_ResetTailRender(UnityEngine.GameObject go) { List <TrailRenderer> tempList = ListCache <TrailRenderer> .Acquire(); go.GetComponentsInChildren <TrailRenderer>(false, tempList); foreach (var tr in tempList) { tr.Clear(); } ListCache <TrailRenderer> .Release(tempList); }
public void SetLayerRecursive(UnityEngine.GameObject go, int layer) { if (go == null) { return; } foreach (var trans in go.GetComponentsInChildren <Transform>(true)) { trans.gameObject.layer = layer; } }
public void SetTankEmissive(UnityEngine.GameObject tankRootObject, Color color) { var renderers = tankRootObject.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in renderers) { foreach (Material m in mr.materials) { m.SetColor("_EmissionColor", color * 5f); } } }
private void Start() { //DataController.SaveValue("SkillPoints", 10000); //DataController.SaveValue("Bread", 10000); //DataController.SaveValue("Exp", 10000); SpecialsMenu = GameObject.FindGameObjectWithTag("SpecialsPanel"); Texts = CharacterInfo.GetComponentsInChildren <Text>(); //Debug.Log(Texts.Length); SpecialsMenu.SetActive(false); StatsBars.SetActive(false); }
// SkinnedMeshRenderer private void HandleSkinnedMeshRendererInfo(UnityEngine.GameObject go, ref int vertices, ref int skinnedMeshTriangles, ref int meshCount) { Component[] skinnedMeshes = go.GetComponentsInChildren(typeof(SkinnedMeshRenderer)); for (int skinnedMeshIndex = 0; skinnedMeshIndex < skinnedMeshes.Length; skinnedMeshIndex++) { SkinnedMeshRenderer skinnedMeshRenderer = (SkinnedMeshRenderer)skinnedMeshes[skinnedMeshIndex]; vertices += skinnedMeshRenderer.sharedMesh.vertexCount; skinnedMeshTriangles += skinnedMeshRenderer.sharedMesh.triangles.Length / 3; meshCount++; } }
// MeshFilter private void HandleMeshFilterInfo(UnityEngine.GameObject go, ref int vertices, ref int meshTriangles, ref int meshCount) { Component[] meshFilters = go.GetComponentsInChildren(typeof(MeshFilter)); for (int meshFiltersIndex = 0; meshFiltersIndex < meshFilters.Length; meshFiltersIndex++) { MeshFilter meshFilter = (MeshFilter)meshFilters[meshFiltersIndex]; vertices += meshFilter.sharedMesh.vertexCount; meshTriangles += meshFilter.sharedMesh.triangles.Length / 3; meshCount++; } }
static public int GetComponentsInChildren(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); var ret = self.GetComponentsInChildren(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); var ret = self.GetComponentsInChildren(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function GetComponentsInChildren to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public static void SetCollision(UGameObject obj1, UGameObject obj2, bool enabled) { Collider[] col1 = obj1.GetComponentsInChildren <Collider>(); Collider[] col2 = obj2.GetComponentsInChildren <Collider>(); for (int x = 0; x < col1.Length; x++) { for (int y = 0; y < col2.Length; y++) { Physics.IgnoreCollision(col1[x], col2[y], !enabled); } } }
private void SetTankColor(UnityEngine.GameObject tankRootObject, Color color) { tankRootObject.GetComponent <TankController>().mainTankColor = color; var renderers = tankRootObject.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in renderers) { foreach (Material m in mr.materials) { m.color = color * 2f; } } }
public static T[] FindComponents <T>(this UnityEngine.GameObject g, bool in_parent = true, bool in_children = true, int sibling_depth = 0, bool ignore_self = false) where T : Component { HashSet <T> components = new HashSet <T>(); if (ignore_self) { if (in_children) { foreach (Transform child in g.transform) { components.Concat(child.GetComponentsInChildren <T>()); } } if (in_parent) { components.Concat(g.transform.parent.GetComponentsInParent <T>()); } return(components.ToArray()); } if (!in_children && !in_parent) { return(g.GetComponents <T>()); } if (in_children) { components.Concat(g.GetComponentsInChildren <T>()); } if (in_parent && g.transform.parent) { components.Concat(g.transform.parent.GetComponentsInParent <T>()); } GameObject current = g; GameObject last = g; while (sibling_depth > 0) { current = current.transform.parent.gameObject; if (!current) { break; } components.Concat(current.GetComponentsInChildren <T>()); sibling_depth--; } return(components.ToArray()); }
static public int GetComponentsInChildren__Type(IntPtr l) { try { UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l); System.Type a1; checkType(l, 2, out a1); var ret = self.GetComponentsInChildren(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public static void BeginDissolveEffect(Engine.IRenderObj obj) { if (obj == null) { return; } UnityEngine.GameObject gameObject = obj.GetNode().GetTransForm().gameObject; DissolveScript[] component = gameObject.GetComponentsInChildren <DissolveScript>(true); for (int i = 0; i < component.Length; i++) { component[i].BeginDissolve(); } }
public static void AutoPopulate(UnityEngine.GameObject go, bool recursive, bool forceRepopulate = false, IErrorReport report = null) { Component[] components = go.GetComponentsInChildren <Component>(); foreach (Component component in components) { AutoPopulate(component, forceRepopulate, report); } if (recursive) { foreach (Transform child in go.transform) { AutoPopulate(child.gameObject, recursive, forceRepopulate, report); } } }