EllanJiang / StarForce

This is a demo made with Game Framework.
https://GameFramework.cn
MIT License
880 stars 467 forks source link

Entity 不继承 EntityLogic 类,而是使用 m_EntityLogic 成员之后,旧代码中直接通过 Entity 访问 EntityLogic 中的成员是错误的 #22

Closed CheapMeow closed 2 years ago

CheapMeow commented 2 years ago

比如 Assets\GameMain\Scripts\HPBar\HPBarItem.cs 中

public bool Refresh()
        {
            if (m_CachedCanvasGroup.alpha <= 0f)
            {
                return false;
            }

            if (m_Owner != null && Owner.Available && Owner.Id == m_OwnerId)
            {
                Vector3 worldPosition = m_Owner.CachedTransform.position + Vector3.forward;
                Vector3 screenPosition = GameEntry.Scene.MainCamera.WorldToScreenPoint(worldPosition);

                Vector2 position;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)m_ParentCanvas.transform, screenPosition,
                    m_ParentCanvas.worldCamera, out position))
                {
                    m_CachedTransform.localPosition = position;
                }
            }

            return true;
        }

Owner.Available 应改为 Owner.Logic.Available m_Owner.CachedTransform.position 应改为 m_Owner.Logic.CachedTransform.position

在 Assets\GameMain\Scripts\HPBar\HPBarItem.cs Assets\GameMain\Scripts\Utility\AIUtility.cs Assets\GameMain\Scripts\Entity\EntityExtension.cs Assets\GameMain\Scripts\Sound\SoundExtension.cs 中发现了这个问题,但我没有把所有文件用过一遍,所以不一定全hhh

同时另外一个问题是 不能从 'UnityGameFramework.Runtime.EntityLogic' 类型转换到 'UnityGameFramework.Runtime.Entity'

比如 Assets\GameMain\Scripts\Entity\EntityExtension.cs 中

public static Entity GetGameEntity(this EntityComponent entityComponent, int entityId)
        {
            UnityGameFramework.Runtime.Entity entity = entityComponent.GetEntity(entityId);
            if (entity == null)
            {
                return null;
            }

            return (Entity)entity.Logic;
        }
CheapMeow commented 2 years ago

哦对不起是我错了,继续看下去才发现,这个 Entity 是 Assets\GameMain\Scripts\Entity\EntityLogic\Entity.cs 新增的,覆盖了 Assets\GameFramework\UnityGameFramework-b2d2ef63517d2cab5f0def57e691a2d794b6a7f5\Scripts\Runtime\Entity\Entity.cs 中的 Entity 我是想着一遍看代码一遍拼,之前并没有创建这个文件,所以我没发现 丢人了丢人了