/// <summary>
        /// 启动本地代码
        /// </summary>
        public void LaunchLocal()
        {
            var types = Assembly.GetExecutingAssembly().GetTypes();


            var istartType = typeof(IGameStart);

            foreach (var t in types)
            {
                if (t.IsClass && t.GetInterface("IGameStart") != null)
                {
                    var attr = t.GetCustomAttribute(typeof(GameStartAtrribute), false);
                    if (attr != null)
                    {
                        var gs = Activator.CreateInstance(t) as IGameStart;

                        //注册
                        gs.Start();

                        BDLauncher.OnUpdate     += gs.Update;
                        BDLauncher.OnLateUpdate += gs.LateUpdate;
                    }
                }
            }
        }
Beispiel #2
0
 private void Update()
 {
     timer += Time.deltaTime;
     if (timer <= animaTime && timer >= 0)
     {
         OnLife?.Invoke(timer / animaTime);
     }
     else if (timer > Cycle)
     {
         timer = 0;
     }
 }
Beispiel #3
0
        private void Start()
        {
            if (Cycle < animaTime)
            {
                Cycle = animaTime;
            }
            image          = GetComponent <Image>();
            spriteRenderer = GetComponent <SpriteRenderer>();
            defcolor       = spriteRenderer ? spriteRenderer.color : image.color;

            if (spriteRenderer)
            {
                OnLife.AddListener(x => spriteRenderer.color = defcolor * gradient.Evaluate(x));
            }
            else
            {
                OnLife.AddListener(x => image.color = defcolor * gradient.Evaluate(x));
            }
            OnLife?.Invoke(0);
        }
        private void UpdateParticlesCreation()
        {
            if (!Enabled.GetValue <bool>())
            {
                return;
            }

            //particles to create in this update
            if (!m_effect.IsStopped)
            {
                float lodBirth = 1.0f;
                if (GetEffect().EnableLods)
                {
                    LODBirth.GetInterpolatedValue <float>(GetEffect().Distance, out lodBirth);
                }

                Birth.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out m_birthRate);
                m_birthRate *=
                    MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS
                    * (EnableCustomBirth ? m_effect.UserBirthMultiplier : 1.0f)
                    * MyParticlesManager.BirthMultiplierOverall
                    * lodBirth;

                m_particlesToCreate += m_birthRate;
            }

            //If speed of effect is too high, there would be created bunches
            //of particles each frame. By interpolating position, we create
            //seamless particle creation.
            Vector3 positionDelta = Vector3.Zero;

            if (!m_lastEffectPosition.HasValue)
            {
                m_lastEffectPosition = EffectMatrix.Translation;
            }

            //Position delta interpolates particle position at fast flying objects, dont do that while motion inheritance
            if (m_particlesToCreate > 1.0f && !m_effect.CalculateDeltaMatrix)
            {
                positionDelta = (EffectMatrix.Translation - m_lastEffectPosition.Value) / (int)m_particlesToCreate;
            }

            //VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("CreateParticle");


            using (ParticlesLock.AcquireExclusiveUsing())
            {
                int maxParticles = 40;
                while (m_particlesToCreate >= 1.0f && maxParticles-- > 0)
                {
                    if (m_effect.CalculateDeltaMatrix)
                    {
                        CreateParticle(EffectMatrix.Translation);
                    }
                    else
                    {
                        CreateParticle(m_lastEffectPosition.Value + positionDelta * (int)m_particlesToCreate);
                    }

                    m_particlesToCreate -= 1.0f;
                }
            }

            //   VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("OnLife");

            if (OnLife.GetValue <int>() != -1)
            {
                MyParticleGeneration inheritedGeneration = GetInheritedGeneration(OnLife.GetValue <int>());

                if (inheritedGeneration == null)
                {
                    OnLife.SetValue(-1);
                }
                else
                {
                    inheritedGeneration.IsInherited = true;

                    float particlesToCreate = inheritedGeneration.m_particlesToCreate;

                    using (ParticlesLock.AcquireSharedUsing())
                    {
                        foreach (MyAnimatedParticle particle in m_particles)
                        {
                            inheritedGeneration.m_particlesToCreate = particlesToCreate;
                            inheritedGeneration.EffectMatrix        = MatrixD.CreateWorld(particle.ActualPosition, (Vector3D)particle.Velocity, Vector3D.Cross(Vector3D.Left, particle.Velocity));
                            inheritedGeneration.UpdateParticlesCreation();
                        }
                    }
                }
            }

            //  VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            m_lastEffectPosition = EffectMatrix.Translation;
        }
        public void Init()
        {
            System.Diagnostics.Debug.Assert(Birth == null);

            AddProperty(MyGenerationPropertiesEnum.Birth, new MyAnimatedPropertyFloat("Birth"));
            AddProperty(MyGenerationPropertiesEnum.BirthVar, new MyConstPropertyFloat("Birth var"));

            AddProperty(MyGenerationPropertiesEnum.Life, new MyAnimatedPropertyFloat("Life"));
            AddProperty(MyGenerationPropertiesEnum.LifeVar, new MyConstPropertyFloat("Life var"));

            AddProperty(MyGenerationPropertiesEnum.Velocity, new MyAnimatedPropertyVector3("Velocity"));
            AddProperty(MyGenerationPropertiesEnum.VelocityDir, new MyConstPropertyEnum("Velocity dir", typeof(MyVelocityDirEnum), s_velocityDirStrings));

            AddProperty(MyGenerationPropertiesEnum.Angle, new MyAnimatedPropertyFloat("Angle"));
            AddProperty(MyGenerationPropertiesEnum.AngleVar, new MyConstPropertyFloat("Angle var"));

            AddProperty(MyGenerationPropertiesEnum.RotationSpeed, new MyAnimatedPropertyFloat("Rotation speed"));
            AddProperty(MyGenerationPropertiesEnum.RotationSpeedVar, new MyConstPropertyFloat("Rotation speed var"));

            AddProperty(MyGenerationPropertiesEnum.Radius, new MyAnimatedProperty2DFloat("Radius"));
            AddProperty(MyGenerationPropertiesEnum.RadiusVar, new MyAnimatedPropertyFloat("Radius var"));

            AddProperty(MyGenerationPropertiesEnum.Color, new MyAnimatedProperty2DVector4("Color"));
            AddProperty(MyGenerationPropertiesEnum.ColorVar, new MyAnimatedPropertyFloat("Color var"));

            AddProperty(MyGenerationPropertiesEnum.Material, new MyAnimatedProperty2DTransparentMaterial("Material", MyTransparentMaterialInterpolator.Switch));

            AddProperty(MyGenerationPropertiesEnum.ParticleType, new MyConstPropertyEnum("Particle type", typeof(MyParticleTypeEnum), s_particleTypeStrings));

            AddProperty(MyGenerationPropertiesEnum.Thickness, new MyAnimatedPropertyFloat("Thickness"));

            AddProperty(MyGenerationPropertiesEnum.Enabled, new MyConstPropertyBool("Enabled"));
            Enabled.SetValue(true);

            AddProperty(MyGenerationPropertiesEnum.BlendTextures, new MyConstPropertyBool("Blend textures"));
            BlendTextures.SetValue(true);

            AddProperty(MyGenerationPropertiesEnum.EnableCustomRadius, new MyConstPropertyBool("Enable custom radius"));
            AddProperty(MyGenerationPropertiesEnum.EnableCustomVelocity, new MyConstPropertyBool("Enable custom velocity"));
            AddProperty(MyGenerationPropertiesEnum.EnableCustomBirth, new MyConstPropertyBool("Enable custom birth"));

            AddProperty(MyGenerationPropertiesEnum.OnDie, new MyConstPropertyGenerationIndex("OnDie"));
            OnDie.SetValue(-1);
            AddProperty(MyGenerationPropertiesEnum.OnLife, new MyConstPropertyGenerationIndex("OnLife"));
            OnLife.SetValue(-1);

            AddProperty(MyGenerationPropertiesEnum.LODBirth, new MyAnimatedPropertyFloat("LODBirth"));
            AddProperty(MyGenerationPropertiesEnum.LODRadius, new MyAnimatedPropertyFloat("LODRadius"));

            AddProperty(MyGenerationPropertiesEnum.MotionInheritance, new MyAnimatedPropertyFloat("Motion inheritance"));

            AddProperty(MyGenerationPropertiesEnum.UseLayerSorting, new MyConstPropertyBool("Use layer sorting"));
            AddProperty(MyGenerationPropertiesEnum.SortLayer, new MyConstPropertyInt("Sort layer"));
            AddProperty(MyGenerationPropertiesEnum.AlphaAnisotropic, new MyConstPropertyBool("Alpha anisotropic"));

            AddProperty(MyGenerationPropertiesEnum.Gravity, new MyConstPropertyFloat("Gravity"));

            Thickness.AddKey(0, 1.0f);

            LODBirth.AddKey(0, 1.0f);
            LODRadius.AddKey(0, 1.0f);

            UseLayerSorting.SetValue(false);
            SortLayer.SetValue(-1);

            m_emitter.Init();
        }