Example #1
0
    private void UpdateVisibility()
    {
        float num;

        if (!this.MpSync)
        {
            num = (GreeblePlugin.GetCameraPosition() - base.transform.position).magnitude;
        }
        else
        {
            num = Scene.SceneTracker.GetClosestPlayerDistanceFromPos(base.transform.position);
        }
        float        num2  = 0f;
        GreebleShape shape = this.Shape;

        if (shape != GreebleShape.Sphere)
        {
            if (shape == GreebleShape.Box)
            {
                Vector2 vector = new Vector2(this.Size.x, this.Size.z);
                num2 = vector.magnitude;
            }
        }
        else
        {
            num2 = this.Radius;
        }
        float num3 = num - num2;
        bool  flag = num3 < this.ToggleDistance * TheForestQualitySettings.UserSettings.DrawDistanceGreebleRatio;

        if (flag != this.currentlyVisible)
        {
            if (flag)
            {
                this.Spawn();
            }
            else
            {
                this.Despawn();
            }
        }
    }
Example #2
0
 public void RemoveGreeble(GameObject greebleInstance)
 {
     if (greebleInstance == null)
     {
         return;
     }
     for (int i = 0; i < this.CountX; i++)
     {
         for (int j = 0; j < GreebleLayer.CountY; j++)
         {
             for (int k = 0; k < this.CountZ; k++)
             {
                 if (this.greebles[i, j, k].Instance == greebleInstance)
                 {
                     GreeblePlugin.Remove(greebleInstance);
                     this.greebles[i, j, k].Instance = null;
                 }
             }
         }
     }
 }
Example #3
0
 public void Despawn()
 {
     if (this.instances == null || this.InstanceData == null)
     {
         return;
     }
     for (int i = 0; i < this.instances.Length; i++)
     {
         if (this.currentlyVisible && i < this.scheduledSpawnIndex && (!this.instances[i] || !this.instances[i].activeSelf) && this.InstanceData != null && this.InstanceData[i].Spawned)
         {
             if (this.AllowRegrowth)
             {
                 this.InstanceData[i].CreationTime = Time.timeSinceLevelLoad;
             }
             else
             {
                 this.InstanceData[i].Destroyed = true;
             }
             if (this.Data != null)
             {
                 this.Data._instancesState[i] = 255;
             }
         }
         if (Application.isPlaying)
         {
             if (this.MpSync && BoltNetwork.isServer && this.instances[i])
             {
                 BoltNetwork.Detach(this.instances[i]);
             }
             GreeblePlugin.Destroy(this.instances[i]);
         }
         else
         {
             UnityEngine.Object.DestroyImmediate(this.instances[i]);
         }
         this.InstanceData[i].Spawned = false;
         this.instances[i]            = null;
     }
     this.currentlyVisible = false;
 }
Example #4
0
    public void ThreadedRefresh()
    {
        float num;

        if (!this.MpSync)
        {
            num = (GreeblePlugin.GetCameraPosition() - this.position).magnitude;
        }
        else
        {
            num = Scene.SceneTracker.GetClosestPlayerDistanceFromPos(this.position);
        }
        float        num2  = 0f;
        GreebleShape shape = this.Shape;

        if (shape != GreebleShape.Sphere)
        {
            if (shape == GreebleShape.Box)
            {
                Vector2 vector = new Vector2(this.Size.x, this.Size.z);
                num2 = vector.magnitude;
            }
        }
        else
        {
            num2 = this.Radius;
        }
        float num3 = num - num2;

        this.nextVisible = (num3 < this.ToggleDistance * TheForestQualitySettings.UserSettings.DrawDistanceGreebleRatio * ((!this.currentlyVisible) ? 1f : 1.1f));
        if (this.nextVisible != this.currentlyVisible)
        {
            this.ShouldDoMainThreadRefresh = true;
        }
        else if (this.ShouldDoMainThreadRefresh)
        {
            this.ShouldDoMainThreadRefresh = false;
        }
    }
Example #5
0
    public static GameObject Spawn(GreebleDefinition greebleDefinition, Ray ray, float distance, Quaternion rotation, float maxSlope = 0.5f)
    {
        if (distance <= 0f)
        {
            return(null);
        }
        Vector3    vector = ray.origin;
        RaycastHit raycastHit;

        if (!Physics.Raycast(ray, out raycastHit, distance, greebleDefinition.SurfaceMask | greebleDefinition.KillMask))
        {
            return(null);
        }
        if ((greebleDefinition.KillMask.value & 1 << raycastHit.collider.gameObject.layer) > 0)
        {
            return(null);
        }
        if (Vector3.Dot(ray.direction, raycastHit.normal) > -maxSlope)
        {
            return(null);
        }
        bool flag = greebleDefinition.TerrainTextureMask != null && greebleDefinition.TerrainTextureMask.Length > 0;

        if (flag)
        {
            Terrain component = raycastHit.collider.GetComponent <Terrain>();
            if (component)
            {
                Debug.Log("We have terrain");
                Vector3     position           = component.GetPosition();
                TerrainData terrainData        = component.terrainData;
                int         alphamapResolution = terrainData.alphamapResolution;
                int         num   = (int)((raycastHit.point.x - position.x) / terrainData.size.x * (float)alphamapResolution);
                int         num2  = (int)((raycastHit.point.z - position.z) / terrainData.size.z * (float)alphamapResolution);
                bool        flag2 = false;
                if (num >= 0 && num2 >= 0 && num < alphamapResolution && num2 < alphamapResolution)
                {
                    float[,,] alphamaps = component.terrainData.GetAlphamaps(num, num2, 1, 1);
                    float num3 = 0f;
                    int   num4 = -1;
                    for (int i = terrainData.alphamapLayers - 1; i >= 0; i--)
                    {
                        if (alphamaps[0, 0, i] > num3)
                        {
                            num3 = alphamaps[0, 0, i];
                            num4 = i;
                        }
                    }
                    if (num4 >= 0)
                    {
                        int[] terrainTextureMask = greebleDefinition.TerrainTextureMask;
                        for (int j = 0; j < terrainTextureMask.Length; j++)
                        {
                            int num5 = terrainTextureMask[j];
                            if (num5 == num4)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                }
                if (!flag2)
                {
                    return(null);
                }
            }
        }
        vector = raycastHit.point;
        if (greebleDefinition.MatchSurfaceNormal)
        {
            Vector3    lhs        = Vector3.Cross(Vector3.forward, raycastHit.normal);
            Vector3    forward    = Vector3.Cross(lhs, raycastHit.normal);
            Quaternion quaternion = Quaternion.LookRotation(forward, raycastHit.normal);
            if (greebleDefinition.RandomizeRotation)
            {
                rotation = quaternion * rotation;
            }
            else
            {
                rotation = quaternion;
            }
        }
        vector   += rotation * greebleDefinition.Prefab.transform.position;
        rotation *= greebleDefinition.Prefab.transform.rotation;
        return(GreeblePlugin.Instantiate(greebleDefinition.Prefab, vector, rotation));
    }
Example #6
0
 private void DestroyGreeble(int x, int y, int z)
 {
     GreeblePlugin.Destroy(this.greebles[x, y, z].Instance);
     this.greebles[x, y, z].Instance = null;
 }