public Bounds OnGetFrameBounds()
        {
            SPCRJointDynamicsCollider jointCollider = (SPCRJointDynamicsCollider)target;
            Bounds bounds = new Bounds(jointCollider.transform.position, new Vector3(jointCollider.Radius, jointCollider.Height, jointCollider.Radius));

            return(bounds);
        }
        static SPCRJointDynamicsCollider CreateNewCollider(SPCRJointDynamicsColliderSave colliderData)
        {
            GameObject colliderObject          = new GameObject();
            SPCRJointDynamicsCollider collider = colliderObject.AddComponent <SPCRJointDynamicsCollider>();

            colliderData.AssignTransformData(collider.transform);
            collider.SetGUIIIde(colliderData.RefUniqueId);
            return(collider);
        }
 void UpdateToggle(string Label, SPCRJointDynamicsCollider Source, ref bool Value, bool Reverse = false)
 {
     if (Reverse)
     {
         Value = !EditorGUILayout.Toggle(Label, !Value);
     }
     else
     {
         Value = EditorGUILayout.Toggle(Label, Value);
     }
 }
        void UpdateSlider(string Label, SPCRJointDynamicsCollider Source, ref float Value, float Min, float Max)
        {
            EditorGUI.BeginChangeCheck();
            float Newvalue = EditorGUILayout.Slider(Label, Value, Min, Max);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "SPCRColliderUndo");
                Value = Newvalue;
            }
        }
            public SPCRJointDynamicsColliderSave(SPCRJointDynamicsCollider spcrJoinDynamicsCollider)
            {
                if (spcrJoinDynamicsCollider != null)
                {
                    if (string.IsNullOrEmpty(spcrJoinDynamicsCollider.UniqueGUIID))
                    {
                        spcrJoinDynamicsCollider.Reset();
                    }
                    RefUniqueId = spcrJoinDynamicsCollider.UniqueGUIID;
                    Radius      = spcrJoinDynamicsCollider.RadiusRaw;
                    Height      = spcrJoinDynamicsCollider.HeightRaw;
                    Friction    = spcrJoinDynamicsCollider.FrictionRaw;
                    ForceType   = spcrJoinDynamicsCollider._SurfaceColliderForce;

                    SaveTransformData(spcrJoinDynamicsCollider.transform);
                }
                else
                {
                    RefUniqueId = INVALID_ID;
                }
            }
        public static void Load(SPCRJointDynamicsController SPCRJointDynamicsContoller)
        {
            SPCRJointDynamicsControllerSave spcrJointDynamicsSave = LoadBinary();

            if (spcrJointDynamicsSave == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(SPCRJointDynamicsContoller.Name))
            {
                SPCRJointDynamicsContoller.Name = spcrJointDynamicsSave.name;
            }

            GameObject RootGameObject = GameObject.Find(spcrJointDynamicsSave.rootTransformName);

            if (RootGameObject != null)
            {
                SPCRJointDynamicsContoller._RootTransform = RootGameObject.transform;
            }

            globalUniqueIdList = GetGlobalUniqueIdComponentList();

            if (spcrJointDynamicsSave.spcrChildJointDynamicsPointList != null)
            {
                for (int i = 0; i < spcrJointDynamicsSave.spcrChildJointDynamicsPointList.Length; i++)
                {
                    SPCRJointDynamicsPoint point      = (SPCRJointDynamicsPoint)globalUniqueIdList.Find(obj => obj.GetType() == typeof(SPCRJointDynamicsPoint) && ((SPCRJointDynamicsPoint)obj).UniqueGUIID.Equals(spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].RefUniqueID));
                    SPCRJointDynamicsPoint ChildPoint = (SPCRJointDynamicsPoint)globalUniqueIdList.Find(obj => obj.GetType() == typeof(SPCRJointDynamicsPoint) && ((SPCRJointDynamicsPoint)obj).UniqueGUIID.Equals(spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].refChildID));
                    if (point != null)
                    {
                        point._Mass                   = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].mass;
                        point._RefChildPoint          = ChildPoint;
                        point._IsFixed                = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].IsFixed;
                        point._BoneAxis               = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].BoneAxis.ToUnityVector3();
                        point._Depth                  = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].Depth;
                        point._Index                  = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].Index;
                        point._UseForSurfaceCollision = spcrJointDynamicsSave.spcrChildJointDynamicsPointList[i].UseForSurfaceCollision;
                    }
                }
            }

            if (spcrJointDynamicsSave.spcrChildJointDynamicsColliderList != null)
            {
                List <SPCRJointDynamicsCollider> colliderTable = new List <SPCRJointDynamicsCollider>();
                for (int i = 0; i < spcrJointDynamicsSave.spcrChildJointDynamicsColliderList.Length; i++)
                {
                    SPCRJointDynamicsCollider point = (SPCRJointDynamicsCollider)globalUniqueIdList.Find(obj => obj.GetType() == typeof(SPCRJointDynamicsCollider) && ((SPCRJointDynamicsCollider)obj).UniqueGUIID.Equals(spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i].RefUniqueId));
                    if (point == null)
                    {
                        point = CreateNewCollider(spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i]);
                    }
                    point.RadiusRaw             = spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i].Radius;
                    point.HeightRaw             = spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i].Height;
                    point.FrictionRaw           = spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i].Friction;
                    point._SurfaceColliderForce = spcrJointDynamicsSave.spcrChildJointDynamicsColliderList[i].ForceType;

                    if (!colliderTable.Contains(point))
                    {
                        colliderTable.Add(point);
                    }
                }
                if (colliderTable.Count > 0)
                {
                    SPCRJointDynamicsContoller._ColliderTbl = colliderTable.ToArray();
                }
            }

            if (spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList != null)
            {
                List <SPCRJointDynamicsPointGrabber> grabberList = new List <SPCRJointDynamicsPointGrabber>();
                for (int i = 0; i < spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList.Length; i++)
                {
                    SPCRJointDynamicsPointGrabber point = (SPCRJointDynamicsPointGrabber)globalUniqueIdList.Find(obj => obj.GetType() == typeof(SPCRJointDynamicsPointGrabber) && ((SPCRJointDynamicsPointGrabber)obj).UniqueGUIID.Equals(spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList[i].RefUniqueGUIID));
                    if (point == null)
                    {
                        point = CreateNewGrabber(spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList[i]);
                    }
                    point.IsEnabled = spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList[i].IsEnabled;
                    point.RadiusRaw = spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList[i].Radius;
                    point.Force     = spcrJointDynamicsSave.spcrChildJointDynamicsPointGtabberList[i].Force;

                    grabberList.Add(point);
                }
                if (grabberList.Count > 0)
                {
                    SPCRJointDynamicsContoller._PointGrabberTbl = grabberList.ToArray();
                }
            }

            if (spcrJointDynamicsSave.RootPointTbl != null)
            {
                List <SPCRJointDynamicsPoint> pointList = new List <SPCRJointDynamicsPoint>();
                for (int i = 0; i < spcrJointDynamicsSave.RootPointTbl.Length; i++)
                {
                    SPCRJointDynamicsPoint point = (SPCRJointDynamicsPoint)globalUniqueIdList.Find(obj => obj.GetType() == typeof(SPCRJointDynamicsPoint) && ((SPCRJointDynamicsPoint)obj).UniqueGUIID.Equals(spcrJointDynamicsSave.RootPointTbl[i]));
                    if (point == null)
                    {
                        continue;
                    }
                    pointList.Add(point);
                }
                if (pointList.Count > 0)
                {
                    SPCRJointDynamicsContoller._RootPointTbl = pointList.ToArray();
                }
            }
            else
            {
                SPCRJointDynamicsContoller._RootPointTbl = new SPCRJointDynamicsPoint[0];
            }

            SPCRJointDynamicsContoller._Relaxation = spcrJointDynamicsSave.Relaxation;
            SPCRJointDynamicsContoller._SubSteps   = spcrJointDynamicsSave.SubSteps;

            //@SPCRJointDynamicsContoller._IsEnablePointCollision = spcrJointDynamicsSave.IsEnablePointCollision;
            //@SPCRJointDynamicsContoller._DetailHitDivideMax = spcrJointDynamicsSave.DetailHitDivideMax;

            SPCRJointDynamicsContoller._IsCancelResetPhysics     = spcrJointDynamicsSave.IsCancelResetPhysics;
            SPCRJointDynamicsContoller._IsEnableSurfaceCollision = spcrJointDynamicsSave.IsEnableSurfaceCollision;
            SPCRJointDynamicsContoller._SurfaceCollisionDivision = spcrJointDynamicsSave.SurfaceCollisionDivision;

            SPCRJointDynamicsContoller._MassScaleCurve    = GetAnimCurve(spcrJointDynamicsSave.MassScaleCurve);
            SPCRJointDynamicsContoller._GravityScaleCurve = GetAnimCurve(spcrJointDynamicsSave.GravityScaleCurve);
            SPCRJointDynamicsContoller._ResistanceCurve   = GetAnimCurve(spcrJointDynamicsSave.ResistanceCurve);
            SPCRJointDynamicsContoller._HardnessCurve     = GetAnimCurve(spcrJointDynamicsSave.HardnessCurve);
            SPCRJointDynamicsContoller._FrictionCurve     = GetAnimCurve(spcrJointDynamicsSave.FrictionCurve);

            SPCRJointDynamicsContoller._AllShrinkScaleCurve  = GetAnimCurve(spcrJointDynamicsSave.AllShrinkScaleCurve);
            SPCRJointDynamicsContoller._AllStretchScaleCurve = GetAnimCurve(spcrJointDynamicsSave.AllStretchScaleCurve);
            SPCRJointDynamicsContoller._StructuralShrinkVerticalScaleCurve    = GetAnimCurve(spcrJointDynamicsSave.StructuralShrinkVerticalScaleCurve);
            SPCRJointDynamicsContoller._StructuralStretchVerticalScaleCurve   = GetAnimCurve(spcrJointDynamicsSave.StructuralStretchVerticalScaleCurve);
            SPCRJointDynamicsContoller._StructuralShrinkHorizontalScaleCurve  = GetAnimCurve(spcrJointDynamicsSave.StructuralShrinkHorizontalScaleCurve);
            SPCRJointDynamicsContoller._StructuralStretchHorizontalScaleCurve = GetAnimCurve(spcrJointDynamicsSave.StructuralStretchHorizontalScaleCurve);
            SPCRJointDynamicsContoller._ShearShrinkScaleCurve              = GetAnimCurve(spcrJointDynamicsSave.ShearShrinkScaleCurve);
            SPCRJointDynamicsContoller._ShearStretchScaleCurve             = GetAnimCurve(spcrJointDynamicsSave.ShearStretchScaleCurve);
            SPCRJointDynamicsContoller._BendingShrinkVerticalScaleCurve    = GetAnimCurve(spcrJointDynamicsSave.BendingShrinkVerticalScaleCurve);
            SPCRJointDynamicsContoller._BendingStretchVerticalScaleCurve   = GetAnimCurve(spcrJointDynamicsSave.BendingStretchVerticalScaleCurve);
            SPCRJointDynamicsContoller._BendingShrinkHorizontalScaleCurve  = GetAnimCurve(spcrJointDynamicsSave.BendingShrinkHorizontalScaleCurve);
            SPCRJointDynamicsContoller._BendingStretchHorizontalScaleCurve = GetAnimCurve(spcrJointDynamicsSave.BendingStretchHorizontalScaleCurve);

            SPCRJointDynamicsContoller._Gravity   = spcrJointDynamicsSave.Gravity.ToUnityVector3();
            SPCRJointDynamicsContoller._WindForce = spcrJointDynamicsSave.WindForce.ToUnityVector3();

            SPCRJointDynamicsContoller._RootSlideLimit  = spcrJointDynamicsSave.RootSlideLimit;
            SPCRJointDynamicsContoller._RootRotateLimit = spcrJointDynamicsSave.RootRotateLimit;

            SPCRJointDynamicsContoller._StructuralShrinkVertical    = spcrJointDynamicsSave.StructuralShrinkVertical;
            SPCRJointDynamicsContoller._StructuralStretchVertical   = spcrJointDynamicsSave.StructuralStretchVertical;
            SPCRJointDynamicsContoller._StructuralShrinkHorizontal  = spcrJointDynamicsSave.StructuralShrinkHorizontal;
            SPCRJointDynamicsContoller._StructuralStretchHorizontal = spcrJointDynamicsSave.StructuralStretchHorizontal;
            SPCRJointDynamicsContoller._ShearShrink              = spcrJointDynamicsSave.ShearShrink;
            SPCRJointDynamicsContoller._ShearStretch             = spcrJointDynamicsSave.ShearStretch;
            SPCRJointDynamicsContoller._BendingShrinkVertical    = spcrJointDynamicsSave.BendingShrinkVertical;
            SPCRJointDynamicsContoller._BendingStretchVertical   = spcrJointDynamicsSave.BendingStretchVertical;
            SPCRJointDynamicsContoller._BendingShrinkHorizontal  = spcrJointDynamicsSave.BendingShrinkHorizontal;
            SPCRJointDynamicsContoller._BendingStretchHorizontal = spcrJointDynamicsSave.BendingStretchHorizontal;

            SPCRJointDynamicsContoller._IsAllStructuralShrinkVertical    = spcrJointDynamicsSave.IsAllStructuralShrinkVertical;
            SPCRJointDynamicsContoller._IsAllStructuralStretchVertical   = spcrJointDynamicsSave.IsAllStructuralStretchVertical;
            SPCRJointDynamicsContoller._IsAllStructuralShrinkHorizontal  = spcrJointDynamicsSave.IsAllStructuralShrinkHorizontal;
            SPCRJointDynamicsContoller._IsAllStructuralStretchHorizontal = spcrJointDynamicsSave.IsAllStructuralStretchHorizontal;
            SPCRJointDynamicsContoller._IsAllShearShrink              = spcrJointDynamicsSave.IsAllShearShrink;
            SPCRJointDynamicsContoller._IsAllShearStretch             = spcrJointDynamicsSave.IsAllShearStretch;
            SPCRJointDynamicsContoller._IsAllBendingShrinkVertical    = spcrJointDynamicsSave.IsAllBendingShrinkVertical;
            SPCRJointDynamicsContoller._IsAllBendingStretchVertical   = spcrJointDynamicsSave.IsAllBendingStretchVertical;
            SPCRJointDynamicsContoller._IsAllBendingShrinkHorizontal  = spcrJointDynamicsSave.IsAllBendingShrinkHorizontal;
            SPCRJointDynamicsContoller._IsAllBendingStretchHorizontal = spcrJointDynamicsSave.IsAllBendingStretchHorizontal;

            SPCRJointDynamicsContoller._IsCollideStructuralVertical   = spcrJointDynamicsSave.IsCollideStructuralVertical;
            SPCRJointDynamicsContoller._IsCollideStructuralHorizontal = spcrJointDynamicsSave.IsCollideStructuralHorizontal;
            SPCRJointDynamicsContoller._IsCollideShear = spcrJointDynamicsSave.IsCollideShear;

            SPCRJointDynamicsContoller._IsLoopRootPoints              = spcrJointDynamicsSave.IsLoopRootPoints;
            SPCRJointDynamicsContoller._IsComputeStructuralVertical   = spcrJointDynamicsSave.IsComputeStructuralVertical;
            SPCRJointDynamicsContoller._IsComputeStructuralHorizontal = spcrJointDynamicsSave.IsComputeStructuralHorizontal;
            SPCRJointDynamicsContoller._IsComputeShear             = spcrJointDynamicsSave.IsComputeShear;
            SPCRJointDynamicsContoller._IsComputeBendingVertical   = spcrJointDynamicsSave.IsComputeBendingVertical;
            SPCRJointDynamicsContoller._IsComputeBendingHorizontal = spcrJointDynamicsSave.IsComputeBendingHorizontal;

            SPCRJointDynamicsContoller._IsDebugDraw_StructuralVertical   = spcrJointDynamicsSave.IsDebugDraw_StructuralVertical;
            SPCRJointDynamicsContoller._IsDebugDraw_StructuralHorizontal = spcrJointDynamicsSave.IsDebugDraw_StructuralHorizontal;
            SPCRJointDynamicsContoller._IsDebugDraw_Shear                 = spcrJointDynamicsSave.IsDebugDraw_Shear;
            SPCRJointDynamicsContoller._IsDebugDraw_BendingVertical       = spcrJointDynamicsSave.IsDebugDraw_BendingVertical;
            SPCRJointDynamicsContoller._IsDebugDraw_BendingHorizontal     = spcrJointDynamicsSave.IsDebugDraw_BendingHorizontal;
            SPCRJointDynamicsContoller._IsDebugDraw_SurfaceFace           = spcrJointDynamicsSave.IsDebugDraw_SurfaceFace;
            SPCRJointDynamicsContoller._Debug_SurfaceNormalLength         = spcrJointDynamicsSave.Debug_SurfaceNoramlLength;
            SPCRJointDynamicsContoller._IsDebugDraw_RuntimeColliderBounds = spcrJointDynamicsSave.IsDebugDraw_RuntimeColliderBounds;

            if (spcrJointDynamicsSave.ConstraintTable != null)
            {
                SPCRJointDynamicsContoller.ConstraintTable = new SPCRJointDynamicsJob.Constraint[spcrJointDynamicsSave.ConstraintTable.Length][];
                for (int i = 0; i < spcrJointDynamicsSave.ConstraintTable.Length; i++)
                {
                    SPCRJointDynamicsContoller.ConstraintTable[i] = new SPCRJointDynamicsJob.Constraint[spcrJointDynamicsSave.ConstraintTable[i].Length];
                    for (int j = 0; j < spcrJointDynamicsSave.ConstraintTable[i].Length; j++)
                    {
                        SPCRJointDynamicsContoller.ConstraintTable[i][j] = spcrJointDynamicsSave.ConstraintTable[i][j].ConvertToJobConstraint();
                    }
                }
            }

            SPCRJointDynamicsContoller.MaxPointDepth = spcrJointDynamicsSave.MaxPointDepth;

            SPCRJointDynamicsContoller._UseLimitAngles  = spcrJointDynamicsSave.UseLimitAngles;
            SPCRJointDynamicsContoller._LimitAngle      = spcrJointDynamicsSave.LimitAngle;
            SPCRJointDynamicsContoller._LimitFromRoot   = spcrJointDynamicsSave.LimitFromRoot;
            SPCRJointDynamicsContoller._LimitPowerCurve = GetAnimCurve(spcrJointDynamicsSave.LimitPowerCurve);

            globalUniqueIdList.Clear();
        }