//void OnEnable()
    //{
    //    // Setup the SerializedProperties.
    //    transformsField = serializedObject.FindProperty("transforms");
    //}

    public override void OnInspectorGUI()
    {
        Neuron.NeuronTransformsInstance script = (Neuron.NeuronTransformsInstance)target;

        bool preUseNewRig = script.useNewRig;

        DrawDefaultInspector();
        if (preUseNewRig != script.useNewRig)
        {
            if (script.root == null)
            {
                script.root = script.transform;
            }

            for (int i = 0; i < script.transforms.Length; i++)
            {
                script.transforms[i] = null;
            }
            script.Bind(script.transform, script.prefix);

            EditorUtility.SetDirty(script);

            UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
        }
        if (GUILayout.Button("bind"))
        {
            Debug.Log("[NeuronTransformsInstanceVR] - LOAD all Transform references into the bones list!");

            script.Bind(script.transform, script.prefix);

            EditorUtility.SetDirty(script);

            UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
        }

        // 这种做法适合不定长数组,对定长数组不起作用
        //EditorGUILayout.PropertyField(serializedObject.FindProperty("transforms"), new GUIContent("transforms"), true);
        serializedObject.Update();
        transformsField = serializedObject.FindProperty("transforms");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("transforms"), new GUIContent("transforms"), true);

        EditorGUI.indentLevel += 1;
        // if (transformsField.isExpanded)
        {
            //EditorGUILayout.PropertyField(transformsField.FindPropertyRelative("Array.size"));
            for (int i = 0; i < transformsField.arraySize; i++)
            {
                if (script.useNewRig && (i == (int)Neuron.NeuronBones.Spine3 || i == (int)Neuron.NeuronBones.Neck))
                {
                    EditorGUILayout.PropertyField(transformsField.GetArrayElementAtIndex(i), new GUIContent(((Neuron.NeuronBonesV2)i).ToString()));
                }
                else
                {
                    EditorGUILayout.PropertyField(transformsField.GetArrayElementAtIndex(i), new GUIContent(((Neuron.NeuronBones)i).ToString()));
                }
            }
        }
        EditorGUI.indentLevel -= 1;
        serializedObject.ApplyModifiedProperties();
    }
Пример #2
0
        public static void AddSkeletonBoneLines(Transform root, string prefix, Color color, int render_queue_plus, float parent_width, float child_width)
        {
            Material line_material = GetBoneLineMaterial(color, render_queue_plus);

            if (line_material)
            {
                int counter = NSH.AddBonesComponentsTransform <BoneLine>(root, prefix, delegate_add_bone_line_transform, line_material, parent_width, child_width);
                NeuronTransformsInstance instance = root.GetComponent <NeuronTransformsInstance>();
                instance.Bind(root, prefix);
                Transform t = instance.transforms[(int)NeuronBones.Head];
                if (t != null && t.childCount > 0)
                {
                    // get end_end
                    Transform child = t.GetChild(0);
                    if (child != null)
                    {
                        BoneLine boneline = child.gameObject.AddComponent <BoneLine>();
                        boneline.AddRenderer(line_material, parent_width, child_width, t, child);
                        counter++;
                    }
                }

                Debug.Log(string.Format("[NeuronUtilities] {0} Bone lines added to {1}.", counter, root.name), root);
            }
        }