GameObject CreateObj() { int index = (int)(Random.value * emitobjects.Count); index = Mathf.Clamp(index, 0, emitobjects.Count - 1); GameObject go = (GameObject)GameObject.Instantiate(emitobjects[index], Vector3.zero, Quaternion.identity); go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; go.name = "SmokeObj"; MegaFlowEffect eff = go.GetComponent <MegaFlowEffect>(); if (eff) { eff.vel = vel; eff.source = source; eff.mass = mass; eff.Area = area; eff.scale = scale; eff.framenum = framenum; } return(go); }
GameObject CreateObj() { float w = Random.Range(0.0f, totalweight); int index = 0; for (int i = 0; i < emitobjects.Count; i++) { if (w >= emitobjects[i].tw && w <= emitobjects[i].tw + emitobjects[i].weight) { index = i; break; } } //int index = (int)(Random.value * emitobjects.Count); index = Mathf.Clamp(index, 0, emitobjects.Count - 1); if (emitobjects[index].obj) { GameObject go = (GameObject)GameObject.Instantiate(emitobjects[index].obj.gameObject, Vector3.zero, Quaternion.identity); go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; go.name = "SmokeObj"; MegaFlowEffect eff = go.GetComponent <MegaFlowEffect>(); if (eff) { eff.vel = vel; eff.source = source; eff.mass = mass; eff.Area = area; eff.scale = scale; eff.framenum = framenum; eff.emitindex = index; } return(go); } return(null); }
public override void OnInspectorGUI() { MegaFlowEffect mod = (MegaFlowEffect)target; serializedObject.Update(); #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020 EditorGUIUtility.LookLikeControls(); #endif EditorGUILayout.PropertyField(_prop_source, new GUIContent("Source")); if (mod.source && mod.source.frames.Count > 1) { EditorGUILayout.IntSlider(_prop_framenum, 0, mod.source.frames.Count - 1); mod.SetFrame(mod.framenum); } EditorGUILayout.PropertyField(_prop_scale, new GUIContent("Scale")); EditorGUILayout.PropertyField(_prop_reynolds, new GUIContent("Reynolds")); EditorGUILayout.PropertyField(_prop_density, new GUIContent("Density")); EditorGUILayout.PropertyField(_prop_mass, new GUIContent("Mass")); EditorGUILayout.PropertyField(_prop_area, new GUIContent("Area")); EditorGUILayout.PropertyField(_prop_dt, new GUIContent("dt")); EditorGUILayout.PropertyField(_prop_align, new GUIContent("Align")); EditorGUILayout.PropertyField(_prop_alignrot, new GUIContent("Aligh Rot")); EditorGUILayout.PropertyField(_prop_usegradient, new GUIContent("Use Gradient")); EditorGUILayout.PropertyField(_prop_gradient, new GUIContent("Gradient")); EditorGUILayout.PropertyField(_prop_speedlow, new GUIContent("Speed Low")); EditorGUILayout.PropertyField(_prop_speedhigh, new GUIContent("Speed High")); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } }
void Update() { if (Input.GetMouseButton(0)) { smokepos = transform.position; smokepos.z += Input.GetAxis("Mouse X") * xspeed * 0.02f; smokepos.y += Input.GetAxis("Mouse Y") * yspeed * 0.02f; } if (source && source.frames.Count > 0 && emitobjects.Count > 0) { source.Prepare(); t += Time.deltaTime; if (t > flowrate) { t -= flowrate; for (int i = 0; i < count; i++) { GameObject go = Pop(); if (go) { MegaFlowEffect ef = go.GetComponent <MegaFlowEffect>(); MegaFlowSmokeObjDef def = emitobjects[ef.emitindex]; float z = (Random.value - 0.5f) * width * 2.0f; float y = (Random.value - 0.5f) * height * 2.0f; float x = (Random.value - 0.5f) * 0.95f; Vector3 pos = Vector3.zero; pos.z = z; pos.y = y; pos.x = x; pos += offset; Vector3 scl = Vector3.one; scl.x = Random.Range(def.scalelow.x, def.scalehigh.x); //Random.value + 0.4f) * 2.0f; scl.y = Random.Range(def.scalelow.y, def.scalehigh.y); //Random.value + 0.4f) * 2.0f; scl.z = Random.Range(def.scalelow.z, def.scalehigh.z); //Random.value + 0.4f) * 2.0f; //scl.y = (Random.value + 0.4f) * 2.0f; //scl.z = (Random.value + 0.4f) * 2.0f; Vector3 rotspeed = Vector3.zero; rotspeed.x = Random.Range(def.rotspeedlow.x, def.rotspeedhigh.x); rotspeed.y = Random.Range(def.rotspeedlow.y, def.rotspeedhigh.y); rotspeed.z = Random.Range(def.rotspeedlow.z, def.rotspeedhigh.z); Vector3 srot = Vector3.zero; srot.x = Random.Range(def.rotlow.x, def.rothigh.x); srot.y = Random.Range(def.rotlow.y, def.rothigh.y); srot.z = Random.Range(def.rotlow.z, def.rothigh.z); Quaternion rot = Quaternion.Euler(srot); //Random.rotation; go.transform.position = transform.localToWorldMatrix.MultiplyPoint3x4(pos); go.transform.localScale = scl; ef.vel = transform.right * vel.x; ef.mass = mass; ef.Gravity = Gravity; ef.scale = scale; ef.framenum = framenum; ef.rot = rot.eulerAngles; ef.rotspeed = rotspeed; //Random.insideUnitSphere * 180.0f; Renderer rend = go.GetComponent <Renderer>(); if (cols.Count > 0) { if (colindex >= cols.Count) { colindex = 0; } //Renderer rend = go.GetComponent<Renderer>(); if (rend && rend.sharedMaterial) { rend.sharedMaterial.color = cols[colindex] * 0.5f; } colindex++; } rend.enabled = false; MegaFlowSmokeObj sobj = new MegaFlowSmokeObj(); sobj.obj = go; sobj.lifetime = lifetime; objects.Add(sobj); } } } } for (int i = 0; i < objects.Count; i++) { objects[i].lifetime -= Time.deltaTime; if (objects[i].lifetime < 0.0f) { GameObject sobj = objects[i].obj; Push(sobj); objects.RemoveAt(i); i--; } } }