Beispiel #1
0
 private void OnDisable()
 {
     if (this.m_Material)
     {
         DelegateProxy.DestroyObjectImmediate(this.m_Material);
     }
 }
Beispiel #2
0
 protected virtual void OnDisable()
 {
     if (this.mMaterial)
     {
         DelegateProxy.DestroyObjectImmediate(this.mMaterial);
     }
 }
Beispiel #3
0
    /// <summary>
    /// 根据当前场景的地图信息,计算生成地形网格顶点列表
    /// </summary>
    public void BuildGeometry()
    {
        if (this.mesh == null)
        {
            this.mesh = new Mesh();
        }
        int segmentsW = this.terrainData.segmentsW;
        int segmentsH = this.terrainData.segmentsH;
        int num       = segmentsW + 1;
        int num2      = (segmentsH + 1) * num;

        this.vertices = new Vector3[num2];
        num2          = 0;
        for (int i = 0; i <= segmentsH; i++)
        {
            for (int j = 0; j <= segmentsW; j++)
            {
                float num3   = ((float)j / (float)segmentsW - 0.5f) * this.terrainData.size.x;
                float num4   = ((float)i / (float)segmentsH - 0.5f) * this.terrainData.size.z;
                float height = GameScene.mainScene.terrainData.GetHeight(Mathf.FloorToInt(num3 + base.transform.position.x + 240f), Mathf.FloorToInt(num4 + base.transform.position.z + 240f));
                this.vertices[num2] = new Vector3(num3, height, num4);
                num2++;
            }
        }
        this.mesh.vertices = this.vertices;
        if (Application.isEditor && base.gameObject != null)         //如果是编辑器环境,销毁重建网格碰撞器
        {
            MeshCollider component = base.gameObject.GetComponent <MeshCollider>();
            if (component != null)
            {
                DelegateProxy.DestroyObjectImmediate(component);
                base.gameObject.AddComponent <MeshCollider>();
            }
        }
    }
Beispiel #4
0
 public bool Load(Texture2D brushTex, int size)
 {
     if (this.m_Brush == brushTex && size == this.size && this.strength != null)
     {
         return(true);
     }
     if (brushTex != null)
     {
         float num = (float)size;
         this.size     = size;
         this.strength = new float[this.size * this.size];
         if (this.size > 3)
         {
             for (int i = 0; i < this.size; i++)
             {
                 for (int j = 0; j < this.size; j++)
                 {
                     this.strength[i * this.size + j] = brushTex.GetPixelBilinear(((float)j + 0.5f) / num, (float)i / num).a;
                 }
             }
         }
         else
         {
             for (int k = 0; k < this.strength.Length; k++)
             {
                 this.strength[k] = 1f;
             }
         }
         DelegateProxy.DestroyObjectImmediate(this.m_Preview);
         this.m_Preview            = new Texture2D(this.size, this.size, TextureFormat.ARGB32, false);
         this.m_Preview.wrapMode   = TextureWrapMode.Clamp;
         this.m_Preview.filterMode = FilterMode.Point;
         Color[] array = new Color[this.size * this.size];
         for (int l = 0; l < array.Length; l++)
         {
             array[l] = new Color(0f, 0f, 0f, this.strength[l]);
         }
         this.m_Preview.SetPixels(0, 0, this.size, this.size, array, 0);
         this.m_Preview.Apply();
         if (this.m_BrushProjector == null)
         {
             this.CreatePreviewBrush();
         }
         this.m_BrushProjector.orthographicSize = (float)size * 0.46875f;
         this.m_BrushProjector.material.SetTexture("_CutoutTex", this.m_Preview);
         this.m_BrushProjector.material.mainTexture = brushTex;
         this.m_Brush = brushTex;
         return(true);
     }
     this.strength = new float[]
     {
         1f
     };
     this.size = 1;
     return(false);
 }
Beispiel #5
0
 public void Dispose()
 {
     if (this.m_BrushProjector != null)
     {
         DelegateProxy.DestroyObjectImmediate(this.m_BrushProjector.material.shader);
         DelegateProxy.DestroyObjectImmediate(this.m_BrushProjector.material);
         DelegateProxy.DestroyObjectImmediate(this.m_BrushProjector.gameObject);
         this.m_BrushProjector = null;
     }
     DelegateProxy.DestroyObjectImmediate(this.m_Preview);
     this.m_Preview = null;
 }
Beispiel #6
0
    /// <summary>
    /// 构建水体几何体信息
    /// </summary>
    public void BuildGeometry()
    {
        TerrainConfig terrainConfig = GameScene.mainScene.terrainConfig;

        if (Water.mesh == null)
        {
            Water.mesh = new Mesh();
        }
        int num  = this.segmentsW;
        int num2 = this.segmentsH;
        int num3 = 0;
        int num4 = num + 1;
        int num5 = (num2 + 1) * num4;

        this.vertices  = new Vector3[num5];
        this.triangles = new int[num2 * num * 6];
        this.normals   = new Vector3[num5];
        num5           = 0;
        for (int i = 0; i <= num2; i++)
        {
            for (int j = 0; j <= num; j++)
            {
                float x = ((float)j / (float)num - 0.5f) * (float)terrainConfig.tileSize;
                float z = ((float)i / (float)num2 - 0.5f) * (float)terrainConfig.tileSize;
                float y = 0f;
                this.vertices[num5] = new Vector3(x, y, z);
                num5++;
                if (j != num && i != num2)
                {
                    int num6 = j + i * num4;
                    this.triangles[num3++] = num6;
                    this.triangles[num3++] = num6 + num4;
                    this.triangles[num3++] = num6 + num4 + 1;
                    this.triangles[num3++] = num6;
                    this.triangles[num3++] = num6 + num4 + 1;
                    this.triangles[num3++] = num6 + 1;
                }
            }
        }
        Water.mesh.vertices  = this.vertices;
        Water.mesh.triangles = this.triangles;
        if (Application.isEditor && base.gameObject != null)
        {
            MeshCollider component = base.gameObject.GetComponent <MeshCollider>();
            if (component != null)
            {
                DelegateProxy.DestroyObjectImmediate(component);
                base.gameObject.AddComponent <MeshCollider>();
            }
        }
    }
Beispiel #7
0
    public override UnityEngine.Object Instantiate(UnityEngine.Object prefab)
    {
        GameObject gameObject  = DelegateProxy.Instantiate(prefab) as GameObject;
        GameObject gameObject2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        MeshFilter component   = gameObject2.GetComponent <MeshFilter>();

        gameObject.AddComponent <MeshFilter>().sharedMesh = component.sharedMesh;
        gameObject.AddComponent <MeshCollider>();
        Material sharedMaterial = new Material(Shader.Find("Snail/Diffuse"));

        gameObject.AddComponent <MeshRenderer>().sharedMaterial = sharedMaterial;
        gameObject.GetComponent <MeshRenderer>().castShadows    = false;
        gameObject.GetComponent <MeshRenderer>().receiveShadows = false;
        this.unit.localScale = new Vector3(5f, 5f, 5f);
        gameObject.AddComponent <AmbienceSampler>();
        DelegateProxy.DestroyObjectImmediate(gameObject2);
        return(gameObject);
    }
Beispiel #8
0
 /// <summary>
 /// 移除水体
 /// </summary>
 public void RemoveWater()
 {
     if (this.water != null)
     {
         if (GameScene.isPlaying)
         {
             DelegateProxy.GameDestory(this.water.gameObject);
         }
         else
         {
             DelegateProxy.DestroyObjectImmediate(this.water.gameObject);
         }
         this.water     = null;
         this.waterData = null;
         if (this.terrain != null)
         {
             this.terrain.hasWater = false;
             this.terrain.BuildMaterial(null);
         }
     }
 }
Beispiel #9
0
    public static void RemoveAllChildObject(GameObject parent, bool bImmediate)
    {
        int num = parent.transform.childCount - 1;

        while (0 <= num)
        {
            if (num < parent.transform.childCount)
            {
                Transform child = parent.transform.GetChild(num);
                if (bImmediate)
                {
                    DelegateProxy.DestroyObjectImmediate(child.gameObject);
                }
                else
                {
                    DelegateProxy.GameDestory(child.gameObject);
                }
            }
            num--;
        }
    }
Beispiel #10
0
    public override UnityEngine.Object Instantiate(UnityEngine.Object prefab)
    {
        GameObject gameObject = DelegateProxy.Instantiate(prefab) as GameObject;

        this.light = gameObject.light;
        if (gameObject.light == null)
        {
            return(gameObject);
        }
        if (!this.firstRun)
        {
            this.light.type               = this.type;
            this.light.color              = this.color;
            this.light.intensity          = this.intensity;
            this.light.shadows            = this.shadows;
            this.light.shadowStrength     = this.shadowStrength;
            this.light.shadowBias         = this.shadowBias;
            this.light.shadowSoftness     = this.shadowSoftness;
            this.light.shadowSoftnessFade = this.shadowSoftnessFade;
            this.light.range              = this.range;
            this.light.spotAngle          = this.spotAngle;
            this.light.cullingMask        = this.cullingMask;
        }
        if (!Application.isPlaying)
        {
            GameObject gameObject2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            MeshFilter component   = gameObject2.GetComponent <MeshFilter>();
            gameObject.AddComponent <MeshFilter>().sharedMesh = component.sharedMesh;
            gameObject.AddComponent <MeshCollider>();
            DelegateProxy.DestroyObjectImmediate(gameObject2);
        }
        if (LightmapSettings.lightmaps.Length > 0)
        {
            this.light.enabled = false;
            gameObject.SetActive(false);
        }
        return(gameObject);
    }
Beispiel #11
0
 /// <summary>
 /// 更新计算阻塞tile列表
 /// </summary>
 public void ComputeTiles()
 {
     this.ClearTiles();
     this.mainTile = this.scene.GetTileAt(this.position);
     if (this.mainTile != null)
     {
         this.AddTile(this.mainTile);
         if (this.ins != null)
         {
             BoxCollider boxCollider = this.ComputeBounds();
             if (boxCollider != null)
             {
                 this.cullingFactor = boxCollider.bounds.size.magnitude;                      //根据碰撞体的,包围盒对角线长度做剔除因子
             }
             if (this.cullingFactor <= 0.01f)
             {
                 this.cullingFactor = this.scene.terrainConfig.defautCullingFactor;
             }
             this.UpdateViewRange();
             for (int i = 0; i < this.scene.tiles.Count; i++)                   //遍历当前场景的所有tile
             {
                 Tile tile = this.scene.tiles[i];
                 if (boxCollider != null && boxCollider.bounds.Intersects(tile.bounds))                      //unit有碰撞,通过包围盒检测是否包含到该tile中去
                 {
                     this.AddTile(tile);
                 }
             }
             if (boxCollider != null)                     //使用完了就销毁,也就是说实际游戏运行中,不进行实际碰撞处理,依赖于服务器吧
             {
                 DelegateProxy.DestroyObjectImmediate(boxCollider);
             }
         }
     }
     if (this.tiles.Count < 1)
     {
         Debug.Log("该单位没有所属切片, 无法进行存储! 单位编号[" + this.createID + "]");
     }
 }
Beispiel #12
0
 /// <summary>
 /// 禁用,销毁采样得到的纹理,临时用相机等
 /// </summary>
 private void OnDisable()
 {
     if (this.m_ReflectionTexture)
     {
         DelegateProxy.DestroyObjectImmediate(this.m_ReflectionTexture);
         this.m_ReflectionTexture = null;
     }
     if (this.m_RefractionTexture)
     {
         DelegateProxy.DestroyObjectImmediate(this.m_RefractionTexture);
         this.m_RefractionTexture = null;
     }
     foreach (KeyValuePair <Camera, Camera> current in this.m_ReflectionCameras)
     {
         DelegateProxy.DestroyObjectImmediate(current.Value.gameObject);
     }
     this.m_ReflectionCameras.Clear();
     foreach (KeyValuePair <Camera, Camera> current2 in this.m_RefractionCameras)
     {
         DelegateProxy.DestroyObjectImmediate(current2.Value.gameObject);
     }
     this.m_RefractionCameras.Clear();
 }
Beispiel #13
0
 public static void DestroyLaunch(GameObject obj)
 {
     Resources.UnloadUnusedAssets();
     GC.Collect();
     DelegateProxy.DestroyObjectImmediate(obj);
 }
Beispiel #14
0
 /// <summary>
 /// 销毁回收
 /// </summary>
 public void Destroy()
 {
     if (GameScene.isPlaying)
     {
         if (this.waterData != null)
         {
             this.waterData.Release();
         }
         if (this.terrain != null)
         {
             this.terrain.Destroy();
             DelegateProxy.GameDestory(this.terrain);
             DelegateProxy.GameDestory(this.terrain.gameObject);
             this.terrain = null;
         }
         if (this.water != null)
         {
             this.water.Destroy();
             DelegateProxy.GameDestory(this.water);
             DelegateProxy.GameDestory(this.water.gameObject);
             this.water = null;
         }
     }
     else
     {
         if (this.terrain != null)
         {
             DelegateProxy.DestroyObjectImmediate(this.terrain.gameObject);
         }
         if (this.water != null)
         {
             DelegateProxy.DestroyObjectImmediate(this.water.gameObject);
         }
     }
     //同时销毁tile上的(静态)unit
     if (this.units != null)
     {
         while (this.units.Count > 0)
         {
             GameObjectUnit gameObjectUnit = this.units[0];
             //进行destory,放入cache待重用
             if (this.scene.ContainUnit(gameObjectUnit))
             {
                 this.scene.RemoveUnit(gameObjectUnit, true, true);
             }
             else
             {
                 //场景不包含的unit,销毁,并加入静态缓存待重用
                 gameObjectUnit.Destroy();
                 this.scene.RemoveEmptyUnit(gameObjectUnit);
             }
         }
         this.units.Clear();
         this.units = null;
         this.unitsMap.Clear();
         this.unitsMap = null;
     }
     this.left               = null;
     this.right              = null;
     this.top                = null;
     this.bot                = null;
     this.top_left           = null;
     this.top_right          = null;
     this.bot_left           = null;
     this.bot_right          = null;
     this.region             = null;
     this.scene              = null;
     this._lightmapPrototype = null;
     this.waterData          = null;
     this.heights            = new float[0, 0];
     this.grids              = new int[0, 0];
     this.heights            = null;
     this.grids              = null;
 }
Beispiel #15
0
 /// <summary>
 /// 销毁unit游戏对象
 /// </summary>
 public virtual void Destroy()
 {
     if (this.destroyInsListener != null)
     {
         try
         {
             this.destroyInsListener();
         }
         catch (Exception ex)
         {
             LogSystem.LogError(new object[]
             {
                 "监听创建单位函数中出错!" + ex.ToString()
             });
         }
     }
     if (this.ins != null)
     {
         if (GameScene.isPlaying)
         {
             DelegateProxy.GameDestory(this.ins);
         }
         else
         {
             DelegateProxy.DestroyObjectImmediate(this.ins);
         }
     }
     if (this.combinUnitIDs != null)
     {
         this.combinUnitIDs.Clear();
     }
     this.combineParentUnitID = -1;
     if (this.tiles != null)
     {
         for (int i = 0; i < this.tiles.Count; i++)
         {
             this.tiles[i].RemoveUnit(this);
         }
         this.tiles.Clear();
     }
     if (this.materials != null)
     {
         this.materials.Clear();
         this.materials = null;
     }
     this.active = false;
     this.grids  = null;
     this.pre    = null;
     this.ins    = null;
     if (this.unitParser != null)
     {
         this.unitParser.Destroy();
         this.unitParser = null;
     }
     if (this.lightmapPrototypes != null)
     {
         this.lightmapPrototypes.Clear();
     }
     this.bornEffectPrePath  = string.Empty;
     this.bornEffect         = null;
     this.dataLength         = -1L;
     this.prePath            = string.Empty;
     this.createInsListener  = null;
     this.destroyInsListener = null;
     this.activeListener     = null;
     this.visible            = false;
     this.destroyed          = true;
     this.scene  = null;
     this.readed = false;
 }
Beispiel #16
0
 /// <summary>
 /// 给指定相机创建采样水体需要的摄像机对象
 /// </summary>
 /// <param name="currentCamera"></param>
 /// <param name="reflectionCamera"></param>
 /// <param name="refractionCamera"></param>
 private void CreateWaterObjects(Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera)
 {
     AmbienceSampler.WaterMode waterMode = this.GetWaterMode();
     reflectionCamera = null;
     refractionCamera = null;
     if (waterMode >= AmbienceSampler.WaterMode.Reflective)
     {
         if (!this.m_ReflectionTexture || this.m_OldReflectionTextureSize != this.m_TextureSize)
         {
             if (this.m_ReflectionTexture)
             {
                 DelegateProxy.DestroyObjectImmediate(this.m_ReflectionTexture);
             }
             this.m_ReflectionTexture              = new RenderTexture(this.m_TextureSize, this.m_TextureSize, 16);
             this.m_ReflectionTexture.name         = "__WaterReflection" + base.GetInstanceID();
             this.m_ReflectionTexture.isPowerOfTwo = true;
             this.m_ReflectionTexture.hideFlags    = HideFlags.DontSave;
             this.m_ReflectionTexture.format       = RenderTextureFormat.ARGB32;
             this.m_OldReflectionTextureSize       = this.m_TextureSize;
         }
         this.m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
         if (!reflectionCamera)
         {
             GameObject gameObject = new GameObject(string.Concat(new object[]
             {
                 "Water Refl Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             reflectionCamera                    = gameObject.camera;
             reflectionCamera.enabled            = false;
             reflectionCamera.transform.position = base.transform.position;
             reflectionCamera.transform.rotation = base.transform.rotation;
             reflectionCamera.gameObject.AddComponent("FlareLayer");
             gameObject.hideFlags = HideFlags.HideAndDontSave;
             this.m_ReflectionCameras[currentCamera] = reflectionCamera;
         }
     }
     if (waterMode >= AmbienceSampler.WaterMode.Refractive)
     {
         if (!this.m_RefractionTexture || this.m_OldRefractionTextureSize != this.m_TextureSize)
         {
             if (this.m_RefractionTexture)
             {
                 DelegateProxy.DestroyObjectImmediate(this.m_RefractionTexture);
             }
             this.m_RefractionTexture              = new RenderTexture(this.m_TextureSize, this.m_TextureSize, 16);
             this.m_RefractionTexture.name         = "__WaterRefraction" + base.GetInstanceID();
             this.m_ReflectionTexture.isPowerOfTwo = true;
             this.m_RefractionTexture.hideFlags    = HideFlags.DontSave;
             this.m_RefractionTexture.format       = RenderTextureFormat.ARGB32;
             this.m_OldRefractionTextureSize       = this.m_TextureSize;
         }
         this.m_RefractionCameras.TryGetValue(currentCamera, out refractionCamera);
         if (!refractionCamera)
         {
             GameObject gameObject2 = new GameObject(string.Concat(new object[]
             {
                 "Water Refr Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             refractionCamera                    = gameObject2.camera;
             refractionCamera.enabled            = false;
             refractionCamera.transform.position = base.transform.position;
             refractionCamera.transform.rotation = base.transform.rotation;
             refractionCamera.gameObject.AddComponent("FlareLayer");
             gameObject2.hideFlags = HideFlags.HideAndDontSave;
             this.m_RefractionCameras[currentCamera] = refractionCamera;
         }
     }
 }