GetChildNodeByName() public static méthode

public static GetChildNodeByName ( GameObject gameobj, string name ) : Transform
gameobj UnityEngine.GameObject
name string
Résultat UnityEngine.Transform
Exemple #1
0
        private AudioSource CreateNewAudioSource(GameObject obj)
        {
            if (string.IsNullOrEmpty(m_AudioSourceName))
            {
                return(null);
            }
            GameObject audiosource_obj = ResourceSystem.Instance.NewObject(
                m_AudioSourceName,
                (StartTime + m_AudioSourceLifeTime) / 1000.0f) as GameObject;

            if (audiosource_obj == null)
            {
                return(null);
            }
            if (m_IsBoneSound)
            {
                Transform attach_node = TriggerUtil.GetChildNodeByName(obj, m_BoneName);
                if (attach_node != null)
                {
                    audiosource_obj.transform.SetParent(attach_node);
                    audiosource_obj.transform.rotation = Quaternion.identity;
                    audiosource_obj.transform.position = Vector3.zero;
                    if (!m_IsAttach)
                    {
                        audiosource_obj.transform.SetParent(null);
                    }
                }
                else
                {
                    audiosource_obj.transform.position = obj.transform.TransformPoint(m_Position);
                    if (m_IsAttach)
                    {
                        audiosource_obj.transform.SetParent(obj.transform);
                    }
                }
            }
            else
            {
                audiosource_obj.transform.position = obj.transform.TransformPoint(m_Position);
                if (m_IsAttach)
                {
                    audiosource_obj.transform.SetParent(obj.transform);
                }
            }
            return(audiosource_obj.GetComponentInChildren <AudioSource>());
        }
        private void AttachToObject(GameObject obj, GameObject owner)
        {
            Transform parent = TriggerUtil.GetChildNodeByName(owner, m_BoneName);

            if (parent == null)
            {
                parent = owner.transform;
            }
            obj.transform.SetParent(parent);
            Vector3 world_pos = parent.TransformPoint(m_Postion);

            TriggerUtil.MoveObjTo(obj, world_pos);
            obj.transform.localRotation = Quaternion.Euler(m_Rotate);
            if (!m_IsAttach)
            {
                obj.transform.SetParent(null);
            }
        }
Exemple #3
0
        public static void MoveChildToNode(GameObject obj, string childname, string nodename)
        {
            Transform child = GetChildNodeByName(obj, childname);

            if (child == null)
            {
                GameFramework.LogSystem.Info("----not find child! {0} on {1}", childname, obj.name);
                return;
            }
            Transform togglenode = TriggerUtil.GetChildNodeByName(obj, nodename);

            if (togglenode == null)
            {
                GameFramework.LogSystem.Info("----not find node! {0} on {1}", nodename, obj.name);
                return;
            }
            child.parent        = togglenode;
            child.localRotation = Quaternion.identity;
            child.localPosition = Vector3.zero;
        }
        private void AttachToObjectForRandomRotate(GameObject obj, GameObject owner)
        {
            Transform parent = TriggerUtil.GetChildNodeByName(owner, m_BoneName);

            if (parent == null)
            {
                parent = owner.transform;
            }
            obj.transform.SetParent(parent);
            Vector3 world_pos = parent.TransformPoint(m_Postion);

            TriggerUtil.MoveObjTo(obj, world_pos);
            Vector3 resultrotate = new Vector3(
                m_Rotate.x + UnityEngine.Random.Range(m_RandomRotate.x / -2, m_RandomRotate.x / 2),
                m_Rotate.y + UnityEngine.Random.Range(m_RandomRotate.y / -2, m_RandomRotate.y / 2),
                m_Rotate.z + UnityEngine.Random.Range(m_RandomRotate.z / -2, m_RandomRotate.z / 2));

            obj.transform.localRotation = Quaternion.Euler(resultrotate);
            if (!m_IsAttach)
            {
                obj.transform.SetParent(null);
            }
        }