Exemple #1
0
        public static void createFluidParticleDef()
        {
            string path = EditorUtility.SaveFilePanel("Save", "Assets/", "ParticleDef", "asset");

            if (path == "")
            {
                return;
            }

            FluidParticleDef asset = ScriptableObject.CreateInstance <FluidParticleDef> ();

            path = FileUtil.GetProjectRelativePath(path);
            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.SaveAssets();
        }
        public FluidParticle createParticle(FluidParticleDef def)
        {
            if (count >= fluidSystemDef.maxCount)
            {
                return(null);
            }
            count++;

            FluidParticle fp = new FluidParticle();

            particleBuffer.Add(fp);
            setParticleFlags(fp, def.flags);
            fp.position            = def.position;
            fp.prevPosition        = def.position;
            fp.velocity            = def.velocity;
            fp.weight              = 0;
            fp.force               = Vector2.zero;
            fp.mass                = def.mass;
            fp.staticPressure      = 0;
            fp.depth               = 0;
            fp.color               = def.color;
            fp.foamColor           = def.foamColor;
            fp.foamWeightThreshold = def.foamWeightThreshold;
            fp.temperature         = def.temperature;
            fp.freezingTemperature = def.freezingTemperature;
            fp.boilingTemperature  = def.boilingTemperature;

            FluidProxy proxy = new FluidProxy();

            proxyBuffer.Add(proxy);
            proxy.fp = fp;

//		bool finiteLifetime = def.lifetime > 0;
//		if (m_expirationTimeBuffer.data || finiteLifetime)
//		{
//			SetParticleLifetime(index, finiteLifetime ? def.lifetime :
//			                    ExpirationTimeToLifetime(
//				-GetQuantizedTimeElapsed()));
//			// Add a reference to the newly added particle to the end of the
//			// queue.
//			m_indexByExpirationTimeBuffer.data[index] = index;
//		}

            return(fp);
        }
        public void createParticlesFillShapeForGroup(FluidFixtureShape shape, FluidParticleDef def)
        {
            float     stride = getParticleStride();
            FluidAABB aabb   = shape.getAABB();

//			Color c = def.color;
            for (float y = Mathf.Floor(aabb.lowerBound.y / stride) * stride; y < aabb.upperBound.y; y += stride)
            {
                for (float x = Mathf.Floor(aabb.lowerBound.x / stride) * stride; x < aabb.upperBound.x; x += stride)
                {
                    Vector2 p = new Vector2(x, y);
                    if (shape.testPoint(p))
                    {
                        def.position = p;
//						def.color = new Color(Random.Range(0,2),Random.Range(0,2),Random.Range(0,2));
                        createParticle(def);
                    }
                }
            }
//			def.color = c;
        }