Exemplo n.º 1
0
    private Texture GetWormholeTex(double actualInsectIntake, out int threshold)
    {
        /*
         * 阈值
         * 用于后续关键帧动画中虫洞的模拟
         * 当为0时表示虫洞未发生变化
         */
        threshold = 0;

        /*
         * 存在的各种情况:
         * 1、该叶片不受病虫影响
         *     1.1、该叶片原先无病虫害,故现在也无病虫害,即叶面积(LeafArea)与未受病虫害的叶面积(LeafArea_Uninsected)相等
         *          故该模型的纹理无需替换
         *     1.2、该叶片原先有病虫害,再分两种情况:
         *          1.2.1、与昨日的模型相同,即今日模型的哈希值与昨日模型的哈希值相同,故叶片形态、纹理与昨日相同
         *          故直接调用昨日模型的纹理即可
         *          1.2.2、与昨日的模型不同,即该叶片发育到不同的阶段(成熟或衰老),故调用的纹理与昨日不同
         *          故重新生成虫洞纹理
         * 2、该叶片受病虫影响
         *    形态不同,故直接重新生成虫洞纹理
         */
        if (LeafArea == LeafArea_Uninsected)
        {
            return(null);
        }
        else if (Texture_PreDay != null &&
                 actualInsectIntake <= 0 && LeafMesh.GetHashCode() == MeshHashCode_PreDay)
        {
            return(Texture_PreDay);
        }
        else
        {
            if (Texture_PreDay != null && Texture_PreDay.name == "Wormhole Texture")
            {
                if (LScene.GetInstance().HaveAnimator)
                {
                    GameObjectOperation.DestroyTexWithoutAnimation(Texture_PreDay);
                }
                else
                {
                    GameObject.Destroy(Texture_PreDay);
                }

                Texture_PreDay = null;
            }

            Texture leafTex = GameObjectOperation.GetTexture(Belong);

            Texture wormholeTex = CelluarTex.CreateWormhole(InsectedRatio, leafTex, out threshold);
            wormholeTex.name = "Wormhole Texture";

            /*
             * 清除纹理
             * 释放内存
             */
            if (leafTex.name == "Wormhole Texture")
            {
                GameObject.DestroyObject(leafTex);
            }

            return(wormholeTex);
        }
    }