예제 #1
0
    private void InspectorSelectedPointGUI()
    {
        if ((_target == null) || (_target.points == null) || (_target.points.Count == 0))
        {
            return;
        }

        GUIStyle s = new GUIStyle(EditorStyles.largeLabel);

        s.fontStyle = FontStyle.Bold;

        EditorGUILayout.LabelField("Selected Item", s);

        EditorGUILayout.IntSlider(activeItemIndex, 0, _target.points.Count - 1, GUIContent.none);

        // Display selected item
        _target.UpdateActivePoint();

        int indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;
        float labelWidth = EditorGUIUtility.labelWidth;

        try
        {
            // Display point position
            Rect position = EditorGUILayout.GetControlRect();

            GUIContent label           = EditorGUI.BeginProperty(position, new GUIContent("Position"), activeItem);
            Rect       contentPosition = EditorGUI.PrefixLabel(position, label);

            // Show point position and gravity
            EditorGUIUtility.labelWidth = 14f;
            contentPosition.width      *= 0.333f;
            SerializedProperty activeItemPos = activeItem.FindPropertyRelative("position");

            EditorGUI.PropertyField(contentPosition, activeItemPos.FindPropertyRelative("x"));

            contentPosition.x += contentPosition.width;
            EditorGUI.PropertyField(contentPosition, activeItemPos.FindPropertyRelative("y"));

            contentPosition.x += contentPosition.width;
            EditorGUI.PropertyField(contentPosition, activeItemPos.FindPropertyRelative("z"));

            EditorGUI.EndProperty();

            // Display point rotation
            SerializedProperty activeItemRotation = activeItem.FindPropertyRelative("rotation");
            position = EditorGUILayout.GetControlRect();
            EditorGUIUtility.labelWidth = labelWidth;
            label = EditorGUI.BeginProperty(position, new GUIContent("Rotation"), activeItemRotation);

            contentPosition             = EditorGUI.PrefixLabel(position, label);
            EditorGUIUtility.labelWidth = 14f;
            //contentPosition.width *= 0.333f;

            Vector3 eulerRotation = activeItemRotation.quaternionValue.eulerAngles;

            eulerRotation = EditorGUI.Vector3Field(contentPosition, GUIContent.none, eulerRotation);
            activeItemRotation.quaternionValue = Quaternion.Euler(eulerRotation);

            EditorGUI.EndProperty();

            EditorGUIUtility.labelWidth = labelWidth;
            EditorGUILayout.Slider(activeItem.FindPropertyRelative("gravity"), -20, 20, new GUIContent("Gravity"));

            EditorGUILayout.PropertyField(layerMask, new GUIContent("Layer"));

            EditorGUILayout.PropertyField(activeItem.FindPropertyRelative("raycastDistance"), new GUIContent("RayCast Distance"));

            GUILayout.BeginHorizontal();

            GUI.enabled = _target.points.Count > 1;
            if (GUILayout.Button("Center in layer"))
            {
                _target.RealignPoint();
                SceneView.RepaintAll();
            }
            GUI.enabled = true;
            if (GUILayout.Button("Find in scene"))
            {
                SceneView.lastActiveSceneView.pivot = activeItemPos.vector3Value;
                SceneView.lastActiveSceneView.Repaint();
            }
            GUILayout.EndHorizontal();
        }
        finally
        {
            EditorGUI.indentLevel       = indent;
            EditorGUIUtility.labelWidth = labelWidth;
        }
    }