示例#1
0
 private void Awake()
 {
     trs           = transform;
     localRotation = transform.localRotation;
     //Kobayashi:Reference for "SpringManager" component with unitychan
     // GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
     // managerRef = GetParentSpringManager(transform);
     managerRef = GetComponentInParent <SpringManager>();
 }
示例#2
0
 private void OnFocus()
 {
     if (sManager == null)
     {
         sManager = GameObject.FindObjectOfType <SpringManager>();
         if (sManager != null)
         {
             sManagerGo = sManager.gameObject;
         }
     }
 }
示例#3
0
        void OnGUI()
        {
            //GUILayout.BeginHorizontal();
            if (GUILayout.Button("自动配置选中结点"))
            {
                DoConfig();
            }

            if (GUILayout.Button("更新角色配置"))
            {
                DoUpdate();
            }

            if (GUILayout.Button("为选中结点添加SpringCollider"))
            {
                Object[] _selecedOBs = Selection.objects;


                foreach (var token in _selecedOBs)
                {
                    var _tmpGo = token as GameObject;
                    if (_tmpGo != null)
                    {
                        AddSpringColider(_tmpGo.transform);
                    }
                }
            }

            //if (GUILayout.Button("+", GUILayout.Width(50)))
            //{
            //    Object[] _selecedOBs = Selection.objects;
            //    if (_selecedOBs != null && _selecedOBs.Length > 0)
            //    {
            //        foreach (var token in _selecedOBs)
            //        {
            //            if (token is GameObject && !springRoots.Contains(token as GameObject))
            //            {
            //                springRoots.Add(token as GameObject);
            //            }
            //        }
            //    }
            //}

            //GUILayout.EndHorizontal();

            scrollPos = GUILayout.BeginScrollView(scrollPos);
            EditorGUI.BeginChangeCheck();
            sManagerGo = EditorGUILayout.ObjectField("SpringManager", sManagerGo, typeof(GameObject), true) as GameObject;
            if (EditorGUI.EndChangeCheck())
            {
                if (sManagerGo != null)
                {
                    sManager = sManagerGo.GetComponent <SpringManager>();
                    if (sManager == null)
                    {
                        sManager = sManagerGo.AddComponent <SpringManager>();
                    }
                }
                else
                {
                    sManager = null;
                }
            }
            GUILayout.Label("Spring Roots");
            if (sManager != null && sManager.springBones != null && sManager.springBones.Length > 0)
            {
                for (int i = 0, imax = sManager.springBones.Length; i < imax; ++i)
                {
                    EditorGUILayout.ObjectField(i.ToString(), sManager.springBones[i], typeof(GameObject), true);
                }
            }
            else
            {
                GUILayout.Label("   没有配置节点");
            }
            GUILayout.EndScrollView();
        }
示例#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();
        }