Exemplo n.º 1
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     AcresManager.Get().UnregisterAcre(this);
     if (this.m_Plant != null)
     {
         UnityEngine.Object.Destroy(this.m_Plant);
     }
     if (this.m_GrownPlant != null)
     {
         UnityEngine.Object.Destroy(this.m_GrownPlant);
     }
     HUDProcess.Get().UnregisterProcess(this);
 }
Exemplo n.º 2
0
 protected override void Awake()
 {
     base.Awake();
     if (this.s_VisMap == null)
     {
         this.InitializeVisMap();
     }
     if (this.s_ItemsMap == null)
     {
         this.InitializeItemsMap();
     }
     if (this.m_PlantRoot == null)
     {
         this.SetupRoot();
     }
     if (this.s_GrowTimeMap == null)
     {
         this.SetupGrowTimeMap();
     }
     this.m_ItemSlot = base.transform.FindDeepChild("ItemSlot").GetComponent <ItemSlot>();
     for (int i = 0; i < this.m_MaterialObjects.Count; i++)
     {
         Material[] materials = this.m_MaterialObjects[i].GetComponent <MeshRenderer>().materials;
         for (int j = 0; j < materials.Length; j++)
         {
             if (materials[j].name.Contains("Acre_soil"))
             {
                 this.m_Materials.Add(materials[j]);
                 this.m_Shaders.Add(this.m_Materials[i].shader);
                 break;
             }
         }
     }
     AcresManager.Get().RegisterAcre(this);
     if (Acre.s_PlowAudioClip == null)
     {
         Acre.s_PlowAudioClip = (AudioClip)Resources.Load("Sounds/Player/climb_end_fail");
     }
 }
Exemplo n.º 3
0
        public float InitCellContent(int cellIndex)
        {
            GrassCell grassCell        = this.Cells[cellIndex];
            int       cellContentCount = grassCell.CellContentCount;

            for (int i = 0; i < cellContentCount; i++)
            {
                int num = grassCell.CellContentIndexes[i];
                GrassCellContent grassCellContent = this.CellContent[num];
                int num2 = grassCellContent.Layer;
                int num3 = 0;
                this.samplePosition.x   = grassCellContent.Pivot.x;
                this.samplePosition.y   = grassCellContent.Pivot.z;
                this.tempSamplePosition = this.samplePosition;
                int   num4 = (int)this.InstanceRotation[num2];
                bool  flag = this.WriteNormalBuffer[num2];
                float num5 = this.Noise[num2];
                float num6 = this.MinSize[num2];
                float num7 = this.MaxSize[num2] - num6;
                int   num8 = 1;
                if (grassCellContent.SoftlyMergedLayers != null)
                {
                    num8 += grassCellContent.SoftlyMergedLayers.Length;
                }
                for (int j = 0; j < num8; j++)
                {
                    this.tempSamplePosition = this.samplePosition;
                    if (j > 0)
                    {
                        num2 = grassCellContent.SoftlyMergedLayers[j - 1];
                        num5 = this.Noise[num2];
                        num6 = this.MinSize[num2];
                        num7 = this.MaxSize[num2] - num6;
                    }
                    for (int k = 0; k < this.NumberOfBucketsPerCell; k++)
                    {
                        for (int l = 0; l < this.NumberOfBucketsPerCell; l++)
                        {
                            GrassManager.ATGSeed = (uint)((float)(cellIndex + num2 + j * 55 - (k * this.NumberOfBucketsPerCell + l)) * 0.0001f * 2.14748365E+09f);
                            Vector2 vector;
                            vector.x = this.tempSamplePosition.x;
                            vector.y = this.tempSamplePosition.y;
                            int num9 = (int)this.mapByte[num2][grassCellContent.PatchOffsetX + grassCellContent.PatchOffsetZ + k * (int)this.TerrainDetailSize.y + l];
                            num9 = (int)Math.Ceiling((double)((float)num9 * this.CurrentDetailDensity));
                            float num10 = (vector.x < this.TerrainSizeOverHeightmap) ? 0f : this.OneOverHeightmapWidth;
                            float num11 = (vector.x >= this.OneOverHeightmapWidthRight) ? 0f : this.OneOverHeightmapWidth;
                            float num12 = (vector.y < this.TerrainSizeOverHeightmap) ? 0f : this.OneOverHeightmapHeight;
                            float num13 = (vector.y >= this.OneOverHeightmapHeightUp) ? 0f : this.OneOverHeightmapHeight;
                            for (int m = 0; m < num9; m++)
                            {
                                float   num14 = GrassManager.GetATGRandomNext() * this.BucketSize;
                                float   num15 = GrassManager.GetATGRandomNext() * this.BucketSize;
                                Vector2 vector2;
                                vector2.x = (vector.x + num14) * this.OneOverTerrainSize.x;
                                vector2.y = (vector.y + num15) * this.OneOverTerrainSize.z;
                                float num16 = vector2.x * (float)(this.TerrainHeightmapWidth - 1);
                                float num17 = vector2.y * (float)(this.TerrainHeightmapHeight - 1);
                                int   num18 = (int)num16;
                                int   num19 = (int)num17;
                                int   num20 = (int)(num16 + 1f);
                                int   num21 = (int)(num17 + 1f);
                                float num22 = num16 - (float)num18;
                                float num23 = (float)num20 - num16;
                                float num24 = num17 - (float)num19;
                                float num25 = (float)num21 - num17;
                                num18 *= this.TerrainHeightmapHeight;
                                num20 *= this.TerrainHeightmapHeight;
                                float num26 = this.TerrainHeights[num18 + num19] * num23;
                                num26 += this.TerrainHeights[num20 + num19] * num22;
                                float num27 = this.TerrainHeights[num18 + num21] * num23;
                                num27 += this.TerrainHeights[num20 + num21] * num22;
                                this.tempPosition.y = num26 * num25 + num27 * num24;
                                float   num28 = this.GetfilteredHeight((vector2.x - num10) * (float)(this.TerrainHeightmapWidth - 1), vector2.y * (float)(this.TerrainHeightmapHeight - 1));
                                float   num29 = this.GetfilteredHeight((vector2.x + num11) * (float)(this.TerrainHeightmapWidth - 1), vector2.y * (float)(this.TerrainHeightmapHeight - 1));
                                float   num30 = this.GetfilteredHeight(vector2.x * (float)(this.TerrainHeightmapWidth - 1), (vector2.y + num13) * (float)(this.TerrainHeightmapHeight - 1));
                                float   num31 = this.GetfilteredHeight(vector2.x * (float)(this.TerrainHeightmapWidth - 1), (vector2.y - num12) * (float)(this.TerrainHeightmapHeight - 1));
                                Vector3 vector3;
                                vector3.x = -2f * (num29 - num28);
                                if (num4 != 2 && num4 != 4)
                                {
                                    vector3.y = 6.283184f * this.TerrainSizeOverHeightmap;
                                }
                                else
                                {
                                    vector3.y = 4f * this.TerrainSizeOverHeightmap;
                                }
                                vector3.z = (num30 - num31) * -2f;
                                float num32 = (float)Math.Sqrt((double)(vector3.x * vector3.x + vector3.y * vector3.y + vector3.z * vector3.z));
                                float num33 = 1f / num32;
                                vector3.x          *= num33;
                                vector3.y          *= num33;
                                vector3.z          *= num33;
                                this.tempPosition.x = this.tempSamplePosition.x + num14 + this.TerrainPosition.x;
                                this.tempPosition.z = this.tempSamplePosition.y + num15 + this.TerrainPosition.z;
                                float num34 = num6 + Mathf.PerlinNoise(this.tempPosition.x * num5, this.tempPosition.z * num5) * num7;
                                this.tempScale.x = num34;
                                this.tempScale.y = num34;
                                this.tempScale.z = num34;
                                Quaternion zeroQuat = this.ZeroQuat;
                                if (num4 != 2)
                                {
                                    zeroQuat.x = vector3.z;
                                    zeroQuat.y = 0f;
                                    zeroQuat.z = -vector3.x;
                                    zeroQuat.w = (float)Math.Sqrt((double)(1f + vector3.y));
                                    float num35 = (float)(1.0 / Math.Sqrt((double)(zeroQuat.w * zeroQuat.w + zeroQuat.x * zeroQuat.x + zeroQuat.y * zeroQuat.y + zeroQuat.z * zeroQuat.z)));
                                    zeroQuat.w *= num35;
                                    zeroQuat.x *= num35;
                                    zeroQuat.y *= num35;
                                    zeroQuat.z *= num35;
                                }
                                float      num36      = GrassManager.GetATGRandomNext() * 180f;
                                float      num37      = (float)Math.Cos((double)num36);
                                float      num38      = (float)Math.Sin((double)num36);
                                Quaternion quaternion = zeroQuat;
                                zeroQuat.x = quaternion.x * num37 - quaternion.z * num38;
                                zeroQuat.y = quaternion.w * num38 + quaternion.y * num37;
                                zeroQuat.z = quaternion.z * num37 + quaternion.x * num38;
                                zeroQuat.w = quaternion.w * num37 - quaternion.y * num38;
                                if (num4 == 1)
                                {
                                    num36 = GrassManager.GetATGRandomNext() * 180f;
                                    float num39 = (float)Math.Sin((double)num36);
                                    float num40 = (float)Math.Cos((double)num36);
                                    quaternion = zeroQuat;
                                    zeroQuat.x = quaternion.w * num39 + quaternion.x * num40;
                                    zeroQuat.y = quaternion.y * num40 + quaternion.z * num39;
                                    zeroQuat.z = quaternion.z * num40 - quaternion.y * num39;
                                    zeroQuat.w = quaternion.w * num40 - quaternion.x * num39;
                                }
                                this.tempMatrix.m03 = this.tempPosition.x;
                                this.tempMatrix.m13 = this.tempPosition.y + this.TerrainPosition.y;
                                this.tempMatrix.m23 = this.tempPosition.z;
                                float num41 = 2f * zeroQuat.x * zeroQuat.x;
                                float num42 = 2f * zeroQuat.y * zeroQuat.y;
                                float num43 = 2f * zeroQuat.z * zeroQuat.z;
                                this.tempMatrix.m00 = 1f - num42 - num43;
                                this.tempMatrix.m01 = 2f * zeroQuat.x * zeroQuat.y - 2f * zeroQuat.z * zeroQuat.w;
                                this.tempMatrix.m02 = 2f * zeroQuat.x * zeroQuat.z + 2f * zeroQuat.y * zeroQuat.w;
                                this.tempMatrix.m10 = 2f * zeroQuat.x * zeroQuat.y + 2f * zeroQuat.z * zeroQuat.w;
                                this.tempMatrix.m11 = 1f - num41 - num43;
                                this.tempMatrix.m12 = 2f * zeroQuat.y * zeroQuat.z - 2f * zeroQuat.x * zeroQuat.w;
                                this.tempMatrix.m20 = 2f * zeroQuat.x * zeroQuat.z - 2f * zeroQuat.y * zeroQuat.w;
                                this.tempMatrix.m21 = 2f * zeroQuat.y * zeroQuat.z + 2f * zeroQuat.x * zeroQuat.w;
                                this.tempMatrix.m22 = 1f - num41 - num42;
                                this.tempMatrix.m00 = this.tempMatrix.m00 * this.tempScale.x;
                                this.tempMatrix.m01 = this.tempMatrix.m01 * this.tempScale.y;
                                this.tempMatrix.m02 = this.tempMatrix.m02 * this.tempScale.z;
                                this.tempMatrix.m10 = this.tempMatrix.m10 * this.tempScale.x;
                                this.tempMatrix.m11 = this.tempMatrix.m11 * this.tempScale.y;
                                this.tempMatrix.m12 = this.tempMatrix.m12 * this.tempScale.z;
                                this.tempMatrix.m20 = this.tempMatrix.m20 * this.tempScale.x;
                                this.tempMatrix.m21 = this.tempMatrix.m21 * this.tempScale.y;
                                this.tempMatrix.m22 = this.tempMatrix.m22 * this.tempScale.z;
                                if (num4 == 2 && flag)
                                {
                                    Vector3 vector4 = vector3;
                                    float   num44   = -num36;
                                    num37 = (float)Math.Cos((double)num44);
                                    num38 = (float)Math.Sin((double)num44);
                                    float num45 = num38 * 2f;
                                    float num46 = num38 * num45;
                                    float num47 = num37 * num45;
                                    vector4.x           = (1f - num46) * vector3.x + num47 * vector3.z;
                                    vector4.z           = -num47 * vector3.x + (1f - num46) * vector3.z;
                                    this.tempMatrix.m30 = vector4.x;
                                    this.tempMatrix.m31 = vector4.y;
                                    this.tempMatrix.m32 = vector4.z;
                                }
                                else
                                {
                                    this.tempMatrix.m30 = 0f;
                                    this.tempMatrix.m31 = 0f;
                                    this.tempMatrix.m32 = 0f;
                                }
                                this.tempMatrix.m33 = (float)j + this.tempScale.x * 0.01f;
                                if (!AcresManager.Get().IsPointInsideAny(this.tempPosition))
                                {
                                    this.tempMatrixArray[num3] = this.tempMatrix;
                                    num3++;
                                }
                            }
                            this.tempSamplePosition.y = this.tempSamplePosition.y + this.BucketSize;
                        }
                        this.tempSamplePosition.y = this.samplePosition.y;
                        this.tempSamplePosition.x = this.tempSamplePosition.x + this.BucketSize;
                    }
                }
                grassCellContent.v_matrices = new Matrix4x4[num3];
                Array.Copy(this.tempMatrixArray, grassCellContent.v_matrices, num3);
            }
            grassCell.state = 2;
            return(1f);
        }