示例#1
0
        private void AddAttachObject(Collider collider)
        {
            GameObject parent = m_ColliderInfo.GetCollider();

            if (parent == null)
            {
                return;
            }
            AttachConfig     attach_config = m_ColliderInfo.GetAttachConfig();
            AttachTargetInfo attach_info   = new AttachTargetInfo();

            attach_info.ParentObj  = parent;
            attach_info.TargetObj  = collider.gameObject;
            attach_info.AttachNode = TriggerUtil.GetChildNodeByName(collider.gameObject,
                                                                    attach_config.AttachNodeName);

            UnityEngine.Vector3 hit_pos = parent.GetComponent <Collider>().ClosestPointOnBounds(attach_info.AttachNode.position);
            attach_info.ParentPos     = attach_info.ParentObj.transform.InverseTransformPoint(hit_pos);
            attach_info.Rotate        = attach_config.AttachRotation;
            attach_info.MoveControler = attach_info.TargetObj.GetComponent <CharacterController>();
            m_AttachedObjects.Add(attach_info);
            UpdateAttachTargetPos(attach_info);
            LogicSystem.NotifyGfxMoveControlStart(attach_info.TargetObj, m_OwnSkill.SkillId, true);
            //Debug.Log("---AttachImpact: send " + attach_config.AttachImpact + " to " + attach_info.TargetObj.name);
            m_DamageManager.SendImpactToObject(m_DamageManager.GetOwner(),
                                               collider.gameObject, attach_config.AttachImpact,
                                               attach_config.AttachImpactTime,
                                               m_OwnSkill.SkillId, m_CurHitCountId);
        }
        private void CreateBoxCollider(GameObject obj, float liveTime, object onTriggerEnter,
                                       object onTriggerExit, object onDestroy)
        {
            GameObject collider = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube);

            collider.transform.localScale = m_Size;
            BoxCollider boxcollider = collider.GetComponent <BoxCollider>();

            if (boxcollider != null)
            {
                boxcollider.isTrigger = true;
            }
            collider.layer = LayerMask.NameToLayer("DamageCollider");;
            Rigidbody rigidbody = collider.AddComponent <Rigidbody>();

            rigidbody.useGravity = false;
            ColliderScript cs = (ColliderScript)collider.AddComponent <ColliderScript>();

            if (cs != null)
            {
                cs.SetOnTriggerEnter((MyAction <Collider>)onTriggerEnter);
                cs.SetOnTriggerExit((MyAction <Collider>)onTriggerExit);
                cs.SetOnDestroy((MyAction)(onDestroy));
            }
            if (!m_IsShow)
            {
                MeshRenderer mesh = collider.GetComponent <MeshRenderer>();
                if (mesh != null)
                {
                    GameObject.Destroy(mesh);
                }
            }
            if (m_ColliderType == ColliderType.kBoneBoxCollider)
            {
                Transform child = TriggerUtil.GetChildNodeByName(obj, m_Bone);
                if (child != null)
                {
                    collider.transform.parent = child;
                }
                else
                {
                    LogSystem.Error("not find bone " + m_Bone);
                }
            }
            else
            {
                collider.transform.parent = obj.transform;
            }
            collider.transform.localPosition = m_Position;
            collider.transform.localRotation = m_Eular;
            if (!m_IsAttach)
            {
                collider.transform.parent = null;
            }
            m_Collider = collider;
            GameObject.Destroy(collider, liveTime);
        }
示例#3
0
        private AudioSource CreateNewAudioSource(GameObject obj)
        {
            if (string.IsNullOrEmpty(m_AudioSourceName))
            {
                return(null);
            }
            GameObject audiosource_obj = ResourceSystem.NewObject(
                m_AudioSourceName,
                (m_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.parent   = attach_node;
                    audiosource_obj.transform.rotation = UnityEngine.Quaternion.identity;
                    audiosource_obj.transform.position = UnityEngine.Vector3.zero;
                    if (!m_IsAttach)
                    {
                        audiosource_obj.transform.parent = null;
                    }
                }
                else
                {
                    audiosource_obj.transform.position = obj.transform.TransformPoint(m_Position);
                    if (m_IsAttach)
                    {
                        audiosource_obj.transform.parent = obj.transform;
                    }
                }
            }
            else
            {
                audiosource_obj.transform.position = obj.transform.TransformPoint(m_Position);
                if (m_IsAttach)
                {
                    audiosource_obj.transform.parent = obj.transform;
                }
            }
            return(audiosource_obj.GetComponent <AudioSource>());
        }
示例#4
0
        private void AttachToObject(GameObject obj, GameObject owner)
        {
            Transform parent = TriggerUtil.GetChildNodeByName(owner, m_BoneName);

            if (parent == null)
            {
                parent = owner.transform;
            }
            obj.transform.parent = parent;
            UnityEngine.Vector3 world_pos = parent.TransformPoint(m_Postion);
            TriggerUtil.MoveObjTo(obj, world_pos);
            obj.transform.localRotation = UnityEngine.Quaternion.Euler(m_Rotate);
            if (!m_IsAttach)
            {
                obj.transform.parent = null;
            }
        }
        private void CreateSceneOrBoneCollider(GameObject obj, float liveTime,
                                               object onTriggerEnter,
                                               object onTriggerExit)
        {
            GameObject collider_obj = ResourceSystem.NewObject(m_Prefab, liveTime) as GameObject;

            if (null == collider_obj)
            {
                LogSystem.Error("------create collider failed! " + m_Prefab);
                return;
            }
            m_Collider = collider_obj;
            Component[] transes = collider_obj.GetComponentsInChildren <Transform>();
            for (int i = 0; i < transes.Length; i++)
            {
                transes[i].gameObject.SendMessage("SetOnTriggerEnter", onTriggerEnter, UnityEngine.SendMessageOptions.DontRequireReceiver);
                transes[i].gameObject.SendMessage("SetOnTriggerExit", onTriggerExit, UnityEngine.SendMessageOptions.DontRequireReceiver);
            }

            /*
             * foreach(Transform child in transes) {
             * child.gameObject.SendMessage("SetOnTriggerEnter", onTriggerEnter, SendMessageOptions.DontRequireReceiver);
             * child.gameObject.SendMessage("SetOnTriggerExit", onTriggerExit, SendMessageOptions.DontRequireReceiver);
             * }*/

            if (m_ColliderType == ColliderType.kSceneCollider)
            {
                UnityEngine.Vector3 pos = obj.transform.position + obj.transform.rotation * m_Position;
                collider_obj.transform.position = pos;
            }
            else
            {
                Transform node = TriggerUtil.GetChildNodeByName(obj, m_Bone);
                if (node != null)
                {
                    collider_obj.transform.parent        = node;
                    collider_obj.transform.localPosition = UnityEngine.Vector3.zero;
                    collider_obj.transform.localRotation = UnityEngine.Quaternion.identity;
                    if (!m_IsAttach)
                    {
                        collider_obj.transform.parent = null;
                    }
                }
            }
        }
 public override bool Execute(object sender, SkillInstance instance, long delta, long curSectionTime)
 {
     if (curSectionTime < m_StartTime)
     {
         return(true);
     }
     UnityEngine.GameObject obj = sender as UnityEngine.GameObject;
     if (obj == null)
     {
         return(false);
     }
     UnityEngine.Transform child = TriggerUtil.GetChildNodeByName(obj, m_ChildName);
     if (child != null && child.gameObject != null)
     {
         TriggerUtil.SetObjVisible(child.gameObject, m_IsShow);
     }
     return(false);
 }
示例#7
0
        public static void MoveChildToNode(GameObject obj, string childname, string nodename)
        {
            Transform child = GetChildNodeByName(obj, childname);

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

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

            if (parent == null)
            {
                parent = owner.transform;
            }
            obj.transform.parent = parent;
            UnityEngine.Vector3 world_pos = parent.TransformPoint(m_Postion);
            TriggerUtil.MoveObjTo(obj, world_pos);
            UnityEngine.Vector3 resultrotate = new UnityEngine.Vector3(
                m_Rotate.x + Random.Range(m_RandomRotate.x / -2, m_RandomRotate.x / 2),
                m_Rotate.y + Random.Range(m_RandomRotate.y / -2, m_RandomRotate.y / 2),
                m_Rotate.z + Random.Range(m_RandomRotate.z / -2, m_RandomRotate.z / 2));
            obj.transform.localRotation = UnityEngine.Quaternion.Euler(resultrotate);
            if (!m_IsAttach)
            {
                obj.transform.parent = null;
            }
        }
示例#9
0
 public override bool Execute(object sender, SkillInstance instance, long delta, long curSectionTime)
 {
     if (curSectionTime < m_StartTime)
     {
         return(true);
     }
     UnityEngine.GameObject obj = sender as UnityEngine.GameObject;
     if (obj == null)
     {
         return(false);
     }
     UnityEngine.Transform part_transform = TriggerUtil.GetChildNodeByName(obj, m_PartName);
     if (part_transform == null || part_transform.gameObject == null)
     {
         LogSystem.Debug("----play part anim: not find part {0}", m_PartName);
         return(false);
     }
     UnityEngine.GameObject     part       = part_transform.gameObject;
     UnityEngine.AnimationState anim_state = part.GetComponent <UnityEngine.Animation>()[m_AnimName];
     if (anim_state == null)
     {
         LogSystem.Debug("----play part anim: not find anim {0}", m_AnimName);
         return(false);
     }
     anim_state.speed    = m_AnimSpeed;
     anim_state.wrapMode = m_WrapMode;
     if (m_FadeLength <= 0)
     {
         part.GetComponent <UnityEngine.Animation>().Play(m_AnimName);
     }
     else
     {
         part.GetComponent <UnityEngine.Animation>().CrossFade(m_AnimName, m_FadeLength);
     }
     return(false);
 }