Exemplo n.º 1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="drawer">パーティクルを描画するためのシェーダー</param>
		/// <param name="device"></param>
		/// <param name="tex">パーティクルのテクスチャ</param>
		/// <param name="number">パーティクル最大数</param>
		public ParticleEngine(Effect drawer, GraphicsDevice device, Texture2D tex, ushort number,
			ParticleMode mode, Matrix projection, Vector2 fieldSize)
			:base(tex, number)
		{
			Device = device;
			
			//int[] x = { -1, -1, 1, 1 };
			//int[] y = { 1, -1, -1, 1 };
			
			VertexDataBuffer = new DynamicVertexBuffer(device, typeof(ParticleVertex), ParticleNum * 1, BufferUsage.WriteOnly);

		
			IndexVertexBuffer = new VertexBuffer(device, typeof(ParticleIndexVertex), indexVertex.Length, BufferUsage.WriteOnly);
			IndexVertexBuffer.SetData(indexVertex);

			short[] index = new short[] { 0, 1, 2, 0, 2, 3 };
			Index = new IndexBuffer(device, IndexElementSize.SixteenBits, index.Length, BufferUsage.WriteOnly);
			Index.SetData(index);
			
			Drawer = drawer;
			InitEffectParam();
			Mode = mode;
			Projection = projection;
			FieldSize = fieldSize;
			BlendColor = Vector4.One;
			Enable = true;

			SetVertex();//初期化
			bind = new VertexBufferBinding(VertexDataBuffer, 0, 1);
		}
Exemplo n.º 2
0
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            clickPos                = Input.mousePosition;
            clickPosWorldPos        = cam.ScreenToWorldPoint(new Vector3(clickPos.x, clickPos.y, cam.nearClipPlane));
            this.transform.position = clickPosWorldPos;
            Debug.Log("clickPosWoldPos: " + clickPosWorldPos);
            myMode = HorizCheck(clickPosWorldPos.x);
            Debug.Log("myMode: " + myMode);
            PS.Emit(1);
        }

        switch (myMode)
        {
        case ParticleMode.cone:
            myShape.enabled   = true;
            myShape.shapeType = ParticleSystemShapeType.Cone;
            myColor.enabled   = false;
            break;

        case ParticleMode.donut:
            myShape.enabled   = true;
            myShape.shapeType = ParticleSystemShapeType.Donut;
            myColor.enabled   = true;
            grad.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.blue, 0.0f), new GradientColorKey(Color.red, 1.0f) },
                         new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) });
            myColor.color = grad;
            break;

        case ParticleMode.line:
            myShape.enabled = false;
            myColor.enabled = false;
            break;

        case ParticleMode.grow:
            mySize.enabled        = true;
            mySize.sizeMultiplier = 10f;
            break;

        case ParticleMode.shrink:
            mySize.enabled = true;
            mySize.size    = 0.5f;
            break;

        case ParticleMode.spin:
            myRot.enabled     = true;
            myRot.xMultiplier = 10f;
            break;

        default:
            break;
        }
    }
                // ...

                public void setToInstancedParticleMode(bool set)
                {
                    if (set)
                    {
                        perpetualParticleSystems.gameObject.SetActive(false);
                        instantiatedParticleSystems.gameObject.SetActive(true);

                        particleSpawnInstructionText.gameObject.SetActive(true);

                        particleMode = ParticleMode.instanced;

                        updateCurrentParticleSystemNameText();
                    }
                }
Exemplo n.º 4
0
                // ...

                public void setToInstancedParticleMode(bool set)
                {
                    if (set)
                    {
                        loopingParticleSystems.gameObject.SetActive(false);
                        oneshotParticleSystems.gameObject.SetActive(true);

                        particleSpawnInstructionText.gameObject.SetActive(true);

                        particleMode = ParticleMode.oneshot;

                        updateCurrentParticleSystemNameText();
                    }
                }
Exemplo n.º 5
0
        public virtual void SpawnParticle(ParticleMode shape, Vector2 point, float scale, Color color)
        {
            Vector3 uv           = WorldToTexturePosition(ref point);
            int     particleSize = (int)(scaleMultiplier * scale * 40f);

            if (shape == ParticleMode.Square)
            {
                BitmapDraw.DrawFilledSquare(texture, (int)uv.x, (int)uv.y, particleSize, color);
            }
            else
            {
                BitmapDraw.DrawFilledCircle(texture, (int)uv.x, (int)uv.y, particleSize, color);
            }
            isDirty = true;
        }
Exemplo n.º 6
0
                // ...

                public void setToPerpetualParticleMode(bool set)
                {
                    if (set)
                    {
                        oneshotParticleSystems.clear();

                        loopingParticleSystems.gameObject.SetActive(true);
                        oneshotParticleSystems.gameObject.SetActive(false);

                        particleSpawnInstructionText.gameObject.SetActive(false);

                        particleMode = ParticleMode.looping;

                        updateCurrentParticleSystemNameText();
                    }
                }
Exemplo n.º 7
0
        public ScriptEffectManager(ScriptEngine.ScriptManager script, GraphicsDevice device, Effect effect,
			ParticleMode mode, Matrix projection, Vector2 filedSize,
			IEnumerable<ParticleManagerInitializer> particle, Random rnd)
        {
            viewport = new Viewport(0, 0, (int)filedSize.X, (int)filedSize.Y);
            Script = script;
            effects = new LinkedPoolObjectBaseManager<ScriptEffect>();
            if (rnd == null)
            {
                rnd = new System.Random();//乱数のインスタンスを指定しないときは勝手に作る
            }
            Random = rnd;
            particles = particle.Select(p =>
                {
                    if (p.Disabled)
                    {
                        return null;
                    }
                    else
                    {
                        return new ParticleEngine(effect, device, p.Texture, p.Number, mode, projection, filedSize)
                            {
                                BlendColor = p.color,
                                BlendMode = p.Blend,
                                Layer = p.Layer
                            };
                    }
                }).ToArray();
            textureTable = particle.Select(p => p.Name).ToArray();
            Device = device;
            particleEffect = effect;
            Projection = projection;
            FieldSize = filedSize;
            this.mode = mode;
            effectParams = new EffectParameter[Enum.GetValues(typeof(EffectParam)).Length];
            Action<EffectParam, string> setParam = (p, name) => effectParams[(int)p] = particleEffect.Parameters[name];
            setParam(EffectParam.Projection, "Projection");
            setParam(EffectParam.ViewProjection, "ViewProjection");
            setParam(EffectParam.Offset, "Offset");
            setParam(EffectParam.Time, "Time");
            setParam(EffectParam.TargetSize, "TargetSize");
        }
Exemplo n.º 8
0
        /// <summary>
        /// 2D用Projection
        /// </summary>
        /// <param name="script"></param>
        /// <param name="device"></param>
        /// <param name="effect">描画に使用するシェーダ</param>
        /// <param name="mode"></param>
        /// <param name="width">画面幅(レンダリングターゲットの幅)</param>
        /// <param name="height">画面高さ(レンダリングターゲットの高さ)</param>
        /// <param name="particle">使用する各パーティクルエンジンの設定</param>
        /// <param name="rnd">エフェクトから乱数を使うときの乱数発生器。特に指定しないならnull</param>
        public ScriptEffectManager(ScriptEngine.ScriptManager script, GraphicsDevice device, Effect effect,
			ParticleMode mode, float width, float height, IEnumerable<ParticleManagerInitializer> particle, Random rnd)
            : this(script, device, effect, mode, GetDefault2DProjection(width, height), new Vector2(width, height), particle, rnd)
        {
        }
Exemplo n.º 9
0
    public void Shoot(FiringPoint Point, int Index)
    {
        EmmisionMode Emmision  = Point.Emmision;
        ShotMode     Shooting  = Point.Shooting;
        ParticleMode Particles = Point.Particles;
        SoundMode    Sound     = Point.Sound;

        Vector3 ShootPosition = this.transform.position + this.transform.TransformDirection(Vector3.forward);

        switch (Emmision.Positioning)
        {
        case ShotPositioning.Direct:
            ShootPosition = this.transform.position + this.transform.forward;
            break;

        case ShotPositioning.Weapon1:
            ShootPosition = Weapons.ElementAt(0).position + this.transform.forward;
            break;

        case ShotPositioning.Weapon2:
            ShootPosition = Weapons.ElementAt(1).position + this.transform.forward;
            break;

        case ShotPositioning.Split:
            int CurrentWeapon = SplitFiringSelection.ElementAt(Index);
            ShootPosition = Weapons.ElementAt(CurrentWeapon).position + this.transform.forward;
            switch (CurrentWeapon)
            {
            case 0:
                SplitFiringSelection[Index] = 1;
                break;

            case 1:
                SplitFiringSelection[Index] = 0;
                break;
            }
            break;
        }
        if (Emmision.EmmisionRandomOffset != Vector3.zero && Emmision.EmmisionRandomOffset != null)
        {
            ShootPosition.x += Random.Range(-Emmision.EmmisionRandomOffset.x, Emmision.EmmisionRandomOffset.x);
            ShootPosition.y += Random.Range(-Emmision.EmmisionRandomOffset.y, Emmision.EmmisionRandomOffset.y);
            ShootPosition.z += Random.Range(-Emmision.EmmisionRandomOffset.z, Emmision.EmmisionRandomOffset.x);
        }

        Vector3    ParticlesPosition = Emmision.EmmisionOffset + Particles.Position;
        Quaternion ShootRotation     = this.transform.rotation * Quaternion.Euler(Emmision.RotationOffset);

        if (Particles.HasParticles == true)
        {
            Vector3 ParticleColor = new Vector3(Particles.Coloring.r, Particles.Coloring.g, Particles.Coloring.b);
            PhotonNetwork.RPC(this.photonView, "PlayParticles", RpcTarget.AllBuffered, false, ParticleColor,
                              Particles.Prefab, Particles.Type, ParticlesPosition, ShootRotation, Index, Particles.Size);
        }


        if (Sound != null && Time.time > NextTimeToPlaySound)
        {
            AudioSource Source = this.GetComponent <AudioSource>();
            Source.PlayOneShot(Sound.Clip, Sound.Volume);
            NextTimeToPlaySound = Time.time + Sound.Refresh;
        }

        for (int i = 0; i < Shooting.ShotCount; i++)
        {
            /*
             * EmmisionType EmitType = Emmision.Type;
             * RaycastHit Hit;
             * var dir = Quaternion.Euler(Emmision.RotationOffset) * this.transform.forward;
             * Debug.DrawRay(ShootPosition, dir, Color.cyan);
             *
             * switch (EmitType)
             * {
             *  case EmmisionType.Line:
             *      if (Physics.Raycast(ShootPosition, dir, out Hit, Shooting.Range, ~(1 << LayerMask.NameToLayer("Pieces"))))
             *      {
             *          Damage(Hit, Shooting, Index);
             *      }
             *      break;
             *  case EmmisionType.Tube:
             *      if (Physics.SphereCast(ShootPosition, Emmision.EmmisionSize, dir, out Hit, Shooting.Range, ~(1 << LayerMask.NameToLayer("Pieces"))))
             *      {
             *          Damage(Hit, Shooting, Index);
             *      }
             *
             * break;
             * }
             */

            //Quaternion dir = Quaternion.Euler(Quaternion.Euler(Emmision.RotationOffset) * this.transform.forward);
            Quaternion dir        = this.transform.rotation * Quaternion.Euler(Emmision.RotationOffset);
            GameObject projectile = PhotonNetwork.Instantiate(Emmision.Prefab, ShootPosition, dir);
            projectile.layer = LayerMask.NameToLayer("Bullets");
            projectile.transform.SetParent(GameObject.Find("TempStorage").transform);
            projectile.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
            PhotonNetwork.RPC(photonView, "SetProjectile", RpcTarget.AllBuffered, false, projectile.gameObject.GetPhotonView().ViewID,
                              this.gameObject.GetPhotonView().ViewID, new Vector3(Particles.ProjectileColor.r, Particles.ProjectileColor.g, Particles.ProjectileColor.b));
            projectile.GetComponent <Renderer>().sharedMaterial.color = Particles.ProjectileColor;

            Bullet b = projectile.AddComponent <Bullet>();
            b.shooter  = this.transform;
            b.Shooting = Shooting;
            b.index    = Index;
            b.speed    = Shooting.Speed;
            b.maxRange = Shooting.Range;
            b.force    = Shooting.Force;
            b.Fire();
        }

        NextTimesToFire[Index] = Time.time + (1 / Shooting.FireRate) + Shooting.Recharge;
        if (NextTimesToFire[Index] == Mathf.Infinity || NextTimesToFire[Index] == Mathf.NegativeInfinity)
        {
            NextTimesToFire[Index] = 0;
        }
    }
Exemplo n.º 10
0
                // ...
                public void setToInstancedParticleMode(bool set)
                {
                    if (set)
                    {
                        perpetualParticleSystems.gameObject.SetActive(false);
                        instantiatedParticleSystems.gameObject.SetActive(true);

                        particleSpawnInstructionText.gameObject.SetActive(true);

                        particleMode = ParticleMode.instanced;

                        updateCurrentParticleSystemNameText();
                    }
                }
Exemplo n.º 11
0
        public override void OnOSC(string address, List <object> data)
        {
            switch (address)
            {
            case "/city_voxel/particle_mode":
                particleMode = (ParticleMode)OSCUtils.GetIValue(data);
                break;

            case "/city_voxel/flow":
                FlowRandom(OSCUtils.GetFValue(data, 1, 0.1f));
                break;

            case "/city_voxel/voxel_mode":
                voxelMode = (CityVoxelMode)OSCUtils.GetIValue(data);
                break;

            case "/city_voxel/level":
                level = OSCUtils.GetIValue(data);
                break;

            case "/city_voxel/size":
                size = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/edge":
                edge = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/capture":
                useCapture = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/pack":
                usePack = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/resolution":
                gridResolution = OSCUtils.GetIValue(data);
                break;

            case "/city_voxel/resolution/reactive":
                resolutionReactive = OSCUtils.GetBoolFlag(data);
                break;

            case "/city_voxel/tile/reset":
                ResetTileOffset();
                break;

            case "/city_voxel/tile/speed/x":
                tileSpeedX = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/tile/speed/y":
                tileSpeedY = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/tile/reactive":
                tileReactive = OSCUtils.GetBoolFlag(data);
                break;

            case "/city_voxel/emission/use":
                useEmission = OSCUtils.GetBoolFlag(data);
                break;

            case "/city_voxel/emission/rate":
                emissionRate = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/emission/speed":
                emissionSpeed = OSCUtils.GetFValue(data);
                break;

            case "/city_voxel/emission/random":
                emissionRandom = OSCUtils.GetFValue(data);
                break;
            }
        }