public void LockOccupant(bool locked) { if (IsOccupied) { if (locked && !Occupant.LockedParent == tr) { if (!Occupant.LockTransform(tr)) { Debug.Log("Couldn't lock occupant, already locked by " + Occupant.LockedParent.name); } } else { if (!Occupant.UnlockTransform(tr)) { if (Occupant.LockedParent != null) { Debug.Log("already locked by " + Occupant.LockedParent.name); } } } } }
public void RefreshToolDoppleganger(bool equipping) { if (mDopplegangerLocked) { //rogue call, probably from OnModeChange or something return; } if (!equipping) { BreakDownToolDoppleganger(); //nothing else to do here return; } else if (!HasWorldItem) { BreakDownToolDoppleganger(); } else { //we're equippping and we have a worlditem bool useDoppleganger = true; bool displayAsTool = true; Vector3 equipPos = worlditem.Props.Global.PivotOffset; Vector3 equipRot = worlditem.Props.Global.BaseRotation; Equippable equippable = null; if (worlditem.Is <Equippable> (out equippable)) { displayAsTool = equippable.DisplayAsTool; useDoppleganger = equippable.UseDoppleganger; //prep these just in case, doesn't cost us much equipPos += equippable.EquipOffset; equipRot += equippable.EquipRotation; //invert the equippable X equipPos.x = -equipPos.x; } //now, are we actually using a doppleganger? if (!displayAsTool) { BreakDownToolDoppleganger(); return; } else if (!useDoppleganger) { BreakDownToolDoppleganger(); worlditem.LockTransform(tr); worlditem.tr.localPosition = equipPos; worlditem.tr.localRotation = Quaternion.Euler(equipRot); worlditem.GetComponent <Rigidbody>().isKinematic = true; ToolColliders.AddRange(worlditem.Colliders); //and we're done return; } else { ToolDoppleganger = WorldItems.GetDoppleganger(worlditem, transform, ToolDoppleganger); ToolColliders.AddRange(ToolDoppleganger.GetComponentsInChildren <Collider> ()); //the equipped mode will apply equipped etc. offset //so don't bother to set that here ToolDoppleganger.SetActive(true); } } }
public void RefreshToolDoppleganger(bool equipping) { if (mDopplegangerLocked) { //rogue call, probably from OnModeChange or something return; } if (!equipping) { BreakDownToolDoppleganger(); //nothing else to do here return; } else if (!HasWorldItem) { BreakDownToolDoppleganger(); } else { //we're equippping and we have a worlditem bool useDoppleganger = true; bool displayAsTool = true; Vector3 equipPos = worlditem.Props.Global.PivotOffset; Vector3 equipRot = worlditem.Props.Global.BaseRotation; //Equippable equippable = null; if (worlditem.Is <Equippable>(out mEquippable)) { displayAsTool = mEquippable.DisplayAsTool; useDoppleganger = mEquippable.UseDoppleganger; //prep these just in case, doesn't cost us much equipPos += mEquippable.EquipOffset; equipRot += mEquippable.EquipRotation; } //now, are we actually using a doppleganger? if (!displayAsTool) { BreakDownToolDoppleganger(); return; } else if (!useDoppleganger) { //alright no doppleganger, but we still equip the worlditem as a tool BreakDownToolDoppleganger(); worlditem.LockTransform(tr); worlditem.tr.localPosition = equipPos; worlditem.tr.localRotation = Quaternion.Euler(equipRot); worlditem.GetComponent <Rigidbody>().isKinematic = true; ToolColliders.AddRange(worlditem.Colliders); //and we're done return; } else { //actually use doppleganger! here we go ToolDoppleganger = WorldItems.GetDoppleganger(worlditem, transform, ToolDoppleganger); ToolColliders.AddRange(ToolDoppleganger.GetComponentsInChildren <Collider>()); ToolActionPointObject = ToolDoppleganger.FindOrCreateChild("ToolActionPointObject"); //the equipped mode will apply equipped etc. offset //so don't bother to set that here ToolDoppleganger.SetActive(true); //get any tension morph animations TensionMorph = ToolDoppleganger.GetComponent <MegaMorph>(); if (TensionMorph != null) { TensionChannel = TensionMorph.GetChannel("Tension"); } //get any projectiles //Weapon weapon = null; if (worlditem.Is <Weapon>(out mWeapon)) { //update our action point //the action point is a gameobject in the weapon that indicates where hits collide //and/or where projectiles launch from - it's safe to access because it's a property ToolActionPointObject.transform.localPosition = mWeapon.ActionPointObject.transform.localPosition; ToolActionPointObject.transform.localRotation = mWeapon.ActionPointObject.transform.localRotation; if (HasProjectile) { //if we've found a projectile, create a doppleganger for it ProjectileDoppleganger = WorldItems.GetDoppleganger( ProjectileObject.PackName, ProjectileObject.PrefabName, ToolActionPointObject.transform, ProjectileDoppleganger, WIMode.Equipped, ProjectileObject.StackName, ProjectileObject.State, ProjectileObject.Subcategory, 1f, WorldClock.TimeOfDayCurrent, WorldClock.TimeOfYearCurrent); ProjectileDoppleganger.SetActive(true); } else if (ProjectileDoppleganger != null) { ProjectileDoppleganger.SetActive(false); } } else if (ProjectileDoppleganger != null) { ProjectileDoppleganger.SetActive(false); } } } }