예제 #1
0
        public Material GetShadowMaterial(Color color)
        {
            if (shadowShareMaterial == null)
            {
                return(null);
            }

            foreach (var cache in shadowMatCache)
            {
                if (cache.color == color)
                {
                    return(cache.mat);
                }
            }
            //generate

            ShadowCache newCache = new ShadowCache();

            newCache.color = color;

            newCache.mat = new Material(shadowShareMaterial);

            newCache.mat.SetColor("_Color", color);

            shadowMatCache.Add(newCache);

            newCache.mat.name = newCache.mat.name + "_StaMat_" + staCount;
            staCount++;

            return(newCache.mat);
        }
예제 #2
0
        public ShadowManager()
        {
            shadowShareMaterial = Resources.Load <Material>(SHADOW_MAT_PATH);

            if (shadowShareMaterial)
            {
                shadowMatCache    = new List <ShadowCache>();
                shadowMatDynCache = new List <Material>();
                ShadowCache cache = new ShadowCache();

                cache.color = new Color(1, 1, 1, 1);

                cache.mat = shadowShareMaterial;
            }
            else
            {
                Debug.LogError("shadow路径不存在:" + SHADOW_MAT_PATH);
            }

            Init();
            //UnityEngine.Object shadowObj = ResourceLoader.Instance.try_load_cached_asset("Assets/Res/Core/ShadowProjector/HardShadowProjector.prefab") as UnityEngine.Object;
            //if(shadowObj != null)
            //{
            //    m_ShadowProjector = GameObject.Instantiate(shadowObj) as GameObject;
            //    if(m_ShadowProjector != null)
            //    {
            //        mDrawSceneObject = m_ShadowProjector.GetComponent<DrawSceneObject>();
            //        GameObject.DontDestroyOnLoad(m_ShadowProjector);
            //    }
            //}

            ClientEventMgr.Instance.SubscribeClientEvent((int)ClientEvent.CE_LOCALPLAYER_MODEL_CHANGE, OnLocalPlayerModelChange);
            ClientEventMgr.Instance.SubscribeClientEvent((int)ClientEvent.CE_FINISH_SWITCHSCENE, OnSceneLoaded);
        }
예제 #3
0
    void Update()
    {
        if (light)
        {
            time += Time.deltaTime;
            float t = time / daytime;
            float v = dayIntensity.Evaluate(t);
            light.intensity = v;
            Color c = dayColor.Evaluate(t % 1);
            light.color = c;
            Quaternion rot = Quaternion.AngleAxis(-t * 360, northDir);
            transform.rotation = rot * rotation;

            if ((t % 1) > 0.5f)
            {
                isNight = true;
            }
            else
            {
                isNight = false;
            }

            if (v < 0.9f)
            {
                if (!lightswitch)
                {
                    change = true;
                }
                else
                {
                    change = false;
                }
                lightswitch = true;
            }
            else
            {
                if (lightswitch)
                {
                    change = true;
                }
                else
                {
                    change = false;
                }
                lightswitch = false;
            }

            ShadowCache renderer = GetComponent(typeof(ShadowCache)) as ShadowCache;
            if (renderer)
            {
                if (isNight)
                {
                    renderer.AutoRefresh = false;
                }
                else
                {
                    renderer.AutoRefresh = true;
                }
            }
            if (change)
            {
                if (lightswitch)
                {
                    SetDayNight(1);
                }
                else
                {
                    SetDayNight(0);
                }
            }
        }
    }