summaryrefslogtreecommitdiff
path: root/Assets/LensFlare/FlareSource.cs
blob: 1ab8a2ecd3aa4383995184467bac2e1a8c5c2c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class Flare
{
    public FlareAtlas Atlas;
    public int Index;
}

// 光源
public class FlareSource : MonoBehaviour
{
    [SerializeField] private Camera m_GameCamera;
    [SerializeField] private Camera m_FlareCamera;
    public List<Flare> Flares;

    private Vector3 m_ViewportPosition;
    public Vector3 ViewportPosition
    {
        get
        {
            return m_ViewportPosition;
        }
    }

    public bool IsVisible
    {
        get;private set;
    }

    // Start is called before the first frame update
    void Start()
    {
        IsVisible = false;
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 position = transform.position;
        m_ViewportPosition = m_GameCamera.WorldToViewportPoint(position);

        Ray ray = new Ray(m_GameCamera.transform.position, position - m_GameCamera.transform.position);
        RaycastHit hit;
        if(Physics.Raycast(ray, out hit))
        {
            IsVisible = false;
        }
        else
        {
            IsVisible = true;
        }
    }

    private void OnDrawGizmos()
    {
        Gizmos.DrawLine(transform.position, m_GameCamera.transform.position);
    }

}