public override void OnInspectorGUI() { DrawDefaultInspector(); SkinnedMeshCollider myScript = (SkinnedMeshCollider)target; if (GUILayout.Button("UPDATE MESH COLLIDER")) { myScript.UpdateCollider(); } }
public static void CombatEntityHurt(BaseCombatEntity combatEnt, HitInfo info) { try { Assert.Test(combatEnt.isServer, "This should be called serverside only"); if (combatEnt.IsDead()) { return; } BaseNPC npc = combatEnt.GetComponent <BaseNPC>(); BaseCorpse corpse = combatEnt.GetComponent <BaseCorpse>(); BasePlayer player = combatEnt.GetComponent <BasePlayer>(); if (!SkinnedMeshCollider.ScaleDamage(info)) { if (combatEnt.baseProtection != null) { combatEnt.baseProtection.Scale(info.damageTypes); if (ConsoleGlobal.developer > 1) { Debug.Log("BaseProtection Scaling for entity :" + combatEnt.name); } } } else { if (ConsoleGlobal.developer > 1) { Debug.Log("SMC scaling damage for entity :" + combatEnt.name); } } HurtEvent he; if (player != null) { Player p = Server.GetPlayer(player); if (p.Teleporting) { for (int i = 0; i < info.damageTypes.types.Length; i++) { info.damageTypes.types[i] = 0f; } } he = new PlayerHurtEvent(p, info); OnPlayerHurt.OnNext(he as PlayerHurtEvent); } else if (npc != null) { he = new NPCHurtEvent(new NPC(npc), info); OnNPCHurt.OnNext(he as NPCHurtEvent); } else if (corpse != null) { he = new CorpseHurtEvent(corpse, info); OnCorpseHurt.OnNext(he as CorpseHurtEvent); } else { he = new CombatEntityHurtEvent(combatEnt, info); OnCombatEntityHurt.OnNext(he as CombatEntityHurtEvent); } // the DebugHurt() method if (vis.attack) { if (info.PointStart != info.PointEnd) { ConsoleSystem.Broadcast("ddraw.arrow", new object[] { 60, Color.cyan, info.PointStart, info.PointEnd, 0.1 }); ConsoleSystem.Broadcast("ddraw.sphere", new object[] { 60, Color.cyan, info.HitPositionWorld, 0.05 }); } string text = String.Empty; for (int i = 0; i < info.damageTypes.types.Length; i++) { float num = info.damageTypes.types [i]; if (num != 0) { string text2 = text; text = String.Concat(new string[] { text2, " ", ((Rust.DamageType)i).ToString().PadRight(10), num.ToString("0.00"), "\r\n" }); } } string text3 = String.Concat(new object[] { "<color=lightblue>Damage:</color>".PadRight(10), info.damageTypes.Total().ToString("0.00"), "\r\n<color=lightblue>Health:</color>".PadRight(10), combatEnt.health.ToString("0.00"), " / ", (combatEnt.health - info.damageTypes.Total() > 0) ? "<color=green>" : "<color=red>", (combatEnt.health - info.damageTypes.Total()).ToString("0.00"), "</color>", "\r\n<color=lightblue>Hit Ent:</color>".PadRight(10), combatEnt, "\r\n<color=lightblue>Attacker:</color>".PadRight(10), info.Initiator, "\r\n<color=lightblue>Weapon:</color>".PadRight(10), info.Weapon, "\r\n<color=lightblue>Damages:</color>\r\n", text }); ConsoleSystem.Broadcast("ddraw.text", new object[] { 60, Color.white, info.HitPositionWorld, text3 }); } combatEnt.health -= info.damageTypes.Total(); if (ConsoleGlobal.developer > 1) { Debug.Log("[Combat]".PadRight(10) + combatEnt.gameObject.name + " hurt " + info.damageTypes.GetMajorityDamageType() + "/" + info.damageTypes.Total() + " - " + combatEnt.health.ToString("0") + " health left" ); } combatEnt.lastDamage = info.damageTypes.GetMajorityDamageType(); if (combatEnt.health <= 0) { combatEnt.Die(info); } } catch (Exception ex) { Logger.LogError("[Hooks] Error in CombatEntityHurt hook."); Logger.LogException(ex); } }
void Update() { Camera camera = gameObject.GetComponent <Camera>(); if (mode == MouseMode.None && (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))) { if (Input.GetMouseButton(0)) { mode = MouseMode.Tumbling; } else if (Input.GetMouseButton(1)) { mode = MouseMode.Zooming; } else if (Input.GetMouseButton(2)) { mode = MouseMode.Panning; } if (mode != MouseMode.None) { MousePosition = Input.mousePosition; #if !UNITY_WEBGL // If we have any SkinnedMeshColliders, update them so we can test if the user // clicked on a skinned mesh. // // This is slow on WebGL, so we just use the initial pose for collision, since the // demo model doesn't move enough that updating it again is important. Unity wants // us to do this by creating a bunch of capsule colliders to approximate the model, // but that's not worth it for this simple demo. SkinnedMeshCollider.UpdateAllColliders(); #endif // Find the object the mouse is over. If there isn't one, keep the old origin. // Maya actually remembers the distance to the most recent click (centerOfInterest) // and uses that as the distance to the origin if you click on a point that doesn't // intersect anything, but we don't currently do that. RaycastHit hit; if (GetMouseIntersection(camera, out hit)) { Origin = hit.point; } } } if (mode == MouseMode.None && HasFocus) { // Handle mouse wheel zooming. Don't do this when we don't have focus, to reduce this // triggering unintentionally while scrolling other editor windows. We should really // check whether the mouse is over the window, but Unity doesn't know how to let us do // this. float MouseWheelDelta = Input.GetAxis("Mouse ScrollWheel"); if (MouseWheelDelta != 0) { bool Forward = MouseWheelDelta > 0; float zoom = .1f * (Forward? +1:-1); ZoomBy(zoom); } } if (mode == MouseMode.Tumbling && !Input.GetMouseButton(0)) { mode = MouseMode.None; } if (mode == MouseMode.Zooming && !Input.GetMouseButton(1)) { mode = MouseMode.None; } if (mode == MouseMode.Panning && !Input.GetMouseButton(2)) { mode = MouseMode.None; } Vector3 distance = camera.ScreenToViewportPoint(Input.mousePosition - MousePosition); MousePosition = Input.mousePosition; // Rotate camera along X and Y axis if (mode == MouseMode.Tumbling) { Vector3 OriginWorldSpaceRight = transform.localToWorldMatrix.MultiplyVector(Vector3.right); transform.RotateAround(Origin, OriginWorldSpaceRight, -distance.y * TumblingSpeed); transform.RotateAround(Origin, Vector3.up, distance.x * TumblingSpeed); } else if (mode == MouseMode.Panning) { Vector3 move = new Vector3(distance.x * -1 * PanningSpeed, distance.y * -1 * PanningSpeed, 0); transform.Translate(move, Space.Self); } else if (mode == MouseMode.Zooming) { float zoom = distance.x - distance.y; ZoomBy(zoom); } }