示例#1
0
    public override void SetEntity(ZoneRenderer zoneRenderer, Entity entity)
    {
        base.SetEntity(zoneRenderer, entity);
        var ship = entity as Ship;

        if (ship == null)
        {
            Debug.LogError($"Attempted to assign non-ship entity to {gameObject.name} ship instance prefab!");
            return;
        }
        Ship = ship;
        var drive = ship.GetBehavior <AetherDrive>();

        if (drive != null)
        {
            var particles = Instantiate(UnityHelpers.LoadAsset <ParticleSystem>(drive.DriveData.Particles), transform, false);
            var main      = particles.main;
            main.customSimulationSpace = LocalSpace;
            _aetherDrive = new AetherDriveInstance
            {
                Drive        = drive,
                BaseEmission = particles.emission.rateOverTimeMultiplier,
                Particles    = particles,
                BaseForce    = particles.forceOverLifetime.z.curveMultiplier
            };
        }
        _thrusters = ship.GetBehaviors <Thruster>().Select(thruster =>
        {
            var effectData        = (ThrusterData)thruster.Data;
            var particles         = Instantiate(UnityHelpers.LoadAsset <ParticleSystem>(effectData.ParticlesPrefab), transform, false);
            var particlesShape    = particles.shape;
            var thrusterHardpoint = ThrusterHardpoints
                                    .FirstOrDefault(t => t.name == ship.Hardpoints[thruster.Item.Position.x, thruster.Item.Position.y].Transform);
            particlesShape.meshRenderer = thrusterHardpoint?.Emitter;
            // if (!string.IsNullOrEmpty(thruster.Item.Data.SoundEffectTrigger) && thrusterHardpoint != null)
            // {
            //     AkSoundEngine.RegisterGameObj(thrusterHardpoint.gameObject);
            //     AkSoundEngine.PostEvent(thruster.Item.Data.SoundEffectTrigger, thrusterHardpoint.gameObject);
            // }

            return(new ThrusterInstance
            {
                Thruster = thruster,
                System = particles,
                BaseEmission = particles.emission.rateOverTimeMultiplier,
                MaxParticleCount = 0
            });
        })
                     .ToArray();

        foreach (var particle in _thrusters)
        {
            particle.System.gameObject.SetActive(false);
        }
    }