示例#1
0
        public void RemoveReceiver(ReceiverBase receiver)
        {
            var index = m_receivers.IndexOf(receiver);

            if (0 <= index)
            {
                m_receivers.RemoveAt(index);
            }
            for (var i = 0; i < m_receiverInstances.Count; ++i)
            {
                Destroy(m_receiverInstances[i][index].gameObject);
                m_receiverInstances[i].RemoveAt(index);
            }
        }
示例#2
0
 public void AddReceiver(ReceiverBase receiver)
 {
     if (m_receivers.Contains(receiver))
     {
         return;
     }
     receiver.gameObject.SetActive(false);
     m_receivers.Add(receiver);
     for (var i = 0; i < m_receiverInstances.Count; ++i)
     {
         var clone = Instantiate(receiver) as ReceiverBase;
         clone.transform.parent = transform;
         if (0 < m_receiverInstances[i].Count)
         {
             clone.gameObject.layer = m_receiverInstances[i][0].gameObject.layer;
             clone.gameObject.SetActive(m_receiverInstances[i][0].gameObject.activeSelf);
         }
         else
         {
             clone.gameObject.SetActive(false);
         }
         m_receiverInstances[i].Add(clone);
     }
 }
        private void Start()
        {
            Component    lightProjector = GetComponent <Projector>();
            ReceiverBase receiver       = null;

            if (lightProjector == null)
            {
                receiver = GetComponent <ReceiverBase>();
                if (receiver != null)
                {
                    m_projectorInterface = receiver.projectorInterface;
                    lightProjector       = receiver.unityProjector;
                    if (lightProjector == null)
                    {
                        lightProjector = receiver.customProjector;
                    }
                }
            }
            var r = GetComponent <Renderer>();

            if (r != null && (lightProjector == null || lightProjector.gameObject != gameObject))
            {
                // if light projector is not this game object, cast shadows on only this game object.
                m_material = r.material;
            }
            if (m_material == null)
            {
                if (lightProjector is Projector)
                {
                    var projector = (Projector)lightProjector;
                    m_material         = new Material(projector.material);
                    projector.material = m_material;
                }
                if (m_material == null && (Debug.isDebugBuild || Application.isEditor))
                {
                    Debug.LogError("No material was found!", this);
                }
            }
            m_maxShadowNum = int.Parse(m_material.GetTag("FSRMaxShadowNum", false, "0"));
            if (m_projectorInterface == null)
            {
                if (lightProjector is IProjector)
                {
                    m_projectorInterface = lightProjector as IProjector;
                }
                else if (lightProjector is Projector)
                {
                    m_projectorInterface = new UnityProjector(lightProjector as Projector);
                }
                else if (Debug.isDebugBuild || Application.isEditor)
                {
                    Debug.LogError("No light projector!", this);
                }
            }
            if (s_shadowNumKeyword == null || s_shadowNumKeyword.Length <= m_maxShadowNum)
            {
                s_shadowNumKeyword = new string[m_maxShadowNum + 1];
                for (var i = 0; i < m_maxShadowNum + 1; ++i)
                {
                    s_shadowNumKeyword[i] = "FSR_SHADOW_PROJECTOR_COUNT_" + i;
                }
            }
            if (s_shadowProjectionMatrixPropertyIDs == null ||
                s_shadowProjectionMatrixPropertyIDs.Length < m_maxShadowNum)
            {
                s_shadowProjectionMatrixPropertyIDs = new int[m_maxShadowNum];
                s_shadowTexturePropertyIDs          = new int[m_maxShadowNum];
                for (var i = 0; i < m_maxShadowNum; ++i)
                {
                    s_shadowProjectionMatrixPropertyIDs[i] = Shader.PropertyToID("_ShadowProjector" + (i + 1));
                    s_shadowTexturePropertyIDs[i]          = Shader.PropertyToID("_ShadowTex" + (i + 1));
                }
            }
            if (m_shadowCasters == null || m_shadowCasters.Length < m_maxShadowNum)
            {
                m_shadowCasters = new LightProjectorShadowCaster[m_maxShadowNum];
            }
            if (m_prevShadowCasters == null || m_prevShadowCasters.Length < m_maxShadowNum)
            {
                m_prevShadowCasters = new LightProjectorShadowCaster[m_maxShadowNum];
            }
        }