Example #1
0
        void OnSceneGUI()
        {
            SpringCollider _sc = target as SpringCollider;

            Undo.RecordObject(_sc, "Move Spring Collider Radius");
            Vector3 _oldPoint = _sc.transform.TransformPoint(Vector3.up * _sc.radius);
            Vector3 _newPoint = Handles.FreeMoveHandle(_oldPoint, Quaternion.identity, 0.01f, pointSnap, Handles.DotCap);

            if ((_oldPoint - _newPoint).sqrMagnitude > 0f)
            {
                _sc.radius = _sc.transform.InverseTransformPoint(_newPoint).magnitude;
            }
        }
Example #2
0
        void DoCopy()
        {
            if (from == null || to == null)
            {
                return;
            }
            //from - to
            Dictionary <SpringCollider, SpringCollider> _scDict = new Dictionary <SpringCollider, SpringCollider>();

            //spring collider
            SpringCollider[] _sces = from.GetComponentsInChildren <SpringCollider>();
            foreach (var token in _sces)
            {
                string    _path     = GetPath_FromTrans(token.transform);
                Transform _toTarget = to.Find(_path);
                if (_toTarget == null)
                {
                    _toTarget = AddByPath_ToTrans(_path, token.transform);
                }
                if (_toTarget != null)
                {
                    SpringCollider _addSC = _toTarget.gameObject.GetComponent <SpringCollider>();
                    if (_addSC == null)
                    {
                        _addSC = _toTarget.gameObject.AddComponent <SpringCollider>();
                    }
                    _addSC.radius = token.radius;
                    _scDict.Add(token, _addSC);
                }
            }

            //spring bones
            SpringBone[]      _sbs     = from.GetComponentsInChildren <SpringBone>();
            List <SpringBone> _addedSB = new List <SpringBone>();

            foreach (var token in _sbs)
            {
                string    _path     = GetPath_FromTrans(token.transform);
                Transform _toTarget = to.Find(_path);
                if (_toTarget == null)
                {
                    _toTarget = AddByPath_ToTrans(_path, token.transform);
                }

                if (_toTarget != null)
                {
                    SpringBone _addSB = _toTarget.gameObject.GetComponent <SpringBone>();
                    if (_addSB == null)
                    {
                        _addSB = _toTarget.gameObject.AddComponent <SpringBone>();
                    }
                    _addSB.boneAxis = token.boneAxis;
                    _addSB.radius   = token.radius;
                    _addSB.isUseEachBoneForceSettings = token.isUseEachBoneForceSettings;
                    _addSB.stiffnessForce             = token.stiffnessForce;
                    _addSB.dragForce   = token.dragForce;
                    _addSB.springForce = token.springForce;
                    _addSB.threshold   = token.threshold;
                    _addSB.debug       = token.debug;
                    //set colliders
                    if (token.colliders != null && token.colliders.Length > 0)
                    {
                        _addSB.colliders = new SpringCollider[token.colliders.Length];
                        for (int i = 0, imax = token.colliders.Length; i < imax; ++i)
                        {
                            if (_scDict.ContainsKey(token.colliders[i]))
                            {
                                _addSB.colliders[i] = _scDict[token.colliders[i]];
                            }
                            else
                            {
                                Debug.Log("Error Get Collider");
                            }
                        }
                    }

                    //set child
                    _path = GetPath_FromTrans(token.child);
                    Transform _tmpChild = to.Find(_path);
                    if (_tmpChild == null)
                    {
                        _tmpChild = AddByPath_ToTrans(_path, token.child);
                    }
                    if (_tmpChild != null)
                    {
                        _addSB.child = _tmpChild;
                    }

                    _addedSB.Add(_addSB);
                }
            }

            SpringManager _fromSM    = from.GetComponentInChildren <SpringManager>();
            string        _smPath    = GetPath_FromTrans(_fromSM.transform);
            Transform     _toSMTrans = AddByPath_ToTrans(_smPath, _fromSM.transform);

            if (_toSMTrans == null)
            {
                _toSMTrans = to;
            }
            SpringManager _toSM = _toSMTrans.gameObject.AddComponent <SpringManager>();

            _toSM.dynamicRatio   = _fromSM.dynamicRatio;
            _toSM.stiffnessForce = _fromSM.stiffnessForce;
            _toSM.stiffnessCurve = new AnimationCurve(_fromSM.stiffnessCurve.keys);
            _toSM.dragForce      = _fromSM.dragForce;
            _toSM.dragCurve      = new AnimationCurve(_fromSM.dragCurve.keys);
            _toSM.debug          = _fromSM.debug;
            _toSM.springBones    = _addedSB.ToArray();
        }