Example #1
0
    private void Awake()
    {
        CustomBillboard component = base.GetComponent <CustomBillboard>();

        for (int i = 0; i < this.Count; i++)
        {
            Vector3    point    = new Vector3(UnityEngine.Random.Range(0f, this.Radius), 0f, 0f);
            Quaternion rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f);
            component.Register(rotation * point, base.transform.rotation.y);
        }
    }
Example #2
0
 private void OnEnable()
 {
     if (this.cb == null)
     {
         if (this.billboard != null)
         {
             this.cb = this.billboard.GetComponent <CustomBillboard>();
         }
         if (this.BillboardId == -1 && this.cb != null)
         {
             this.BillboardId = this.cb.Register(base.transform.position, base.transform.eulerAngles.y);
         }
     }
     else
     {
         this.cb.SetAlive(this.BillboardId, true);
     }
 }
Example #3
0
 private void OnEnable()
 {
     if (this.cb == null)
     {
         if (this.billboard != null)
         {
             this.cb = this.billboard.GetComponent<CustomBillboard>();
         }
         if (this.BillboardId == -1 && this.cb != null)
         {
             this.BillboardId = this.cb.Register(base.transform.position, base.transform.eulerAngles.y);
         }
     }
     else
     {
         this.cb.SetAlive(this.BillboardId, true);
     }
 }
Example #4
0
	protected virtual void OnEnable()
	{
		this.CurrentLodTransform = null;
		this._position = base.transform.position;
		if (this.cb == null)
		{
			if (this.billboard != null)
			{
				this.cb = this.billboard.GetComponent<CustomBillboard>();
			}
			if (this.BillboardId == -1 && this.cb != null)
			{
				this.BillboardId = this.cb.Register(this._position, base.transform.eulerAngles.y);
			}
		}
		else
		{
			this.cb.SetAlive(this.BillboardId, true);
		}
		this.wsToken = WorkScheduler.Register(new WorkScheduler.Task(this.RefreshLODs), this._position, this.canForceWorkScheduler);
		this.canForceWorkScheduler = false;
	}
Example #5
0
 protected virtual void OnEnable()
 {
     this.CurrentLodTransform = null;
     this._position = base.transform.position;
     if (this.cb == null)
     {
         if (this.billboard != null)
         {
             this.cb = this.billboard.GetComponent<CustomBillboard>();
         }
         if (this.BillboardId == -1 && this.cb != null)
         {
             this.BillboardId = this.cb.Register(this._position, base.transform.eulerAngles.y);
         }
     }
     else
     {
         this.cb.SetAlive(this.BillboardId, true);
     }
     this.wsToken = WorkScheduler.Register(new WorkScheduler.Task(this.RefreshLODs), this._position, this.canForceWorkScheduler);
     this.canForceWorkScheduler = false;
 }
Example #6
0
    public void Update(float quality)
    {
        if (this.Ranges.Length <= 0)
        {
            return;
        }
        if (Scene.Atmosphere && this.CaveMode != LOD_Settings.CaveModes.Always && (this.CaveMode == LOD_Settings.CaveModes.CaveOnly != Scene.Atmosphere.InACave || this.CaveMode == LOD_Settings.CaveModes.OutsideOnly == Scene.Atmosphere.InACave))
        {
            for (int i = 0; i < this.Ranges.Length; i++)
            {
                this.currentRanges[i] = 0f;
            }
            return;
        }
        float num  = Mathf.Max(quality * this.QualityRatio.Evaluate((float)TheForestQualitySettings.UserSettings.DrawDistance), 0.3f);
        bool  flag = (this.LowLodMode == LOD_Settings.LowLodModes.Always || TheForestQualitySettings.UserSettings.DrawDistance <= TheForestQualitySettings.DrawDistances.High) && this.Ranges.Length > 2;
        float num2 = this.StippleRange * num;

        for (int j = 0; j < this.Ranges.Length; j++)
        {
            switch (this.ScaleRanges[j])
            {
            case LOD_Settings.ScaleModes.ScaledQuality:
                this.currentQuality[j] = num;
                break;

            case LOD_Settings.ScaleModes.Quality:
                this.currentQuality[j] = quality;
                break;

            case LOD_Settings.ScaleModes.One:
                this.currentQuality[j] = 1f;
                break;
            }
            this.currentRanges[j] = this.GetRange(j);
            if (j == this.UpscaleToStippleRange && this.currentRanges[j] < this.currentRanges[j - 1] + num2 * 1.3f)
            {
                this.currentRanges[j] = this.currentRanges[j - 1] + num2 * 1.3f;
            }
            if (j == 2 && (this.currentRanges[j] < this.currentRanges[j - 1] + num2 || !flag))
            {
                flag = false;
                this.currentRanges[j] = -1f;
            }
        }
        float num3 = this.currentRanges[0];
        float num4 = this.currentRanges[1];
        float num5 = this.currentRanges[2];
        float num6;

        if (this.BillboardLowLodMode == LOD_Settings.BillboardLowLodModes.MatchLowMode && flag)
        {
            num6 = num5 - num2 * 0.1f;
        }
        else
        {
            num2 = Mathf.Clamp((num4 - num3) / (num2 * 2f), 0.5f, 1f) * num2;
            num6 = num4 - num2 * 0.2f;
        }
        float num7 = num6 - num2;
        float num8 = num7 + num2 * 0.2f;
        float num9 = num8 - num2;

        if (this.DrawDebug && LocalPlayer.Transform)
        {
            Debug.DrawLine(LocalPlayer.Transform.position + LocalPlayer.Transform.forward * num9 - Vector3.up, LocalPlayer.Transform.position + LocalPlayer.Transform.forward * num8 + Vector3.up, Color.blue);
            Debug.DrawLine(LocalPlayer.Transform.position + LocalPlayer.Transform.forward * num6 - Vector3.up, LocalPlayer.Transform.position + LocalPlayer.Transform.forward * num7 + Vector3.up, Color.red);
            Debug.DrawLine(LocalPlayer.Transform.position + LocalPlayer.Transform.forward * this.currentRanges[1], LocalPlayer.Transform.position + LocalPlayer.Transform.forward * this.currentRanges[2], Color.white);
            Debug.DrawLine(LocalPlayer.Transform.position + LocalPlayer.Transform.forward * this.currentRanges[0], LocalPlayer.Transform.position + LocalPlayer.Transform.forward * this.currentRanges[1], Color.cyan);
        }
        Vector2 lhs   = new Vector2(num4 - num2 + num9 + num5, num4 + num8);
        bool    flag2 = lhs != this.lastStippleRange || (this.Billboards != null && this.lastBillboardCount != this.Billboards.Length) || (this.StippledMaterials != null && this.lastStippledMaterialCount != this.StippledMaterials.Length);

        if (flag2)
        {
            if (this.Billboards != null)
            {
                CustomBillboard[] billboards = this.Billboards;
                for (int k = 0; k < billboards.Length; k++)
                {
                    CustomBillboard customBillboard = billboards[k];
                    customBillboard.FadeNearDistance = num9;
                    customBillboard.FadeFarDistance  = num8;
                }
            }
            if (this.StippledMaterials != null)
            {
                Material[] stippledMaterials = this.StippledMaterials;
                for (int l = 0; l < stippledMaterials.Length; l++)
                {
                    Material material = stippledMaterials[l];
                    material.SetFloat("_StippleNear", num7);
                    material.SetFloat("_StippleFar", num6);
                }
            }
            this.lastStippleRange          = lhs;
            this.lastBillboardCount        = ((this.Billboards == null) ? 0 : this.Billboards.Length);
            this.lastStippledMaterialCount = ((this.StippledMaterials == null) ? 0 : this.StippledMaterials.Length);
        }
    }
Example #7
0
        /// <summary>
        /// Set custom material on billboard gameobject.
        /// </summary>
        /// <paran name="go">Billboard gameobject.</param>
        /// <param name="archive">Archive index.</param>
        /// <param name="record">Record index.</param>
        static public void SetBillboardCustomMaterial(GameObject go, int archive, int record)
        {
            int       numberOfFrames;
            string    name = GetName(archive, record);
            var       meshRenderer = go.GetComponent <MeshRenderer>();
            var       daggerfallBillboard = go.GetComponent <DaggerfallBillboard>();
            Texture2D albedoTexture, emissionMap;

            // Check if billboard is emissive
            bool isEmissive = false;

            if (meshRenderer.material.GetTexture("_EmissionMap") != null)
            {
                isEmissive = true;
            }

            // UVs
            Vector2 uv = Vector2.zero;

            // Get properties from Xml
            if (XMLManager.XmlFileExist(archive, record))
            {
                // Customize billboard size (scale)
                Transform transform = go.GetComponent <Transform>();
                transform.localScale = XMLManager.GetScale(name, texturesPath, transform.localScale);
                daggerfallBillboard.SetCustomSize(archive, record, transform.localScale.y);

                // Get UV
                uv = XMLManager.GetUv(name, texturesPath, uv.x, uv.y);
            }

            // Update UV
            UpdateUV(go.GetComponent <MeshFilter>(), uv.x, uv.y);

            // Get material from cache or import from disk
            MaterialReader materialReader = DaggerfallUnity.Instance.MaterialReader;
            CachedMaterial cachedMaterialOut;

            if (materialReader.GetCachedMaterialCustomBillboard(archive, record, 0, out cachedMaterialOut))
            {
                // Get and set material
                meshRenderer.material = cachedMaterialOut.material;

                // Get other properties
                numberOfFrames = cachedMaterialOut.singleFrameCount;
                albedoTexture  = cachedMaterialOut.albedoMap;
                emissionMap    = cachedMaterialOut.emissionMap;
            }
            else
            {
                // Get textures from disk
                LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record);

                // Main texture
                meshRenderer.material.SetTexture("_MainTex", albedoTexture);

                // Emission maps for lights
                if (isEmissive)
                {
                    meshRenderer.material.SetTexture("_EmissionMap", emissionMap);
                }

                // Get number of frames on disk
                numberOfFrames = NumberOfAvailableFrames(archive, record);

                // Save material in cache
                CachedMaterial newcm = new CachedMaterial()
                {
                    albedoMap        = albedoTexture,
                    emissionMap      = emissionMap,
                    material         = meshRenderer.material,
                    singleFrameCount = numberOfFrames
                };
                materialReader.SetCachedMaterialCustomBillboard(archive, record, 0, newcm);
            }

            // Import textures for each frame if billboard is animated
            if (numberOfFrames > 1)
            {
                List <Texture2D> albedoTextures = new List <Texture2D>();
                List <Texture2D> emissionmaps   = new List <Texture2D>();

                // Frame zero
                albedoTextures.Add(albedoTexture);
                if (isEmissive)
                {
                    emissionmaps.Add(emissionMap);
                }

                // Other frames
                for (int frame = 1; frame < numberOfFrames; frame++)
                {
                    if (materialReader.GetCachedMaterialCustomBillboard(archive, record, frame, out cachedMaterialOut))
                    {
                        // Get textures from cache
                        albedoTexture = cachedMaterialOut.albedoMap;
                        emissionMap   = cachedMaterialOut.emissionMap;
                    }
                    else
                    {
                        // Get textures from disk
                        LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record, frame);

                        // Save textures in cache
                        CachedMaterial newcm = new CachedMaterial()
                        {
                            albedoMap   = albedoTexture,
                            emissionMap = emissionMap,
                        };
                        materialReader.SetCachedMaterialCustomBillboard(archive, record, frame, newcm);
                    }

                    albedoTextures.Add(albedoTexture);
                    if (isEmissive)
                    {
                        emissionmaps.Add(emissionMap);
                    }
                }

                // Set textures and properties
                CustomBillboard customBillboard = new CustomBillboard()
                {
                    MainTexture    = albedoTextures,
                    EmissionMap    = emissionmaps,
                    NumberOfFrames = numberOfFrames,
                    isEmissive     = isEmissive
                };
                daggerfallBillboard.SetCustomMaterial(customBillboard);
            }
        }