void OpenIKWindow(bl_NetworkGun script) { AnimatorRunner window = (AnimatorRunner)EditorWindow.GetWindow(typeof(AnimatorRunner)); window.Show(); bl_PlayerSync pa = script.transform.root.GetComponent <bl_PlayerSync>(); Animator anim = pa.m_PlayerAnimation.m_animator; pa.m_PlayerAnimation.EditorSelectedGun = script; bl_PlayerIK hm = pa.m_PlayerAnimation.GetComponentInChildren <bl_PlayerIK>(true); if (hm != null) { hm.enabled = true; } window.SetAnim(anim); Selection.activeObject = script.LeftHandPosition.gameObject; }
void SetUpModelInPrefab() { #if UNITY_2018_3_OR_NEWER PrefabUtility.UnpackPrefabInstance(PlayerModel, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); #endif GameObject TempPlayerPrefab = PlayerInstantiated; GameObject TempPlayerModel = PlayerModel; //change name of prefabs to identify PlayerInstantiated.gameObject.name += " [NEW]"; PlayerModel.name += " [NEW]"; // get the current player model GameObject RemoteChildPlayer = TempPlayerPrefab.GetComponentInChildren <bl_PlayerAnimations>().gameObject; GameObject ActualModel = TempPlayerPrefab.GetComponentInChildren <bl_PlayerIK>().gameObject; Transform NetGunns = TempPlayerPrefab.GetComponent <bl_PlayerSync>().NetworkGuns[0].transform.parent; //set the new model to the same position as the current model TempPlayerModel.transform.parent = RemoteChildPlayer.transform; TempPlayerModel.transform.localPosition = ActualModel.transform.localPosition; TempPlayerModel.transform.localRotation = ActualModel.transform.localRotation; //add and copy components of actual player model bl_PlayerIK ahl = ActualModel.GetComponent <bl_PlayerIK>(); if (TempPlayerModel.GetComponent <Animator>() == null) { TempPlayerModel.AddComponent <Animator>(); } Animator NewAnimator = TempPlayerModel.GetComponent <Animator>(); if (ahl != null) { bl_PlayerIK newht = TempPlayerModel.AddComponent <bl_PlayerIK>(); newht.Target = ahl.Target; newht.Body = ahl.Body; newht.Weight = ahl.Weight; newht.Head = ahl.Head; newht.Lerp = ahl.Lerp; newht.Eyes = ahl.Eyes; newht.Clamp = ahl.Clamp; newht.useFootPlacement = ahl.useFootPlacement; newht.FootDownOffset = ahl.FootDownOffset; newht.FootHeight = ahl.FootHeight; newht.FootLayers = ahl.FootLayers; newht.PositionWeight = ahl.PositionWeight; newht.RotationWeight = ahl.RotationWeight; newht.AimSightPosition = ahl.AimSightPosition; newht.HandOffset = ahl.HandOffset; newht.TerrainOffset = ahl.TerrainOffset; newht.Radious = ahl.Radious; Animator oldAnimator = ActualModel.GetComponent <Animator>(); NewAnimator.runtimeAnimatorController = oldAnimator.runtimeAnimatorController; NewAnimator.applyRootMotion = oldAnimator.hasRootMotion; if (NewAnimator.avatar == null) { NewAnimator.avatar = oldAnimator.avatar; Debug.LogWarning("Your new model doesn't have a avatar, that can cause some problems with the animations, be sure to add it manually."); } } Transform RightHand = NewAnimator.GetBoneTransform(HumanBodyBones.RightHand); if (RightHand == null) { Debug.Log("Can't get right hand from new model, are u sure that is an humanoid rig?"); return; } bl_PlayerAnimations pa = TempPlayerPrefab.transform.GetComponentInChildren <bl_PlayerAnimations>(); bl_BodyPartManager bdm = TempPlayerPrefab.transform.GetComponentInChildren <bl_BodyPartManager>(); pa.m_animator = NewAnimator; bdm.m_Animator = NewAnimator; bdm.GetRequireBones(); bdm.mRigidBody.Clear(); bdm.HitBoxs.Clear(); bdm.mRigidBody.AddRange(GetRigidBodys(TempPlayerModel.transform)); Collider[] allColliders = GetCollider(TempPlayerModel.transform); if (allColliders == null || allColliders.Length <= 0) { Debug.Log("New player model prefab is not rag-dolled, to continue please create a rag-doll of it."); return; } foreach (Collider c in allColliders) { if (c.gameObject.tag != bl_BodyPartManager.HitBoxTag) { c.gameObject.tag = bl_BodyPartManager.HitBoxTag; } bl_BodyPartManager.Part p = new bl_BodyPartManager.Part(); p.m_Collider = c; p.name = c.name; c.gameObject.layer = LayerMask.NameToLayer("Player"); if (c.gameObject.name.ToLower().Contains("head")) { p.m_HeatShot = true; p.m_Multipler = 50; } bdm.HitBoxs.Add(p); } bdm.AddScript(); if (RightHand != null) { NetGunns.parent = RightHand; NetGunns.localPosition = Vector3.zero; NetGunns.rotation = RightHand.rotation; } else { Debug.Log("Can't find right hand"); } ActualModel.name += " (DELETE THIS)"; ActualModel.SetActive(false); var view = (SceneView)SceneView.sceneViews[0]; view.LookAt(ActualModel.transform.position); view.ShowNotification(new GUIContent("Player Setup")); }