示例#1
0
    public static void InitIfNeeded()
    {
        if (s_init)
        {
            return;
        }

        // For a collision detection to happen between two filters, their 'BelongsTo' and 'CollidesWith' must mention each other

        Physics.CharacterFilter.Data = CollisionFilter.FromLayer(Physics.LAYER_CHARACTER);

        Physics.CollideWithTerrainFilter.Data = new CollisionFilter()
        {
            BelongsTo    = ~(uint)0,
            CollidesWith = CollisionFilter.CreateMask(Physics.LAYER_TERRAIN)
        };
        Physics.CollideWithCharactersAndTerrainFilter.Data = new CollisionFilter()
        {
            BelongsTo    = ~(uint)0,
            CollidesWith = CollisionFilter.CreateMask(Physics.LAYER_TERRAIN, Physics.LAYER_CHARACTER)
        };
        Physics.CollideWithCharactersFilter.Data = new CollisionFilter()
        {
            BelongsTo    = ~(uint)0,
            CollidesWith = CollisionFilter.CreateMask(Physics.LAYER_CHARACTER)
        };

        s_init = true;
    }
    protected override void OnCreate()
    {
        base.OnCreate();

        _tileColliderArchetype = EntityManager.CreateArchetype(
            typeof(TileColliderTag),
            typeof(FixTranslation),
            typeof(PhysicsColliderBlob));

        // Create tile collider
        BoxGeometry boxGeometry = new BoxGeometry()
        {
            Size = float2(1, 1)
        };
        PolygonGeometry triangleGeometry = new PolygonGeometry()
        {
            Vertices = new NativeArray <float2>(new float2[] {
                new float2(-.5f, -.5f),
                new float2(-.5f, .5f),
                new float2(.5f, -0.5f),
            }, Allocator.Temp)
        };
        CollisionFilter filter   = CollisionFilter.FromLayer(SimulationGameConstants.Physics.LAYER_TERRAIN);
        PhysicsMaterial material = PhysicsMaterial.Default;

        _fullTileCollider   = Collider.Create(boxGeometry, filter, material);
        _cornerTileCollider = Collider.Create(triangleGeometry);
    }
示例#3
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (HasProxy)
        {
            dstManager.AddComponentData <HealthProxy>(entity, conversionSystem.GetPrimaryEntity(Proxy.gameObject));
        }
        else
        {
            dstManager.AddComponentData <Health>(entity, (fix)(StartAtMax ? MaxValue : StartValue));
            dstManager.AddComponentData <MinimumFix <Health> >(entity, (fix)0);
            dstManager.AddComponentData <MaximumFix <Health> >(entity, (fix)MaxValue);
            dstManager.AddComponentData <HealthRechargeRate>(entity, (fix)RechargeRate);
            dstManager.AddComponentData <HealthRechargeCooldown>(entity, (fix)RechargeCooldown);
            dstManager.AddComponentData <HealthLastHitTime>(entity, fix.MinValue);

            if (DestroyOnDeath)
            {
                dstManager.AddComponent <DestroyOnDeath>(entity);
            }

            if (ShowTerrainOnlyColliderIfDead && TerrainOnlyColliderIfDead)
            {
                var normalCollider = dstManager.GetComponentData <PhysicsColliderBlob>(entity).Collider;

                if (!dstManager.TryGetComponentData <ActorColliderRefs>(entity, out var actorColliderRefs))
                {
                    actorColliderRefs = new ActorColliderRefs(normalCollider);
                }

                // duplicate collider, but with alternate layer
                var deadCollider = BlobAssetReference <Collider> .Create(normalCollider.Value);

                deadCollider.Value.Filter = CollisionFilter.FromLayer(SimulationGameConstants.Physics.LAYER_CORPSES);

                actorColliderRefs.DeadCollider = deadCollider;

                dstManager.SetOrAddComponentData(entity, actorColliderRefs);
            }
        }
    }