Beispiel #1
0
        void AddSpringBone(Transform _trans)
        {
            if (_trans == null || _trans.childCount < 1)
            {
                return;
            }

            SpringBone _sb = _trans.GetComponent <SpringBone>();

            if (_sb == null)
            {
                _sb = _trans.gameObject.AddComponent <SpringBone>();
            }

            Transform _childTrans = _trans.GetChild(0);

            _sb.child = _childTrans;
            _sb.isUseEachBoneForceSettings = false;
            if (!addBones.Contains(_sb))
            {
                addBones.Add(_sb);
            }

            AddSpringBone(_childTrans);
        }
Beispiel #2
0
        void OnSceneGUI()
        {
            SpringBone _sb = target as SpringBone;

            Undo.RecordObject(_sb, "Move Spring Bone Radius");

            Transform _childTrans = _sb.child;

            if (_childTrans == null)
            {
                return;
            }
            Vector3 _oldPoint = _childTrans.TransformPoint(Vector3.up * _sb.radius);
            Vector3 _newPoint = Handles.FreeMoveHandle(_oldPoint, Quaternion.identity, 0.01f, pointSnap, Handles.DotCap);

            if ((_oldPoint - _newPoint).sqrMagnitude > 0f)
            {
                _sb.radius = _childTrans.InverseTransformPoint(_newPoint).magnitude;
            }
        }
Beispiel #3
0
        void AddSpringColider(Transform trans)
        {
            if (trans == null)
            {
                return;
            }

            SpringBone _sb = trans.GetComponent <SpringBone>();

            if (_sb != null)
            {
                return;
            }

            var col = trans.GetComponent <SpringCollider>();

            if (col == null)
            {
                col = trans.gameObject.AddComponent <SpringCollider>();
            }
        }
Beispiel #4
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();
        }