public void Awake() { if(mBuoyancy == null) { mBuoyancy = GetComponent<Buoyancy>(); } }
void OnCollisionEnter(Collision collision) { if (collision.collider.CompareTag("House")) { if (anim.GetBool("isJumping") == true) { anim.SetBool("isJumping", false); jumpDust.Play(); jumpSfx.Play(); // Decrease buoyancy Buoyancy buoyancyController = collision.gameObject.GetComponent <Buoyancy>(); buoyancyController.buoyantForce -= jumpBuoyantForceDecrement; //Horizontal force, same code from buoyancy Vector3 normalisePlayerPos = new Vector3(transform.position.x - 0.34f, transform.position.y, transform.position.z + 1.23f); Vector3 normaliseHousePos = new Vector3(collision.transform.position.x + 3.8f, collision.transform.position.y, collision.transform.position.z + 4.9f); float distance = Vector3.Distance(normaliseHousePos, normalisePlayerPos); // Range is around (6, 12) float normalisedBaseDiff = (distance - playerHouseDistanceRangeLow + normalisePlusFactor); float normalisedForceFactor = Mathf.Min(Mathf.Pow(normalisedBaseDiff, magnifiedPower), playerMaxStayForceFactor); Vector3 forceVector = new Vector3( normalisePlayerPos.x - normaliseHousePos.x, normalisePlayerPos.y - normaliseHousePos.y, normalisePlayerPos.z - normaliseHousePos.z ); // Force from player to house Vector3 horizontalForceVector = new Vector3(forceVector.x, 0f, forceVector.z); collision.collider.attachedRigidbody.AddForce(horizontalForceVector / forceVectorDampening * normalisedForceFactor, ForceMode.Impulse); Vector3 verticalForceVector = new Vector3(0f, -forceVector.y, 0f); // Downwards force ContactPoint firstContactPoint = collision.contacts[0]; collision.collider.attachedRigidbody.AddForceAtPosition(verticalForceVector * playerDropForceFactor, firstContactPoint.point); // This will rotate the house } } }
public void Awake() { if (mBuoyancy == null) { mBuoyancy = GetComponent <Buoyancy>(); } }
void FixedUpdate() { if (!enableWaves) { return; } Buoyancy buoyancy = GetComponent <Buoyancy>(); water = GetComponent <MeshFilter>().mesh; if (baseHeight == null) { baseHeight = water.vertices; } Vector3[] vertices = new Vector3[baseHeight.Length]; for (int i = 0; i < vertices.Length; i++) { Vector3 vertex = baseHeight[i]; vertex.y += Mathf.Sin(Time.time * frequency + baseHeight[i].x + baseHeight[i].y + baseHeight[i].z + phase) * amplitude + initialWaterLevel; vertex.y += Mathf.PerlinNoise(baseHeight[i].x + noiseWalk, baseHeight[i].y + Mathf.Sin(Time.time * 0.1f)) * noiseStrength; vertices[i] = vertex; } water.vertices = vertices; water.RecalculateNormals(); MeshCollider waterCollider = GetComponent <MeshCollider>(); waterCollider.sharedMesh = water; }
private void Awake() { this._bu = base.transform.GetComponent <Buoyancy>(); this._fl = base.transform.GetComponent <Floating>(); this._rb = base.transform.GetComponent <Rigidbody>(); this._startDrag = this._rb.drag; this._startAngularDrag = this._rb.angularDrag; }
void Start() { buoyancy = GetComponentInChildren <Buoyancy>() as Buoyancy; icebergHitSource = gameObject.AddComponent <AudioSource>(); icebergHitSource.clip = icebergHitClip; krakenHitSource = gameObject.AddComponent <AudioSource>(); krakenHitSource.clip = krakenHitClip; }
private void Awake() { if (this.Remote) { return; } this.Buoyancy = base.GetComponent <Buoyancy>(); }
private void Awake() { this._bu = base.transform.GetComponent<Buoyancy>(); this._fl = base.transform.GetComponent<Floating>(); this._rb = base.transform.GetComponent<Rigidbody>(); this._startDrag = this._rb.drag; this._startAngularDrag = this._rb.angularDrag; }
public void Awake() { if(mBuoyancy == null) { mBuoyancy = GetComponent<Buoyancy>(); } mOriginalHandPos = mHand.localPosition; }
public void Initialize() { List <Mesh> meshList = new List <Mesh>(); List <MeshRenderer> meshRendererList = new List <MeshRenderer>(); List <Transform> transformList = new List <Transform>(); if (GetComponent <Collider>() != null) { meshList.Add(GetComponent <MeshFilter>().sharedMesh); meshRendererList.Add(GetComponent <MeshRenderer>()); transformList.Add(transform); } for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).GetComponent <Collider>() != null) { Transform child = transform.GetChild(i); meshList.Add(child.GetComponent <MeshFilter>().sharedMesh); meshRendererList.Add(child.GetComponent <MeshRenderer>()); transformList.Add(child); } } Mesh[] meshes = meshList.ToArray(); MeshRenderer[] meshRenderers = meshRendererList.ToArray(); Transform[] transforms = transformList.ToArray(); float[] boundsVolumes = new float[meshes.Length]; for (int i = 0; i < boundsVolumes.Length; i++) { boundsVolumes[i] = meshRenderers[i].bounds.size.x * meshRenderers[i].bounds.size.y * meshRenderers[i].bounds.size.z; } float totalBoundsVolume = boundsVolumes.Sum(); float[] meshVolumes = new float[meshes.Length]; for (int i = 0; i < meshVolumes.Length; i++) { meshVolumes[i] = MeshVolume.VolumeOfMesh(meshes[i], transforms[i]); } float totalMeshVolume = meshVolumes.Sum(); Rigidbody rb = GetComponent <Rigidbody>(); rb.isKinematic = true; rb.useGravity = false; rb.mass = density * totalMeshVolume; rb.drag = 0.0f; rb.angularDrag = 0.0f; meshSampler = new MeshSampler(meshRenderers, transforms, DistributeSamples(boundsVolumes, totalBoundsVolume) /*, stratifiedDivisions*/); gravity = new Gravity(rb, meshSampler); buoyancy = new Buoyancy(rb, meshSampler, totalMeshVolume); waterDrag = new WaterDrag(rb, meshSampler, viscosity); rb.isKinematic = false; }
public void Awake() { if (mBuoyancy == null) { mBuoyancy = GetComponent <Buoyancy>(); } mOriginalHandPos = mHand.localPosition; }
private Rigidbody SetupRigidBody() { if (base.isServer) { GameObject gameObject = base.gameManager.FindPrefab(prefabRagdoll.resourcePath); if (gameObject == null) { return(null); } Ragdoll component = gameObject.GetComponent <Ragdoll>(); if (component == null) { return(null); } if (component.primaryBody == null) { Debug.LogError("[BaseCorpse] ragdoll.primaryBody isn't set!" + component.gameObject.name); return(null); } BoxCollider component2 = component.primaryBody.GetComponent <BoxCollider>(); if (component2 == null) { Debug.LogError("Ragdoll has unsupported primary collider (make it supported) ", component); return(null); } BoxCollider boxCollider = base.gameObject.AddComponent <BoxCollider>(); boxCollider.size = component2.size * 2f; boxCollider.center = component2.center; boxCollider.sharedMaterial = component2.sharedMaterial; } Rigidbody rigidbody = base.gameObject.AddComponent <Rigidbody>(); if (rigidbody == null) { Debug.LogError("[BaseCorpse] already has a RigidBody defined - and it shouldn't!" + base.gameObject.name); return(null); } rigidbody.mass = 10f; rigidbody.useGravity = true; rigidbody.drag = 0.5f; rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; if (base.isServer) { Buoyancy component3 = GetComponent <Buoyancy>(); if (component3 != null) { component3.rigidBody = rigidbody; } ConVar.Physics.ApplyDropped(rigidbody); Vector3 velocity = Vector3Ex.Range(-1f, 1f); velocity.y += 1f; rigidbody.velocity = velocity; rigidbody.angularVelocity = Vector3Ex.Range(-10f, 10f); } return(rigidbody); }
void BuoyancyComponent() { Buoyancy buoyancy = gameObject.AddComponent <Buoyancy>(); buoyancy.buoyancyScale = BuoyancyScale; buoyancy.rigidBody = gameObject.GetComponent <Rigidbody>(); buoyancy.rigidBody.velocity = Vector3.zero; buoyancy.rigidBody.angularVelocity = Vector3.zero; buoyancy.rigidBody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezeRotationX; }
public override void ServerInit() { base.ServerInit(); if (this.buoyancy == null) { Debug.LogWarning(string.Concat("Player corpse has no buoyancy assigned, searching at runtime :", base.name)); this.buoyancy = base.GetComponent <Buoyancy>(); } if (this.buoyancy != null) { this.buoyancy.SubmergedChanged = new Action <bool>(this.BuoyancyChanged); } }
private Rigidbody SetupRigidBody() { if (this.isServer) { GameObject prefab = this.gameManager.FindPrefab(this.prefabRagdoll.resourcePath); if (Object.op_Equality((Object)prefab, (Object)null)) { return((Rigidbody)null); } Ragdoll component1 = (Ragdoll)prefab.GetComponent <Ragdoll>(); if (Object.op_Equality((Object)component1, (Object)null)) { return((Rigidbody)null); } if (Object.op_Equality((Object)component1.primaryBody, (Object)null)) { Debug.LogError((object)("[BaseCorpse] ragdoll.primaryBody isn't set!" + ((Object)((Component)component1).get_gameObject()).get_name())); return((Rigidbody)null); } BoxCollider component2 = (BoxCollider)((Component)component1.primaryBody).GetComponent <BoxCollider>(); if (Object.op_Equality((Object)component2, (Object)null)) { Debug.LogError((object)"Ragdoll has unsupported primary collider (make it supported) ", (Object)component1); return((Rigidbody)null); } M0 m0 = ((Component)this).get_gameObject().AddComponent <BoxCollider>(); ((BoxCollider)m0).set_size(Vector3.op_Multiply(component2.get_size(), 2f)); ((BoxCollider)m0).set_center(component2.get_center()); ((Collider)m0).set_sharedMaterial(((Collider)component2).get_sharedMaterial()); } Rigidbody rigidBody = (Rigidbody)((Component)this).get_gameObject().GetComponent <Rigidbody>(); if (Object.op_Equality((Object)rigidBody, (Object)null)) { rigidBody = (Rigidbody)((Component)this).get_gameObject().AddComponent <Rigidbody>(); } rigidBody.set_mass(10f); rigidBody.set_useGravity(true); rigidBody.set_drag(0.5f); rigidBody.set_collisionDetectionMode((CollisionDetectionMode)0); if (this.isServer) { Buoyancy component = (Buoyancy)((Component)this).GetComponent <Buoyancy>(); if (Object.op_Inequality((Object)component, (Object)null)) { component.rigidBody = rigidBody; } Physics.ApplyDropped(rigidBody); Vector3 vector3 = Vector3Ex.Range(-1f, 1f); ref __Null local = ref vector3.y;
public override void ServerInit() { base.ServerInit(); if (Object.op_Equality((Object)this.buoyancy, (Object)null)) { Debug.LogWarning((object)("Player corpse has no buoyancy assigned, searching at runtime :" + ((Object)this).get_name())); this.buoyancy = (Buoyancy)((Component)this).GetComponent <Buoyancy>(); } if (!Object.op_Inequality((Object)this.buoyancy, (Object)null)) { return; } this.buoyancy.SubmergedChanged = new Action <bool>(this.BuoyancyChanged); }
private List <Vector3> SliceIntoVoxels(Transform collidersRoot, Collider[] colliders, Bounds bounds) { List <Vector3> list = new List <Vector3>(this.slicesPerAxis * this.slicesPerAxis * this.slicesPerAxis); Vector3 min = bounds.min; Vector3 vector = bounds.size / ((float)this.slicesPerAxis - 0.6f); for (int i = 0; i < this.slicesPerAxis; i++) { for (int j = 0; j < this.slicesPerAxis; j++) { for (int k = 0; k < this.slicesPerAxis; k++) { Vector3 vector2 = new Vector3(min.x + vector.x * (0.2f + (float)i), min.y + vector.y * (0.2f + (float)j), min.z + vector.z * (0.2f + (float)k)); for (int l = 0; l < colliders.Length; l++) { Collider collider = colliders[l]; if (collider.enabled && !collider.isTrigger) { Vector3 vector3 = collider.transform.InverseTransformPoint(vector2); MeshCollider meshCollider = collider as MeshCollider; SphereCollider sphereCollider = collider as SphereCollider; bool flag; if (meshCollider) { bool convex = meshCollider.convex; meshCollider.convex = true; flag = Buoyancy.PointInsideMeshCollider(meshCollider, vector3); meshCollider.convex = convex; } else if (sphereCollider) { float radius = sphereCollider.radius; flag = ((vector3 - sphereCollider.center).sqrMagnitude < radius * radius); } else { flag = collider.bounds.Contains(vector2); } if (flag) { list.Add((!(collidersRoot == collider.transform)) ? collidersRoot.InverseTransformPoint(vector2) : vector3); break; } } } } } } return(list); }
private void OnDestroy() { if (LocalPlayer.Transform == base.transform) { LocalPlayer.Transform = null; LocalPlayer.Ridigbody = null; FMOD_StudioEventEmitter.LocalPlayerTransform = null; LocalPlayer.GameObject = null; LocalPlayer.PlayerBase = null; LocalPlayer.HeadTr = null; LocalPlayer.HipsTr = null; LocalPlayer.Inventory = null; LocalPlayer.ReceipeBook = null; LocalPlayer.SpecialActions = null; LocalPlayer.SpecialItems = null; LocalPlayer.MainCamTr = null; LocalPlayer.MainCam = null; LocalPlayer.InventoryCam = null; LocalPlayer.CamFollowHead = null; LocalPlayer.Animator = null; LocalPlayer.AnimControl = null; LocalPlayer.Create = null; LocalPlayer.Tuts = null; LocalPlayer.Sfx = null; LocalPlayer.Stats = null; LocalPlayer.FpCharacter = null; LocalPlayer.FpHeadBob = null; LocalPlayer.CamRotator = null; LocalPlayer.MainRotator = null; LocalPlayer.ScriptSetup = null; LocalPlayer.TargetFunctions = null; LocalPlayer.HitReactions = null; LocalPlayer.Buoyancy = null; LocalPlayer.WaterViz = null; LocalPlayer.AiInfo = null; LocalPlayer.WaterEngine = null; LocalPlayer.ItemDecayMachine = null; LocalPlayer.AnimatedBook = null; LocalPlayer.PassengerManifest = null; LocalPlayer.GreebleRoot = null; LocalPlayer.MudGreeble = null; LocalPlayer.PlayerDeadCam = null; LocalPlayer.PauseMenuBlur = null; LocalPlayer.PauseMenuBlurPsCam = null; LocalPlayer.HeldItemsData = null; LocalPlayer.Vis = null; } }
public void PushRaft(Vector3 worldDirection) { if (this.IsRaftGrabbed) { return; } this.raftMainBody.constraints = RigidbodyConstraints.None; this.raftMainBody.AddForce(worldDirection.normalized * this.pushForce * (0.016666f / Time.fixedDeltaTime), this.pushForceMode); Buoyancy componentInParent = base.GetComponentInParent <Buoyancy>(); bool onWater = componentInParent != null && componentInParent.InWater; if (LocalPlayer.Transform) { LocalPlayer.Sfx.PlayPushRaft(onWater, base.gameObject); } }
private static void WeldPoints(IList <Vector3> list, int targetCount) { if (list.Count <= 2 || targetCount < 2) { return; } while (list.Count > targetCount) { int index; int index2; Buoyancy.FindClosestPoints(list, out index, out index2); Vector3 item = (list[index] + list[index2]) * 0.5f; list.RemoveAt(index2); list.RemoveAt(index); list.Add(item); } }
private void Awake() { LocalPlayer.Transform = this._transform; LocalPlayer.Ridigbody = this._ridigbody; FMOD_StudioEventEmitter.LocalPlayerTransform = LocalPlayer.Transform; LocalPlayer.GameObject = this._playerGO; LocalPlayer.PlayerBase = this._playerBase; LocalPlayer.HeadTr = this._headTr; LocalPlayer.HipsTr = this._hipsTr; LocalPlayer.Inventory = this._inventory; LocalPlayer.ReceipeBook = this._receipeBook; LocalPlayer.SpecialActions = this._specialActions; LocalPlayer.SpecialItems = this._specialItems; LocalPlayer.MainCamTr = this._mainCamTr; LocalPlayer.MainCam = this._mainCam; LocalPlayer.InventoryCam = this._inventoryCam; LocalPlayer.CamFollowHead = this._camFollowHead; LocalPlayer.Animator = this._animator; LocalPlayer.AnimControl = this._animControl; LocalPlayer.Create = this._create; LocalPlayer.Tuts = this._tuts; LocalPlayer.Sfx = this._sfx; LocalPlayer.Stats = this._stats; LocalPlayer.FpCharacter = this._fpc; LocalPlayer.FpHeadBob = this._fphb; LocalPlayer.CamRotator = this._camRotator; LocalPlayer.MainRotator = this._mainRotator; LocalPlayer.ScriptSetup = this._scriptSetup; LocalPlayer.TargetFunctions = this._targetFunctions; LocalPlayer.HitReactions = this._hitReactions; LocalPlayer.Buoyancy = this._buoyancy; LocalPlayer.WaterViz = this._waterViz; LocalPlayer.AiInfo = this._aiInfo; LocalPlayer.WaterEngine = this._waterEngine; LocalPlayer.ItemDecayMachine = this._itemDecayMachine; LocalPlayer.AnimatedBook = this._animatedBook; LocalPlayer.PassengerManifest = this._passengerManifest; LocalPlayer.GreebleRoot = this._greebleRoot; LocalPlayer.MudGreeble = this._mudGreeble; LocalPlayer.PlayerDeadCam = this._PlayerDeadCam; LocalPlayer.PauseMenuBlur = this._pauseMenuBlur; LocalPlayer.PauseMenuBlurPsCam = this._pauseMenuBlurPsCam; LocalPlayer.HeldItemsData = this._heldItemsData; LocalPlayer.Vis = this._vis; base.StartCoroutine(this.OldSaveCompat()); }
private void FixedUpdate() { if (!dragging && !start) { velocity += Gravity.Acceleration(); float time = Time.realtimeSinceStartup; // Get Triangle List List <Triangle> underWaterTriangles = Intersection.GetTrianglesUnderWater(ref triangles, ref vertices, transform, intersectPosition); // Get Volume float volumeUnderWater = VolumeCalculator.GetVolume(ref underWaterTriangles, transform, intersectPosition); if (UIText != null) { float totalVolumeRounded = Mathf.Round(totalVolume * 100f) / 100f; float volumeUnderWaterRounded = Mathf.Round(volumeUnderWater * 100f) / 100f; UIText.text = transform.name + " - Total Volume:" + totalVolumeRounded + ", Volume Under Water: " + volumeUnderWaterRounded; } // Calculate drag from air or water float dragDensity = volumeUnderWater > 0f ? densityWater : densityAir; Vector3 drag = Drag.GetDragForce(coefficientOfDrag, dragDensity, velocity, area); velocity -= drag / mass; // Calculate Lift Vector3 bouyancy = Buoyancy.Calculate(transform, intersectPosition, volumeUnderWater, totalVolume); // velocity += lift; velocity += bouyancy / mass * Time.fixedDeltaTime; if (transform.position.y < ground.transform.position.y) { Vector3 currentPosition = transform.position; currentPosition.y = ground.transform.position.y; transform.position = currentPosition; velocity = Vector3.zero; } //velocity += Lift.CalculateLift(ref myTriangles, ref myVertices, transform, intersectPosition, totalVolume) / mass * Time.fixedDeltaTime; ApplyVelocity(); } }
//if bomb hits this object public void hit() { string[] edges = { "edge1", "edge2" }; if (HP < 1) { Buoyancy buoyancyComponent = transform.Find(edges[Random.Range(0, edges.Length - 1)]).GetComponent <Buoyancy>(); buoyancyComponent.Volume = DESTROYED_OBJECT_VOLUME; if (gameObject.name == "AirCarrier") { Timers.timeout(20, () => { Game.Instance.gameOver("air carrier is destroyed"); }); } return; } HP--; foreach (string edge in edges) { transform.Find(edge).GetComponent <Buoyancy>().Volume -= Mathf.Max(MIN_RANDOM_COEFFICIENT, Random.value) * buoyancy / maxHP; } }
void Start() { rb = GetComponent <Rigidbody>(); if (rb == null) { rb = gameObject.AddComponent <Rigidbody>(); } drag = rb.drag; buoy = GetComponent <Buoyancy>(); camH = camPos.position.y; if (pushPos == null) { pushPos = transform; } }
void OnEnable() { Buoyancy boyancy = target as Buoyancy; presetPath = Application.dataPath + "/Ocean/Editor/_OceanPresets"; rrig = boyancy.GetComponent <Rigidbody>(); if (rrig == null) { Debug.Log("Object requires a Rigidbody"); } presetPath = Application.dataPath + "/Ocean/Editor/_OceanPresets"; col = boyancy.GetComponent <BoxCollider>(); if (col == null) { Debug.Log("Object requires a Box Collider"); } }
private void Awake() { this.buoyancy = base.GetComponent <Buoyancy>(); this.rb = base.GetComponent <Rigidbody>(); this.playerPhysicMaterial = base.GetComponent <CapsuleCollider>().material; this.playerPhysicMaterial2 = base.GetComponent <SphereCollider>().material; this.rb.freezeRotation = true; this.rb.useGravity = false; this.collFlags = base.transform.GetComponent <RigidBodyCollisionFlags>(); this.setup = base.GetComponentInChildren <playerScriptSetup>(); this.targets = base.GetComponentInChildren <playerTargetFunctions>(); this.UnLockView(); this.capsule = (base.GetComponent <Collider>() as CapsuleCollider); this.defaultMass = this.rb.mass; this.originalHeight = this.capsule.height; this.originalYPos = this.capsule.center.y; this.crouchCapsuleCenter = (this.crouchHeight - this.originalHeight) / 2f; this.Grounded = true; this.fsmCrouchBool = FsmVariables.GlobalVariables.GetFsmBool("playerCrouchBool"); }
void OnEnable() { Buoyancy boyancy = target as Buoyancy; var script = MonoScript.FromScriptableObject(this); presetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(script)) + "/_OceanPresets"; rrig = boyancy.GetComponent <Rigidbody>(); if (rrig == null) { Debug.Log("Object requires a Rigidbody"); } presetPath = Application.dataPath + "/Ocean/Editor/_OceanPresets"; col = boyancy.GetComponent <BoxCollider>(); if (col == null) { Debug.Log("Object requires a Box Collider"); } }
public void Voxelize(Transform collidersRoot, float minBoundsYOffset = 0f) { if (!base.gameObject.activeInHierarchy) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(base.gameObject); Buoyancy component = gameObject.GetComponent <Buoyancy>(); component.Voxelize(component.transform, 0f); if (component.Voxels != null && component.Voxels.Length > 0) { this.Voxels = new Vector3[component.Voxels.Length]; component.Voxels.CopyTo(this.Voxels, 0); this.voxelHalfHeight = component.voxelHalfHeight; this.localArchimedesForce = component.localArchimedesForce; } UnityEngine.Object.DestroyImmediate(gameObject); return; } Collider[] componentsInChildren = collidersRoot.GetComponentsInChildren <Collider>(); bool flag = false; Bounds bounds = default(Bounds); foreach (Collider collider in componentsInChildren) { if (collider.enabled && !collider.isTrigger) { bounds = collider.bounds; flag = true; break; } } if (!flag) { if (Application.isPlaying) { base.enabled = false; } Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no collider.", base.name)); } else { Quaternion rotation = collidersRoot.rotation; Vector3 position = collidersRoot.position; collidersRoot.rotation = Quaternion.identity; collidersRoot.position = Vector3.zero; if (componentsInChildren.Length > 1) { Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue); for (int j = componentsInChildren.Length - 1; j >= 0; j--) { Collider collider2 = componentsInChildren[j]; if (collider2.enabled && !collider2.isTrigger && collider2.gameObject.activeInHierarchy) { Vector3 min2 = collider2.bounds.min; Vector3 max2 = collider2.bounds.max; if (min2.x < min.x) { min.x = min2.x; } if (min2.y < min.y) { min.y = min2.y; } if (min2.z < min.z) { min.z = min2.z; } if (max2.x > max.x) { max.x = max2.x; } if (max2.y > max.y) { max.y = max2.y; } if (max2.z > max.z) { max.z = max2.z; } } } min.y += minBoundsYOffset; bounds.min = min; bounds.max = max; } if (bounds.size.x < bounds.size.y) { this.voxelHalfHeight = bounds.size.x; } else { this.voxelHalfHeight = bounds.size.y; } if (bounds.size.z < this.voxelHalfHeight) { this.voxelHalfHeight = bounds.size.z; } this.voxelHalfHeight /= (float)(2 * this.slicesPerAxis); if (this.OverrideCenterOfMass) { base.GetComponent <Rigidbody>().centerOfMass = this.OverrideCenterOfMass.position; } else { base.GetComponent <Rigidbody>().centerOfMass = new Vector3(0f, -bounds.extents.y * 0.2f, 0f) + base.transform.InverseTransformPoint(bounds.center); } List <Vector3> list = this.SliceIntoVoxels(collidersRoot, componentsInChildren, bounds); collidersRoot.position = position; collidersRoot.rotation = rotation; float num = base.GetComponent <Rigidbody>().mass / this.density; Buoyancy.WeldPoints(list, this.voxelsLimit); float y = 1000f * Mathf.Abs(Physics.gravity.y) * num; this.localArchimedesForce = new Vector3(0f, y, 0f) / (float)list.Count; this.Voxels = list.ToArray(); } }
public BuoyancySample(Microsoft.Xna.Framework.Game game) : base(game) { // Add basic force effects. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // ----- Buoyancy Force Effect // Buoyancy is a force effect that lets bodies swim in water. The water area is // defined by two properties: // - Buoyancy.AreaOfEffect defines which objects are affected. // - Buoyancy.Surface defines the water level within this area. // The area of effect can be defined in different ways. In this sample we will use // a geometric object ("trigger volume"). // First, define the shape of the water area. We will create simple pool. Shape poolShape = new BoxShape(16, 10, 16); Vector3F poolCenter = new Vector3F(0, -5, 0); // Then create a geometric object for the water area. (A GeometricObject is required // to position the shape in the world. A GeometricObject stores shape, scale, position, // orientation, ...) GeometricObject waterGeometry = new GeometricObject(poolShape, new Pose(poolCenter)); // Then create a collision object for the geometric object. (A CollisionObject required // because the geometry should be used for collision detection with other objects.) _waterCollisionObject = new CollisionObject(waterGeometry) { // Assign the object to a different collision group: // The Grab component (see Grab.cs) uses a ray to perform hit tests. We don't want the ray // to collide with the water. Therefore, we need to assign the water collision object to a // different collision group. The general geometry is in collision group 0. The rays are in // collision group 2. Add the water to collision group 1. Collision between 0 and 2 are // enabled. Collision between 1 and 2 need to be disabled - this collision filter was set // in PhysicsGame.cs. CollisionGroup = 1, // Set the type to "Trigger". This improves the performance because the collision // detection does not need to compute detailed contact information. The collision // detection only returns whether an objects has contact with the water. Type = CollisionObjectType.Trigger, }; // The collision object needs to be added into the collision domain of the simulation. Simulation.CollisionDomain.CollisionObjects.Add(_waterCollisionObject); // Now we can add the buoyancy effect. Buoyancy buoyancy = new Buoyancy { AreaOfEffect = new GeometricAreaOfEffect(_waterCollisionObject), Surface = new Plane(Vector3F.Up, 0), Density = 1000f, // The density of water (1000 kg/m³). AngularDrag = 0.4f, LinearDrag = 4f, // Optional: Let the objects drift in the water by setting a flow velocity. //Velocity = new Vector3F(-0.5f, 0, 0.5f), }; Simulation.ForceEffects.Add(buoyancy); // Add static area around the pool. RigidBody bottom = new RigidBody(new BoxShape(36, 2, 36)) { MotionType = MotionType.Static, Pose = new Pose(new Vector3F(0, -11, 0)), }; Simulation.RigidBodies.Add(bottom); RigidBody left = new RigidBody(new BoxShape(10, 10, 36)) { MotionType = MotionType.Static, Pose = new Pose(new Vector3F(-13, -5, 0)), }; Simulation.RigidBodies.Add(left); RigidBody right = new RigidBody(new BoxShape(10, 10, 36)) { MotionType = MotionType.Static, Pose = new Pose(new Vector3F(13, -5, 0)), }; Simulation.RigidBodies.Add(right); RigidBody front = new RigidBody(new BoxShape(16, 10, 10)) { MotionType = MotionType.Static, Pose = new Pose(new Vector3F(0, -5, 13)), }; Simulation.RigidBodies.Add(front); RigidBody back = new RigidBody(new BoxShape(16, 10, 10)) { MotionType = MotionType.Static, Pose = new Pose(new Vector3F(0, -5, -13)), }; Simulation.RigidBodies.Add(back); // ----- Add some random objects to test the effect. // Note: Objects swim if their density is less than the density of water. They sink // if the density is greater than the density of water. // We can define the density of objects by explicitly setting the mass. // Add a swimming board. BoxShape raftShape = new BoxShape(4, 0.3f, 4); MassFrame raftMass = MassFrame.FromShapeAndDensity(raftShape, Vector3F.One, 700, 0.01f, 3); RigidBody raft = new RigidBody(raftShape, raftMass, null) { Pose = new Pose(new Vector3F(0, 4, 0)), }; Simulation.RigidBodies.Add(raft); // Add some boxes on top of the swimming board. BoxShape boxShape = new BoxShape(1, 1, 1); MassFrame boxMass = MassFrame.FromShapeAndDensity(boxShape, Vector3F.One, 700, 0.01f, 3); for (int i = 0; i < 5; i++) { RigidBody box = new RigidBody(boxShape, boxMass, null) { Pose = new Pose(new Vector3F(0, 5 + i * 1.1f, 0)), }; Simulation.RigidBodies.Add(box); } // Add some "heavy stones" represented as spheres. SphereShape stoneShape = new SphereShape(0.5f); MassFrame stoneMass = MassFrame.FromShapeAndDensity(stoneShape, Vector3F.One, 2500, 0.01f, 3); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-9, 9); position.Y = 5; RigidBody stone = new RigidBody(stoneShape, stoneMass, null) { Pose = new Pose(position), }; Simulation.RigidBodies.Add(stone); } // Add some very light objects. CylinderShape cylinderShape = new CylinderShape(0.3f, 1); MassFrame cylinderMass = MassFrame.FromShapeAndDensity(cylinderShape, Vector3F.One, 500, 0.01f, 3); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-9, 9); position.Y = 5; QuaternionF orientation = RandomHelper.Random.NextQuaternionF(); RigidBody cylinder = new RigidBody(cylinderShape, cylinderMass, null) { Pose = new Pose(position, orientation), }; Simulation.RigidBodies.Add(cylinder); } }
private void Awake() { this.wallSetup = base.transform.GetComponentInChildren<wallTriggerSetup>(); this.setup = base.GetComponent<playerScriptSetup>(); this.buoyancy = base.transform.GetComponentInParent<Buoyancy>(); this.animEvents = base.transform.GetComponent<animEventsManager>(); this.planeCrashGo = GameObject.FindWithTag("planeCrash"); this.player = base.transform.GetComponentInParent<PlayerInventory>(); this.sledHinge = base.transform.GetComponentInChildren<HingeJoint>(); this.sledPivot = base.GetComponentInParent<Rigidbody>().transform.FindChild("sledPivot").transform; if (this.planeCrashGo) { this.setup.sceneInfo.planeCrash = this.planeCrashGo; this.planeCrash = this.planeCrashGo.transform; } else { GameObject gameObject = new GameObject(); this.planeCrash = gameObject.transform; this.planeCrash.position = base.transform.position; if (this.setup.sceneInfo != null) { this.setup.sceneInfo.planeCrash = this.planeCrash.gameObject; } } }
public static void SetBuoyancy(DependencyObject element, Buoyancy value) { element.SetValue(BuoyancyProperty, value); }
//saves a buoyancy preset public static void savePreset(Buoyancy buoyancy) { if (!Directory.Exists(presetPath)) { Directory.CreateDirectory(presetPath); } string preset = EditorUtility.SaveFilePanel("Save buoyancy preset", presetPath, "", "buoyancy"); if (preset != null) { if (preset.Length > 0) { using (BinaryWriter swr = new BinaryWriter(File.Open(preset, FileMode.Create))) { //rigidbody parameters if (rrig != null) { swr.Write((byte)1); //has Rigidbody swr.Write((float)rrig.mass); //float swr.Write((float)rrig.drag); //float swr.Write((float)rrig.angularDrag); //float swr.Write((bool)rrig.useGravity); //bool } //box collider parameters if (col != null) { swr.Write((byte)1); //has Boxcollider swr.Write(col.center.x); //float swr.Write(col.center.y); //float swr.Write(col.center.z); //float swr.Write(col.size.x * buoyancy.transform.localScale.x); //float swr.Write(col.size.y * buoyancy.transform.localScale.y); //float swr.Write(col.size.z * buoyancy.transform.localScale.z); //float } //buoyancy parameters swr.Write(buoyancy.magnitude); //float swr.Write(buoyancy.ypos); //float swr.Write(buoyancy.CenterOfMassOffset); //float swr.Write(buoyancy.dampCoeff); //float swr.Write(buoyancy.SlicesX); //int swr.Write(buoyancy.SlicesZ); //int swr.Write(buoyancy.interpolation); //int swr.Write(buoyancy.ChoppynessAffectsPosition); //bool swr.Write(buoyancy.cvisible); //bool swr.Write(buoyancy.ChoppynessFactor); //float swr.Write(buoyancy.WindAffectsPosition); //bool swr.Write(buoyancy.wvisible); //bool swr.Write(buoyancy.WindFactor); //float swr.Write(buoyancy.xAngleAddsSliding); //bool swr.Write(buoyancy.svisible); //bool swr.Write(buoyancy.slideFactor); //float swr.Write(buoyancy.moreAccurate); //bool swr.Write(buoyancy.useFixedUpdate); //bool var bc = buoyancy.GetComponent <BoatController>(); //If the object has a boat controller attached write the properties. //This is useful, because if you change the buoynacy settings the speed //settings of the boat controller need tweaking again. if (bc != null) { swr.Write(true); //bool swr.Write(bc.m_FinalSpeed); //float swr.Write(bc.m_accelerationTorqueFactor); //float swr.Write(bc.m_InertiaFactor); //float swr.Write(bc.m_turningFactor); //float swr.Write(bc.m_turningTorqueFactor); //float } else { swr.Write(false); //bool } swr.Write(buoyancy.renderQueue); //int } } } }
public override void OnInspectorGUI() { Buoyancy buoyancy = target as Buoyancy; DrawSeparator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Render Queue", GUILayout.MaxWidth(130)); buoyancy.renderQueue = EditorGUILayout.IntField(buoyancy.renderQueue); GUILayout.Space(175); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Material Render Queue", "Set the object's material render queue to something that suits you. Useful for not showing shore lines under boat.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("More Accurate", GUILayout.MaxWidth(130)); buoyancy.moreAccurate = EditorGUILayout.Toggle(buoyancy.moreAccurate); GUILayout.Space(175); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("More accurate Calculation", "If a more accurate function of the Water height function should be used.\n\nIt is however 2.5x times slower.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Use FixedUpdate", GUILayout.MaxWidth(130)); buoyancy.useFixedUpdate = EditorGUILayout.Toggle(buoyancy.useFixedUpdate); GUILayout.Space(175); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Use FixedUpdate()", "If this object should be simulated in the FixedUpdate function. Can be better timed but it is more accurate if unchecked.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Buoyancy"); GUILayout.Space(-100); buoyancy.magnitude = EditorGUILayout.Slider(buoyancy.magnitude, 0, 20); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Buoyancy magnitude", "The amount of the buoyant forces applied to this vessel.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Y offset"); GUILayout.Space(-100); buoyancy.ypos = EditorGUILayout.Slider(buoyancy.ypos, -30f, 30f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Y offset", "How many units the boat will float above the calculated position.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Center of Mass"); GUILayout.Space(-100); buoyancy.CenterOfMassOffset = EditorGUILayout.Slider(buoyancy.CenterOfMassOffset, -20f, 20f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Center of Mass offset", "Offsets the height of the center of mass of the rigidbody.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Damp Coeff"); GUILayout.Space(-100); buoyancy.dampCoeff = EditorGUILayout.Slider(buoyancy.dampCoeff, 0f, 2f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Damp Coefficient", "The damp coefficient of the buoyancy.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Slices X"); GUILayout.Space(-100); buoyancy.SlicesX = (int)EditorGUILayout.Slider(buoyancy.SlicesX, 2, 20); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Slices X dimension", "The slicing of the bounds of the box collider in the X dimension.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Slices Z"); GUILayout.Space(-100); buoyancy.SlicesZ = (int)EditorGUILayout.Slider(buoyancy.SlicesZ, 2, 20); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Slices Z dimension", "The slicing of the bounds of the box collider in the Z dimension.", "OK"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Interpolation"); GUILayout.Space(-100); buoyancy.interpolation = (int)EditorGUILayout.Slider(buoyancy.interpolation, 0, 20); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Buoyancy Interpolation", "How many cycles will be used to average/interpolate the final buoynacy.\n\nKeep this as small as you can since it adds overhead.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); DrawSeparator(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Choppyness influence", GUILayout.MaxWidth(130)); buoyancy.ChoppynessAffectsPosition = EditorGUILayout.Toggle(buoyancy.ChoppynessAffectsPosition); GUILayout.Space(175); EditorGUILayout.LabelField("ifIsVisible", GUILayout.MaxWidth(60)); buoyancy.cvisible = EditorGUILayout.Toggle(buoyancy.cvisible); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Choppyness affects boat", "If the choppyness of the waves affect the boat's position and rotation.\n\nThis will be skipped if the boat has reached a high speed.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Choppyness factor", GUILayout.MinWidth(100)); GUILayout.Space(-80); buoyancy.ChoppynessFactor = EditorGUILayout.Slider(buoyancy.ChoppynessFactor, 0, 10f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Choppyness Factor", "The amount of choppyness that will influence the boat.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Wind affects boat", GUILayout.MaxWidth(130)); buoyancy.WindAffectsPosition = EditorGUILayout.Toggle(buoyancy.WindAffectsPosition); GUILayout.Space(175); EditorGUILayout.LabelField("ifIsVisible", GUILayout.MaxWidth(60)); buoyancy.wvisible = EditorGUILayout.Toggle(buoyancy.wvisible); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Wind affects boat", "If the Ocean wind affect the boat's position and rotation.\n\nThis will be skipped if the boat has reached a high speed.\n\n" + "If ifIsVisible is checked the calculations will take place only if the objects renderer is visible.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Wind factor", GUILayout.MinWidth(100)); GUILayout.Space(-80); buoyancy.WindFactor = EditorGUILayout.Slider(buoyancy.WindFactor, 0, 5f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Wind Factor", "The amount of wind that will influence the boat.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Slope sliding", GUILayout.MaxWidth(130)); buoyancy.xAngleAddsSliding = EditorGUILayout.Toggle(buoyancy.xAngleAddsSliding); GUILayout.Space(175); EditorGUILayout.LabelField("ifIsVisible", GUILayout.MaxWidth(60)); buoyancy.svisible = EditorGUILayout.Toggle(buoyancy.svisible); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Slope sliding", "If the boat faces stormy waves, sliding forces will be applied to it.\n\n" + "If ifIsVisible is checked the calculations will take place only if the objects renderer is visible.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Slide factor", GUILayout.MinWidth(100)); GUILayout.Space(-80); buoyancy.slideFactor = EditorGUILayout.Slider(buoyancy.slideFactor, 0, 10f); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Slope sliding Factor", "The amount of sliding force applied to the boat.", "OK"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Visible Renderer", GUILayout.MinWidth(130)); GUILayout.Space(-150); buoyancy._renderer = (Renderer)EditorGUILayout.ObjectField(buoyancy._renderer, typeof(Renderer), true, GUILayout.MinWidth(120)); if (GUILayout.Button("?", GUILayout.MaxWidth(20))) { EditorUtility.DisplayDialog("Renderer", "The object's renderer to make visibilty checks against it.", "OK"); } EditorGUILayout.EndHorizontal(); DrawSeparator(); GUILayout.Space(8); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save preset")) { savePreset(buoyancy); } if (GUILayout.Button("Load preset")) { loadPreset(buoyancy); } EditorGUILayout.EndHorizontal(); GUILayout.Space(8); DrawSeparator(); if (GUI.changed) { EditorUtility.SetDirty(buoyancy); if (!EditorApplication.isPlaying) { EditorSceneManager.MarkSceneDirty(buoyancy.gameObject.scene); } } }
//loads a buoyancy preset (and boat controller settings if available) public static bool loadPreset(Buoyancy buoyancy) { string preset = EditorUtility.OpenFilePanel("Load Ocean preset", presetPath, "buoyancy"); if (!Application.isPlaying) { if (preset != null) { if (preset.Length > 0) { if (File.Exists(preset)) { using (BinaryReader br = new BinaryReader(File.Open(preset, FileMode.Open))){ bool hasrigidbody = false, hascollider = false; if (br.BaseStream.Position != br.BaseStream.Length) { hasrigidbody = br.ReadBoolean(); } if (hasrigidbody) { float mass = 1, drag = 1, andrag = 1; bool usegrav = true; if (br.BaseStream.Position != br.BaseStream.Length) { mass = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { drag = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { andrag = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { usegrav = br.ReadBoolean(); } if (rrig != null) { rrig.mass = mass; rrig.drag = drag; rrig.angularDrag = andrag; rrig.useGravity = usegrav; } else { Debug.Log("No rigid body found"); } } if (br.BaseStream.Position != br.BaseStream.Length) { hascollider = br.ReadBoolean(); } if (hascollider) { float x = 0, y = 0, z = 0, sx = 1, sy = 1, sz = 1; if (br.BaseStream.Position != br.BaseStream.Length) { x = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { y = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { z = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { sx = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { sy = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { sz = br.ReadSingle(); } if (col != null) { col.center = new Vector3(x, y, z); col.size = new Vector3(sx / buoyancy.transform.localScale.x, sy / buoyancy.transform.localScale.y, sz / buoyancy.transform.localScale.z); } else { Debug.Log("No Box Collider found"); } } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.magnitude = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.ypos = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.CenterOfMassOffset = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.dampCoeff = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.SlicesX = br.ReadInt32(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.SlicesZ = br.ReadInt32(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.interpolation = br.ReadInt32(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.ChoppynessAffectsPosition = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.cvisible = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.ChoppynessFactor = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.WindAffectsPosition = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.wvisible = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.WindFactor = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.xAngleAddsSliding = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.svisible = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.slideFactor = br.ReadSingle(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.moreAccurate = br.ReadBoolean(); } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.useFixedUpdate = br.ReadBoolean(); } bool hasBoatController = false; if (br.BaseStream.Position != br.BaseStream.Length) { hasBoatController = br.ReadBoolean(); if (hasBoatController) { float res = 0; var bc = buoyancy.GetComponent <BoatController>(); res = br.ReadSingle(); if (bc) { bc.m_FinalSpeed = res; } res = br.ReadSingle(); if (bc) { bc.m_accelerationTorqueFactor = res; } res = br.ReadSingle(); if (bc) { bc.m_InertiaFactor = res; } res = br.ReadSingle(); if (bc) { bc.m_turningFactor = res; } res = br.ReadSingle(); if (bc) { bc.m_turningTorqueFactor = res; } } } if (br.BaseStream.Position != br.BaseStream.Length) { buoyancy.renderQueue = br.ReadInt32(); } //try to asign a renderer for visibility checks if there is none assigned in the boyancy inspector. if (buoyancy._renderer == null) { buoyancy._renderer = buoyancy.GetComponent <Renderer>(); if (!buoyancy._renderer) { buoyancy._renderer = buoyancy.GetComponentInChildren <Renderer>(); } } EditorUtility.SetDirty(buoyancy); if (hasBoatController) { var bc = buoyancy.GetComponent <BoatController>(); EditorUtility.SetDirty(bc); if (!EditorApplication.isPlaying) { EditorSceneManager.MarkSceneDirty(bc.gameObject.scene); } } if (!EditorApplication.isPlaying) { EditorSceneManager.MarkSceneDirty(buoyancy.gameObject.scene); } return(true); } } else { Debug.Log(preset + " does not exist..."); return(false); } } } } else { Debug.Log("Cannot load this on runtime"); } return(false); }