Beispiel #1
0
    public bool FilterRaycastHit(EnRaycastManager manager, EnRaycast enRaycast, RaycastHit hit, ref RaycastHit raycastHit)
    {
#if FIRST_PERSON_CONTROLLER || THIRD_PERSON_CONTROLLER
        if (ValidateObject(manager, hit.collider.gameObject))
        {
            raycastHit = hit;
            return(true);
        }
#endif
        return(false);
    }
Beispiel #2
0
    public bool FilterRaycastHitsAllNonAlloc(EnRaycastManager manager, EnRaycast enRaycast, int length, RaycastHit[] hits, ref RaycastHit raycastHit)
    {
#if FIRST_PERSON_CONTROLLER || THIRD_PERSON_CONTROLLER
        for (int i = 0; i < length; i++)
        {
            var hitObject = hits[i].collider.gameObject;
            if (ValidateObject(manager, hitObject))
            {
                raycastHit = hits[i];
                return(true);
            }
        }
#endif
        return(false);
    }
Beispiel #3
0
 public EnRaycastEventData(EnRaycastManager manager, EnRaycast cast)
 {
     Manager   = manager;
     EnRaycast = cast;
 }
 public bool FilterRaycastHitsAllNonAlloc(EnRaycastManager manager, EnRaycast enRaycast, int hitCount, RaycastHit[] hits, ref RaycastHit raycastHit)
 {
     raycastHit = GetClosestRaycastHit(enRaycast.m_Origin, hitCount, hits);
     return(true);
 }
 public bool FilterRaycastHit(EnRaycastManager manager, EnRaycast enRaycast, RaycastHit hit, ref RaycastHit raycastHit)
 {
     raycastHit = hit;
     return(true);
 }
Beispiel #6
0
    // Draws the elements on the list
    void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
    {
        var defaultFontSize = GUI.skin.button.fontSize;

        GUI.skin.button.fontSize  = 9;
        GUI.skin.button.alignment = TextAnchor.MiddleCenter;

        SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index); //The element in the list

        float spacing          = EditorGUIUtility.singleLineHeight / 2;
        var   currentViewWidth = EditorGUIUtility.currentViewWidth - 60;
        // Create a property field and label field for each property.

        var typeProp         = element.FindPropertyRelative("m_Type");
        var raycastTypeValue = (EnRaycast.RaycastType)typeProp.enumValueIndex;

        // The 'm_Type' property. Since the enum is self-evident, I am not making a label field for it.
        // The property field for m_Type (width 100, height of a single line)
        EditorGUI.PropertyField(
            new Rect(rect.x, rect.y + spacing, currentViewWidth * 0.4f, EditorGUIUtility.singleLineHeight),
            typeProp,
            GUIContent.none
            );

        var expectProp      = element.FindPropertyRelative("m_Expect");
        var expectPropValue = (EnRaycast.Expect)typeProp.enumValueIndex;

        EditorGUI.PropertyField(
            new Rect(rect.x + currentViewWidth * 0.4f, rect.y + spacing, currentViewWidth * 0.6f - 50, EditorGUIUtility.singleLineHeight),
            expectProp,
            GUIContent.none
            );

        var executed = element.FindPropertyRelative("Executed").boolValue;
        var result   = element.FindPropertyRelative("Result").boolValue;
        var status   = element.FindPropertyRelative("Success").boolValue;

        EditorGUI.DrawRect(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 2 - spacing / 2,
                                    currentViewWidth, 2), result ? status ? expectedCollisionColor : notExpectedCollisionColor : expectedNoCollisionColor);

        var controlCount     = RaycastTypeControlLength(raycastTypeValue) - 1;
        var heightStatusLine = EditorGUIUtility.singleLineHeight * controlCount + spacing * 3 - 2;

        EditorGUI.DrawRect(new Rect(rect.x - 11, rect.y + EditorGUIUtility.singleLineHeight * 2 - spacing * 2,
                                    2, heightStatusLine), executed ? status ? expectedCollisionColor : expectedNoCollisionColor : Color.gray);


        EditorGUI.PropertyField(
            new Rect(rect.x + currentViewWidth - 50, rect.y + spacing, 50, EditorGUIUtility.singleLineHeight),
            element.FindPropertyRelative("m_Color"),
            GUIContent.none
            );


        EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 2, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Origin Offset");
        EditorGUI.PropertyField(
            new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 2, currentViewWidth * 0.60f - 88, EditorGUIUtility.singleLineHeight),
            element.FindPropertyRelative("m_Origin"),
            GUIContent.none
            );

        //copy
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 88, rect.y + EditorGUIUtility.singleLineHeight * 2, 44, 18), "copy", GUI.skin.button))
        {
            EnRaycastManager manager = (EnRaycastManager)serializedObject.targetObject;
            string           json    = JsonUtility.ToJson(manager.items[index]);
            GUIUtility.systemCopyBuffer = json;
        }
        //paste
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 44, rect.y + EditorGUIUtility.singleLineHeight * 2, 44, 18), "paste", GUI.skin.button))
        {
            string    json      = GUIUtility.systemCopyBuffer;
            EnRaycast enRaycast = JsonUtility.FromJson <EnRaycast>(json);//FromJsonOverwrite(json, enRaycast);
            element.FindPropertyRelative("m_Type").enumValueIndex       = (int)enRaycast.m_Type;
            element.FindPropertyRelative("m_Expect").enumValueIndex     = (int)enRaycast.m_Expect;
            element.FindPropertyRelative("m_Color").colorValue          = enRaycast.m_Color;
            element.FindPropertyRelative("m_Origin").vector3Value       = enRaycast.m_Origin;
            element.FindPropertyRelative("m_Direction").vector3Value    = enRaycast.m_Direction;
            element.FindPropertyRelative("m_MaxDistance").floatValue    = enRaycast.m_MaxDistance;
            element.FindPropertyRelative("m_Radius").floatValue         = enRaycast.m_Radius;
            element.FindPropertyRelative("m_Height").floatValue         = enRaycast.m_Height;
            element.FindPropertyRelative("m_HeightAxis").enumValueIndex = (int)enRaycast.m_HeightAxis;
            element.FindPropertyRelative("m_Size").vector3Value         = enRaycast.m_Size;
        }

        EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 3, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Direction");
        EditorGUI.PropertyField(
            new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 3, currentViewWidth * 0.60f - 88, EditorGUIUtility.singleLineHeight),
            element.FindPropertyRelative("m_Direction"),
            GUIContent.none
            );

        //x
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 88, rect.y + EditorGUIUtility.singleLineHeight * 3, 22, 18), "↔", GUI.skin.button))
        {
            element.FindPropertyRelative("m_Direction").vector3Value = element.FindPropertyRelative("m_Direction").vector3Value != Vector3.right ? Vector3.right : Vector3.left;
        }
        //y
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 66, rect.y + EditorGUIUtility.singleLineHeight * 3, 22, 18), "↕", GUI.skin.button))
        {
            element.FindPropertyRelative("m_Direction").vector3Value = element.FindPropertyRelative("m_Direction").vector3Value != Vector3.up ? Vector3.up : Vector3.down;
        }
        //z
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 44, rect.y + EditorGUIUtility.singleLineHeight * 3, 22, 18), element.FindPropertyRelative("m_Direction").vector3Value != Vector3.forward ? "→" : "←", GUI.skin.button))
        {
            element.FindPropertyRelative("m_Direction").vector3Value = element.FindPropertyRelative("m_Direction").vector3Value != Vector3.forward ? Vector3.forward : Vector3.back;
        }
        //±
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 22, rect.y + EditorGUIUtility.singleLineHeight * 3, 22, 18), "‼", GUI.skin.button))
        {
            element.FindPropertyRelative("m_Direction").vector3Value *= -1;
        }

        EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 4, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Max Distance");
        EditorGUI.PropertyField(
            new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 4, currentViewWidth * 0.60f - 88, EditorGUIUtility.singleLineHeight),
            element.FindPropertyRelative("m_MaxDistance"),
            GUIContent.none
            );
        //duplicate
        if (GUI.Button(new Rect(rect.x + currentViewWidth - 88, rect.y + EditorGUIUtility.singleLineHeight * 4, 88, 18), "duplicate", GUI.skin.button))
        {
            Duplicate();
        }


        switch (raycastTypeValue)
        {
        case EnRaycast.RaycastType.Raycast:
        case EnRaycast.RaycastType.RaycastAll:
        case EnRaycast.RaycastType.RaycastNonAlloc:
            break;

        case EnRaycast.RaycastType.SphereCast:
        case EnRaycast.RaycastType.SphereCastAll:
        case EnRaycast.RaycastType.SphereCastNonAlloc:
            EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Radius");
            EditorGUI.PropertyField(
                new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.60f, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("m_Radius"),
                GUIContent.none
                );
            break;

        case EnRaycast.RaycastType.CapsuleCast:
        case EnRaycast.RaycastType.CapsuleCastAll:
        case EnRaycast.RaycastType.CapsuleCastNonAlloc:
            EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Radius");
            EditorGUI.PropertyField(
                new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.60f, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("m_Radius"),
                GUIContent.none
                );

            EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 6, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Height");
            EditorGUI.PropertyField(
                new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 6, currentViewWidth * 0.60f, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("m_Height"),
                GUIContent.none
                );

            EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 7, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Axis Direction");

            var heightAxis      = element.FindPropertyRelative("m_HeightAxis");
            var heightAxisValue = (CapsuleBoundsHandle.HeightAxis)heightAxis.enumValueIndex;
            EditorGUI.PropertyField(
                new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 7, currentViewWidth * 0.6f, EditorGUIUtility.singleLineHeight),
                heightAxis,
                GUIContent.none
                );

            break;

        case EnRaycast.RaycastType.BoxCast:
        case EnRaycast.RaycastType.BoxCastAll:
        case EnRaycast.RaycastType.BoxCastNonAlloc:
            EditorGUI.LabelField(new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.40f, EditorGUIUtility.singleLineHeight), "Size");
            EditorGUI.PropertyField(
                new Rect(rect.x + currentViewWidth * 0.40f, rect.y + EditorGUIUtility.singleLineHeight * 5, currentViewWidth * 0.60f, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("m_Size"),
                GUIContent.none
                );
            break;
        }
        GUI.skin.button.fontSize = defaultFontSize;
    }