Ejemplo n.º 1
0
    public static UIHotSpot AddWidgetHotSpot(GameObject go)
    {
        int    num;
        AABBox aABBox;

        if (go == null)
        {
            return(null);
        }
        Collider collider = go.collider;

        if (collider)
        {
            UIHotSpot hotSpot = NGUITools.ColliderToHotSpot(collider, true);
            if (!hotSpot)
            {
                return(null);
            }
            return(hotSpot);
        }
        UIHotSpot component = go.GetComponent <UIHotSpot>();

        if (component)
        {
            if (component.isRect)
            {
                UIRectHotSpot uIRectHotSpot = component.asRect;
                num                  = NGUITools.CalculateNextDepth(go);
                aABBox               = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
                uIRectHotSpot.size   = aABBox.size;
                uIRectHotSpot.center = aABBox.center + (Vector3.back * ((float)num * 0.25f));
                return(uIRectHotSpot);
            }
            if (!Application.isPlaying)
            {
                UnityEngine.Object.DestroyImmediate(component);
            }
            else
            {
                UnityEngine.Object.Destroy(component);
            }
        }
        num    = NGUITools.CalculateNextDepth(go);
        aABBox = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
        UIRectHotSpot uIRectHotSpot1 = go.AddComponent <UIRectHotSpot>();

        uIRectHotSpot1.size   = aABBox.size;
        uIRectHotSpot1.center = aABBox.center + (Vector3.back * ((float)num * 0.25f));
        return(uIRectHotSpot1);
    }
Ejemplo n.º 2
0
    private static UIHotSpot ColliderToHotSpot(Collider collider, bool nullChecked)
    {
        Bounds bound;

        if (!nullChecked && !collider)
        {
            return(null);
        }
        if (collider is BoxCollider)
        {
            return(NGUITools.ColliderToHotSpot((BoxCollider)collider));
        }
        if (collider is SphereCollider)
        {
            return(NGUITools.ColliderToHotSpot((SphereCollider)collider));
        }
        if (collider is TerrainCollider)
        {
            Debug.Log("Sorry not going to convert a terrain collider.. that sounds destructive.", collider);
            return(null);
        }
        Bounds    bound1    = collider.bounds;
        Matrix4x4 matrix4x4 = collider.transform.worldToLocalMatrix;

        AABBox.Transform3x4(ref bound1, ref matrix4x4, out bound);
        bool       flag       = collider.enabled;
        GameObject gameObject = collider.gameObject;

        NGUITools.ColliderDestroy(collider);
        Vector3 vector3 = bound.size;

        if (vector3.z > 0.001f)
        {
            UIBoxHotSpot uIBoxHotSpot = gameObject.AddComponent <UIBoxHotSpot>();
            uIBoxHotSpot.size    = vector3;
            uIBoxHotSpot.center  = bound.center;
            uIBoxHotSpot.enabled = flag;
            return(uIBoxHotSpot);
        }
        UIRectHotSpot uIRectHotSpot = gameObject.AddComponent <UIRectHotSpot>();

        uIRectHotSpot.size    = vector3;
        uIRectHotSpot.center  = bound.center;
        uIRectHotSpot.enabled = flag;
        return(uIRectHotSpot);
    }
Ejemplo n.º 3
0
 public static UIHotSpot ColliderToHotSpot(Collider collider)
 {
     return(NGUITools.ColliderToHotSpot(collider, false));
 }