using UnityEngine; namespace NBF { public static class PrefabCreator { // #region 轮 // // public static ReelAsset Create(this GameReels self, Transform parent, bool isPreview = false) // { // ReelAsset ret = null; // var prefab = self.Instantiate(parent); // // prefab.transform.localPosition = Vector3.zero; // prefab.transform.localRotation = Quaternion.identity; // // if (prefab.TryGetComponent(out var reel)) // { // ret = reel; // // if (!isPreview) // { // prefab.AddComponent(); // // prefab.AddJoint(); // // var dis = prefab.AddComponent(); // // dis.moveCharacteristic = FWaterDisplacement.MoveCharacteristic.Custom; // // dis.objectDisplacement = 2; // // dis.outwaterMass = 0.1f; // } // } // // return ret; // } // // #endregion // #region 浮漂 // // public static BobberAsset Create(this GameFloats self, Transform parent, bool isPreview = false) // { // BobberAsset ret = null; // var prefab = self.Instantiate(parent); // // prefab.transform.localPosition = Vector3.zero; // prefab.transform.localRotation = Quaternion.identity; // // if (prefab.TryGetComponent(out var lure)) // { // ret = lure; // // if (!isPreview) // { // prefab.AddComponent(); // prefab.AddJoint(); // var dis = prefab.AddComponent(); // dis.moveCharacteristic = FWaterDisplacement.MoveCharacteristic.Custom; // dis.objectDisplacement = 2; // dis.outwaterMass = 0.1f; // } // } // // return ret; // } // // #endregion // // // #region 饵 // // public static LureAsset Create(this GameLures self, Transform parent, bool isPreview = false) // { // LureAsset ret = null; // var prefab = self.Instantiate(parent); // // // if (prefab.TryGetComponent(out var lure)) // { // ret = lure; // // if (!isPreview) // { // prefab.AddComponent(); // prefab.AddJoint(); // var rigidbody = prefab.GetComponent(); // rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; // rigidbody.linearDamping = 0.5f; // var dis = prefab.AddComponent(); // // dis.moveCharacteristic = FWaterDisplacement.MoveCharacteristic.Custom; // // dis.objectDisplacement = 2; // dis.outwaterMass = 0.5f; // } // // if (lure.hookPoints != null && lure.hookPoints.Length > 0) // { // for (int i = 0; i < lure.hookPoints.Length; i++) // { // var hookPoint = lure.hookPoints[i]; // var hook = self.hook[0]; // var hookConfig = GameHooks.Get(hook); // var hookAsset = hookConfig.Create(hookPoint, true); // hookAsset.transform.localPosition = Vector3.zero; // hookAsset.transform.localRotation = Quaternion.identity; // var configurableJoint = hookAsset.GetComponent(); // configurableJoint.connectedBody = prefab.GetComponent(); // } // } // } // // return ret; // } // // public static BaitAsset Create(this GameBaits self, Transform parent, bool isPreview = false) // { // var prefab = self.Instantiate(parent); // BaitAsset ret = null; // if (prefab.TryGetComponent(out var hook)) // { // ret = hook; // } // // prefab.transform.localPosition = Vector3.zero; // prefab.transform.localRotation = Quaternion.identity; // if (!isPreview) // { // prefab.AddComponent(); // } // // return ret; // } // // #endregion // // #region 钩 // // public static HookAsset Create(this GameHooks self, Transform parent, bool isPreview = false) // { // var prefab = self.Instantiate(parent); // HookAsset ret = null; // if (prefab.TryGetComponent(out var hook)) // { // ret = hook; // } // // prefab.transform.localPosition = Vector3.zero; // prefab.transform.localRotation = Quaternion.identity; // if (!isPreview) // { // prefab.AddComponent(); // var d = prefab.AddComponent(); // d.outwaterMass = 0.1f; // } // // return ret; // } // // #endregion #region 工具 public static void AddJoint(this GameObject prefab) { var rigidbody = prefab.GetComponent(); if (rigidbody == null) { rigidbody = prefab.AddComponent(); } var configurableJoint = prefab.GetComponent(); if (configurableJoint == null) { configurableJoint = prefab.AddComponent(); } configurableJoint.xMotion = ConfigurableJointMotion.Locked; configurableJoint.yMotion = ConfigurableJointMotion.Locked; configurableJoint.zMotion = ConfigurableJointMotion.Locked; // configurableJoint.angularXMotion = ConfigurableJointMotion.Limited; // configurableJoint.angularYMotion = ConfigurableJointMotion.Limited; // configurableJoint.angularZMotion = ConfigurableJointMotion.Limited; } #endregion } }