void Start() { if ( water ) { dynamicwater = (MegaDynamicRipple)water.GetComponent<MegaDynamicRipple>(); } }
void Start() { if (water) { dynamicwater = (MegaDynamicRipple)water.GetComponent <MegaDynamicRipple>(); } }
void Start() { rbody = GetComponent <Rigidbody>(); if (water) { dynamicwater = (MegaDynamicRipple)water.GetComponent <MegaDynamicRipple>(); } }
void Start() { rbody = GetComponent<Rigidbody>(); if ( water ) { dynamicwater = (MegaDynamicRipple)water.GetComponent<MegaDynamicRipple>(); } }
public override bool Inspector() { MegaDynamicRipple mod = (MegaDynamicRipple)target; EditorGUIUtility.LookLikeControls(); bool dirty = false; mod.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis); mod.cols = EditorGUILayout.IntField("Columns", mod.cols); if (mod.cols < 1) { mod.cols = 1; } mod.rows = EditorGUILayout.IntField("Rows", mod.rows); if (mod.rows < 1) { mod.rows = 1; } if (GUI.changed) { dirty = true; } mod.damping = EditorGUILayout.Slider("Damping", mod.damping, 0.0f, 1.0f); mod.inputdamp = EditorGUILayout.Slider("Input Damping", mod.inputdamp, 0.0f, 1.0f); mod.scale = EditorGUILayout.Slider("Scale", mod.scale, 0.0f, 4.0f); mod.speed = EditorGUILayout.Slider("Speed", mod.speed, 0.0f, 0.5f); mod.Force = EditorGUILayout.FloatField("Force", mod.Force); mod.InputForce = EditorGUILayout.FloatField("InputForce", mod.InputForce); mod.Obstructions = EditorGUILayout.Toggle("Obstructions", mod.Obstructions); mod.DropsPerSec = EditorGUILayout.FloatField("Drops Per Sec", mod.DropsPerSec); if (mod.DropsPerSec < 0.0f) { mod.DropsPerSec = 0.0f; } if (dirty) { //mod.ResetGrid(); } if (GUILayout.Button("Reset Physics")) { mod.ResetGrid(); } return(false); }
/// <summary> /// Provides initialization. /// </summary> private void Start() { if ( water ) { dynamicwater = (MegaDynamicRipple)water.GetComponent<MegaDynamicRipple>(); } rbody = GetComponent<Rigidbody>(); mycollider = GetComponent<Collider>(); if ( dynamicwater ) dwtrans = dynamicwater.transform; else { Debug.LogWarning(string.Format("[Buoyancy.cs] No Dynamic Ripple modifier found", name)); } //forces = new List<Vector3[]>(); // For drawing force gizmos // Store original rotation and position var originalRotation = transform.rotation; var originalPosition = transform.position; transform.rotation = Quaternion.identity; transform.position = Vector3.zero; // The object must have a collider if ( mycollider == null ) { mycollider = gameObject.AddComponent<MeshCollider>(); Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no collider. MeshCollider has been added.", name)); } isMeshCollider = GetComponent<MeshCollider>() != null; var bounds = mycollider.bounds; if ( bounds.size.x < bounds.size.y ) { voxelHalfHeight = bounds.size.x; } else { voxelHalfHeight = bounds.size.y; } if ( bounds.size.z < voxelHalfHeight ) { voxelHalfHeight = bounds.size.z; } voxelHalfHeight /= 2.0f * slicesPerAxis; // The object must have a RidigBody if ( rbody == null ) { rbody = gameObject.AddComponent<Rigidbody>(); Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no Rigidbody. Rigidbody has been added.", name)); } rbody.centerOfMass = new Vector3(0, -bounds.extents.y * 0f, 0) + transform.InverseTransformPoint(bounds.center); voxels = SliceIntoVoxels(isMeshCollider && isConcave); // Restore original rotation and position transform.rotation = originalRotation; transform.position = originalPosition; float volume = rbody.mass / density; WeldPoints(voxels, voxelsLimit); float archimedesForceMagnitude = WATER_DENSITY * Mathf.Abs(Physics.gravity.y) * volume; localArchimedesForce = new Vector3(0, archimedesForceMagnitude, 0) / voxels.Count; Debug.Log(string.Format("[Buoyancy.cs] Name=\"{0}\" volume={1:0.0}, mass={2:0.0}, density={3:0.0}", name, volume, rbody.mass, density)); }
public override bool Inspector() { MegaDynamicRipple mod = (MegaDynamicRipple)target; #if !UNITY_5 && !UNITY_2017 EditorGUIUtility.LookLikeControls(); #endif bool dirty = false; mod.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis); mod.cols = EditorGUILayout.IntField("Columns", mod.cols); if (mod.cols < 1) { mod.cols = 1; } mod.rows = EditorGUILayout.IntField("Rows", mod.rows); if (mod.rows < 1) { mod.rows = 1; } if (GUI.changed) { dirty = true; } mod.damping = EditorGUILayout.Slider("Damping", mod.damping, 0.0f, 1.0f); mod.inputdamp = EditorGUILayout.Slider("Input Damping", mod.inputdamp, 0.0f, 1.0f); mod.scale = EditorGUILayout.Slider("Scale", mod.scale, 0.0f, 4.0f); mod.speed = EditorGUILayout.Slider("Speed", mod.speed, 0.0f, 0.5f); mod.Force = EditorGUILayout.FloatField("Force", mod.Force); mod.InputForce = EditorGUILayout.FloatField("InputForce", mod.InputForce); mod.Obstructions = EditorGUILayout.BeginToggleGroup("Obstructions", mod.Obstructions); bool bilin = EditorGUILayout.Toggle("Bilinear Sample", mod.bilinearSample); if (bilin != mod.bilinearSample) { mod.bilinearSample = bilin; dirty = true; } Texture2D obtex = (Texture2D)EditorGUILayout.ObjectField("Obstructions", mod.obTexture, typeof(Texture2D), true); EditorGUILayout.EndToggleGroup(); if (obtex != mod.obTexture) { mod.obTexture = obtex; dirty = true; } mod.DropsPerSec = EditorGUILayout.FloatField("Drops Per Sec", mod.DropsPerSec); if (mod.DropsPerSec < 0.0f) { mod.DropsPerSec = 0.0f; } if (dirty) { mod.ResetGrid(); } if (GUILayout.Button("Reset Physics")) { mod.ResetGrid(); } return(false); }
/// <summary> /// Provides initialization. /// </summary> private void Start() { if (water) { dynamicwater = (MegaDynamicRipple)water.GetComponent <MegaDynamicRipple>(); } //forces = new List<Vector3[]>(); // For drawing force gizmos // Store original rotation and position var originalRotation = transform.rotation; var originalPosition = transform.position; transform.rotation = Quaternion.identity; transform.position = Vector3.zero; // The object must have a collider if (GetComponent <Collider>() == null) { gameObject.AddComponent <MeshCollider>(); Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no collider. MeshCollider has been added.", name)); } isMeshCollider = GetComponent <MeshCollider>() != null; var bounds = GetComponent <Collider>().bounds; if (bounds.size.x < bounds.size.y) { voxelHalfHeight = bounds.size.x; } else { voxelHalfHeight = bounds.size.y; } if (bounds.size.z < voxelHalfHeight) { voxelHalfHeight = bounds.size.z; } voxelHalfHeight /= 2.0f * slicesPerAxis; // The object must have a RidigBody if (GetComponent <Rigidbody>() == null) { gameObject.AddComponent <Rigidbody>(); Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no Rigidbody. Rigidbody has been added.", name)); } GetComponent <Rigidbody>().centerOfMass = new Vector3(0, -bounds.extents.y * 0f, 0) + transform.InverseTransformPoint(bounds.center); voxels = SliceIntoVoxels(isMeshCollider && isConcave); // Restore original rotation and position transform.rotation = originalRotation; transform.position = originalPosition; float volume = GetComponent <Rigidbody>().mass / density; WeldPoints(voxels, voxelsLimit); float archimedesForceMagnitude = WATER_DENSITY * Mathf.Abs(Physics.gravity.y) * volume; localArchimedesForce = new Vector3(0, archimedesForceMagnitude, 0) / voxels.Count; Debug.Log(string.Format("[Buoyancy.cs] Name=\"{0}\" volume={1:0.0}, mass={2:0.0}, density={3:0.0}", name, volume, GetComponent <Rigidbody>().mass, density)); }