コード例 #1
0
    public T GetComponentInCrosshair <T>() where T : MonoBehaviour
    {
        T t = null;

        for (int i = 0; i < crosshairParts.Length; i++)
        {
            t = GetComponentInCrosshairLayer <T>(i);
            if (t != null)
            {
                break;
            }
        }
        return(t);
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        serializedObject.Update();
        EditorGUILayout.Space();
        _list.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        //draw on the crosshair in the template
        CrosshairTemplate t = (CrosshairTemplate)target;

        Rect totalRect = GUILayoutUtility.GetAspectRect(1, GUILayout.MaxWidth(300), GUILayout.MaxHeight(300));
        //Get a quick reference to the center
        Vector2 center = totalRect.center;

        foreach (var e in t.elements)
        {
            //draw the surrounding lines only if there are more than 0
            if (e.count != 0)
            {
                float movement = e.orbitStartAngle;

                //Draw the lines
                float angleIncrease = e.orbitSize / e.count;
                Color col           = e.overrideColor ? e.color : t.color;
                for (int i = 0; i < e.count; i++)
                {
                    movement += angleIncrease;
                    //GUIUtility.RotateAroundPivot(movement, center);

                    float   fakeSpread = (Mathf.Sin(Time.time) + 2);
                    Vector2 size       = e.size;

                    if (e.scaleWithSpread.HasFlag(EffectAxis.X))
                    {
                        size.x *= fakeSpread * 10;
                    }
                    if (e.scaleWithSpread.HasFlag(EffectAxis.Y))
                    {
                        size.y *= fakeSpread * 10;
                    }


                    //more positive means more down in this viewer
                    //                                      simulate scaling by horizontal fov
                    var mid = center + scale * (e.offset + (e.offsetWithSpread ? e.spreadOffsetDirection * fakeSpread * 10 : Vector2.zero));
                    //apply center offset
                    mid += new Vector2(1, -1) * CrosshairController.MaskFromEffects(e.offsetFromCenter) * size * 0.5f;

                    mid = (mid - center).Rotate(movement) + center;

                    GUIUtility.RotateAroundPivot(e.rotationOffset + movement, mid);


                    if (e.sprite != null)
                    {
                        GUI.color = col;
                        Rect rect = e.sprite.rect;
                        //support drawing sprites that are not the entire texture
                        rect.x      /= e.sprite.texture.width;
                        rect.y      /= e.sprite.texture.height;
                        rect.width  /= e.sprite.texture.width;
                        rect.height /= e.sprite.texture.height;
                        GUI.DrawTextureWithTexCoords(RectAround(mid, size), e.sprite.texture, rect);
                        GUI.color = Color.white;
                    }
                    else
                    {
                        //draw the normal square
                        EditorGUI.DrawRect(RectAround(mid, size), col);
                    }

                    //reset the rotation back to normal
                    GUIUtility.RotateAroundPivot(-e.rotationOffset - movement, mid);


                    //GUIUtility.RotateAroundPivot(-movement, center);
                }
            }
        }
    }