コード例 #1
0
ファイル: ColliderObject.cs プロジェクト: cnscj/THSTG
        //碰撞检测开始
        public void BeginCollide(Vector3 aPos)
        {
            m_result = m_result ?? new ColliderContent();
            m_result.Clear();

            this.center    = aPos;
            m_result.owner = this;
        }
コード例 #2
0
ファイル: ColliderSystem.cs プロジェクト: cnscj/THSTG
 ///////////////////////////////////
 private void OnHeroCollide(GameEntity owner, ColliderContent content)
 {
     if (owner.hasPlayerData)
     {
         var ownerEntity = content.owner.data as GameEntity;
         ownerEntity.health.blood = 0;
     }
 }
コード例 #3
0
ファイル: ColliderObject.cs プロジェクト: cnscj/THSTG
        /// <summary>
        /// a与b进行碰撞检测
        /// </summary>
        /// <param name="aObj"></param>
        /// <param name="aPos"></param>
        /// <param name="bObj"></param>
        /// <param name="bPos"></param>
        /// <returns></returns>
        public static ColliderContent Collide(ColliderObject aObj, Vector3 aPos, ColliderObject bObj, Vector3 bPos)
        {
            if (aObj == null || bObj == null)
            {
                return(null);
            }

            if (aObj.m_shapes == null || bObj.m_shapes == null)
            {
                return(null);
            }

            {
                aObj.center = aPos;
                bObj.center = bPos;

                ColliderContent result = new ColliderContent();
                result.collisions?.Clear();
                bool isCollided = false;
                foreach (var aShape in aObj.m_shapes)
                {
                    foreach (var bShape in bObj.m_shapes)
                    {
                        if (aShape.Check(bShape))
                        {
                            result.collisions = result.collisions ?? new Dictionary <ColliderObject, List <ColliderShape> >();
                            if (!result.collisions.ContainsKey(bObj))
                            {
                                result.collisions[bObj] = new List <ColliderShape>();
                            }
                            result.collisions[bObj].Add(bShape);

                            isCollided = true;
                        }
                    }
                }

                if (isCollided)
                {
                    result.owner = aObj;
                    return(result);
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: ColliderSystem.cs プロジェクト: cnscj/THSTG
        private void OnHeroBulletCollde(GameEntity owner, ColliderContent content)
        {
            if (owner.isHeroBulletFlag)
            {
                var ownerEntity = content.owner.data as GameEntity;
                foreach (var collision in content.collisions)
                {
                    var otherEntity = collision.Key.data as GameEntity;

                    if (otherEntity.hasHealth)
                    {
                        if (otherEntity.hasMobData)
                        {
                            //TODO:
                            otherEntity.health.blood -= 20;
                            otherEntity.ReplaceComponent(GameComponentsLookup.Health, otherEntity.health);
                        }
                        else if (otherEntity.hasBossData)
                        {
                            //TODO:
                            otherEntity.health.blood -= 20;
                            otherEntity.ReplaceComponent(GameComponentsLookup.Health, otherEntity.health);
                        }
                    }

                    //自己的
                    if (ownerEntity.hasHealth)
                    {
                        //TODO:根据不同子弹处理,如穿甲弹不应该消亡
                        ownerEntity.health.blood = 0;   //子弹直接消亡

                        if (ownerEntity.health.blood <= 0)
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: ColliderSystem.cs プロジェクト: cnscj/THSTG
 private void OnCollide(GameEntity owner, ColliderContent content)
 {
     //碰撞处理
     OnHeroCollide(owner, content);
     OnHeroBulletCollde(owner, content);
 }