예제 #1
0
    void Start()
    {
        var mousePos = Input.mousePosition;

        mousePos.z           = 10; // select distance = 10 units from the camera
        spriteRenderer.color = Color.green;
        targetCollider.SetEnable(true);

        targetCollider.AddCollisionCallback(() => {
            spriteRenderer.color = Color.red;
        });
        targetCollider.AddNoHitCallback(() => {
            spriteRenderer.color = Color.green;
        });

        collisionMonitor.AddTargetCollider(targetCollider);
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        EditorUtility.SetDirty(target);          //ensures repaint on value change
        UTargetCollider uCollider = (UTargetCollider)target;

        //Radius
        if (uCollider.radius < 0f)
        {
            uCollider.radius = 0f;             //forcefully avoid negative values
        }
        bool is_radius_over_suggested_max = (uCollider.radius > UTargetCollider.GetSuggestedMaxRadius());

        if (is_radius_over_suggested_max)
        {
            GUI.color = Color.yellow;
        }
        uCollider.radius = EditorGUILayout.FloatField("Collider Radius", uCollider.radius);
        GUI.color        = Color.white;
        if (is_radius_over_suggested_max)
        {
            EditorGUILayout.HelpBox("Exceeding UCollider suggested radius range", MessageType.Warning);
        }
        EditorGUILayout.HelpBox("UDEngine currently requires all collider to have the shape of circle to ensure good performance. To simulate other shapes, consider multiple circle colliders", MessageType.Info);

        // default the .trans prop as its own parent
        // default the .trans prop as its own parent
        if (uCollider.trans == null)
        {
            if (uCollider.transform.parent != null)
            {
                uCollider.SetTransform(uCollider.transform.parent);
            }
            else
            {
                uCollider.SetTransform(uCollider.transform);
            }
        }
        uCollider.SetTransform(EditorGUILayout.ObjectField("Transform", uCollider.trans, typeof(Transform), true) as Transform);

        uCollider.SetLayer(EditorGUILayout.IntField("Layer", uCollider.layer));

        uCollider.SetEnable(EditorGUILayout.Toggle("Enabled", uCollider.IsEnabled()));
    }