Пример #1
0
        public void TraverseHierarchy(Transform root)
        {
            Control globalControl = root.transform.GetComponent <Control>();

            _Controls.Add(globalControl);

            foreach (Transform child in root)
            {
                GameObject Go = child.gameObject;

                Control control = Go.transform.GetComponent <Control>();
                _Controls.Add(control);

                Bone bone = Go.transform.GetComponent <Bone>();
                _Bones.Add(bone);

                ParentControl newParentCtrl = Go.transform.GetComponent <ParentControl>();

                if (newParentCtrl)
                {
                    _ParentControls.Add(newParentCtrl);
                }
                IKControl newIKCtrl = Go.transform.GetComponent <IKControl>();
                if (newIKCtrl)
                {
                    _Ikhandles.Add(newIKCtrl);
                }


                SplineControl splineCtrl = Go.transform.GetComponent <SplineControl>();
                if (splineCtrl)
                {
                    _SplineControls.Add(splineCtrl);
                }

                IKFKBlend ikfkBlend = Go.transform.GetComponent <IKFKBlend>();
                if (ikfkBlend)
                {
                    _IKFKBlends.Add(ikfkBlend);
                }

                DrivenKey newDrivenKey = Go.transform.GetComponent <DrivenKey>();

                if (newDrivenKey)
                {
                    _DrivenKeys.Add(newDrivenKey);
                }

                TraverseHierarchy(child);
            }
        }
Пример #2
0
        public static void CreateOrientControl(float DefaultScale = 1f)
        {
            GameObject bone = Selection.activeObject as GameObject;

            if (bone)
            {
                if (!bone.GetComponent <Bone>())
                {
                    Debug.LogWarning("This is not a Puppet3D Bone");
                    return;
                }
            }
            else
            {
                Debug.LogWarning("This is not a Puppet3D Bone");
                return;
            }
            GameObject globalCtrl = CreateGlobalControl();

            foreach (IKControl ikhandle in globalCtrl.GetComponent <GlobalControl>()._Ikhandles)
            {
                if ((ikhandle.bottomJointTransform == bone.transform) || (ikhandle.middleJointTransform == bone.transform))
                {
                    Debug.LogWarning("Can't create a orient Control on Bone; it alreay has an IK handle");
                    return;
                }
            }
            foreach (ParentControl parentControl in globalCtrl.GetComponent <GlobalControl>()._ParentControls)
            {
                if ((parentControl.bone.transform == bone.transform))
                {
                    Debug.LogWarning("Can't create a Parent Control on Bone; it alreay has an Parent Control");
                    return;
                }
            }
            foreach (SplineControl splineCtrl in globalCtrl.GetComponent <GlobalControl>()._SplineControls)
            {
                foreach (GameObject splineBone in splineCtrl.bones)
                {
                    if (splineBone.transform == bone.transform)
                    {
                        Debug.LogWarning(bone.transform.parent.transform.parent.name + " has a Spline control attached");
                        return;
                    }
                }
            }

            GameObject control = new GameObject();

            Undo.RegisterCreatedObjectUndo(control, "Created control");
            control.name = (bone.name + "_CTRL");
            GameObject controlGroup = new GameObject();

            Undo.RegisterCreatedObjectUndo(controlGroup, "Created controlGroup");
            controlGroup.name               = (bone.name + "_CTRL_GRP");
            control.transform.parent        = controlGroup.transform;
            controlGroup.transform.position = bone.transform.position;
            controlGroup.transform.rotation = bone.transform.rotation;

            ParentControl parentConstraint = control.AddComponent <ParentControl>();

            parentConstraint.Orient      = true;
            parentConstraint.Point       = false;
            parentConstraint.bone        = bone;
            parentConstraint.HandleScale = Vector3.one * DefaultScale;

            Selection.activeObject       = control;
            parentConstraint.OffsetScale = bone.transform.localScale;

            controlGroup.transform.parent = globalCtrl.transform;

            if (globalCtrl.GetComponent <GlobalControl>().AutoRefresh)
            {
                globalCtrl.GetComponent <GlobalControl>().Init();
            }
            else
            {
                globalCtrl.GetComponent <GlobalControl>()._ParentControls.Add(parentConstraint);
            }
        }