Example #1
0
    private void ComputeWormholeFragment(GameObject preGameObject, GameObject curGameObject)
    {
        /*
         * 从材质中的shader获取其阈值(十进制)
         * 当后一个关键帧的阈值为0时,说明无虫害变化
         * 当后一个关键帧的阈值不为0时,根据阈值变化确定每一帧的阈值的变化
         */
        Material preMaterial = GameObjectOperation.GetMaterial(preGameObject);
        Material curMaterial = GameObjectOperation.GetMaterial(curGameObject);

        if (preMaterial == null || preMaterial.shader.name != "Custom/Leaves")
        {
            m_WormholeFragment.Add(new WormholeFragment());
            return;
        }

        int preThreshold = CellularTexture.Color2DEC(preMaterial.GetColor("_Threshold"));
        int curThreshold = CellularTexture.Color2DEC(curMaterial.GetColor("_Threshold"));

        if (curThreshold == 0)
        {
            m_WormholeFragment.Add(new WormholeFragment());
        }
        else
        {
            m_WormholeFragment.Add(new WormholeFragment(preThreshold, (curThreshold - preThreshold) * 1.0 / m_AnimationMaxIndex));
        }
    }
Example #2
0
    private void CreateBranchModel()
    {
        /*
         * 更新枝干数据
         * 否则不会显示
         */
        GameObjectOperation.UpdateMeshInfo(BranchModel, temp_Vertices.ToArray(), temp_UV.ToArray(), temp_Triangles.ToArray());

        TempVariablesInit();

        /*
         * 养分
         */
        Material material = GameObjectOperation.GetMaterial(BranchModel);

        switch (EnvironmentParams.NutrientType)
        {
        case LightResponseType.N_LACK:
            //material.SetColor("_Color", MaizeParams.lackN_Color);
            break;

        case LightResponseType.P_LACK:
            material.SetColor("_Color", MaizeParams.lackP_Color);
            break;

        case LightResponseType.K_LACK:
            material.SetColor("_Color", MaizeParams.lackK_Color);
            break;
        }
    }
Example #3
0
    /// <summary>
    /// 更新该帧内的对象
    /// </summary>
    private void UpdateGameObject(GameObject preGameObject, GameObject curGameObject, List <Vector3> veticesFragment, WormholeFragment wormholeFragment)
    {
        if (m_AnimationIndex < m_AnimationMaxIndex)
        {
            /*
             * 若该片段为NULL或该片段的个数为0
             * 则说明该对象无顶点
             * 不继续进行计算
             */
            if (!GameObjectValidate.HavaVertices(preGameObject) || veticesFragment == null)
            {
                return;                                                                             //09-05
            }
            //09-05
            if (veticesFragment.Count != 0)
            {
                Vector3[] vertices = GameObjectOperation.GetVertices(preGameObject);

                /*
                 * 根据片段中记录的顶点偏移数据
                 * 计算对象在该帧移动后的位置
                 * 其中该片段记录的是世界坐标系下的数据
                 * 因此要转换成对象所在的局部坐标系下
                 */
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i] += veticesFragment[i];
                }

                /*
                 * 更新该对象
                 * 防止渲染出现异常
                 */
                GameObjectOperation.UpdateMeshInfo(preGameObject, vertices);
            }

            /*
             * 虫洞逐帧变化模拟
             * 当阈值增量为0,说明不变化
             * 当阈值增量不为0
             * 开启虫洞模拟 (_SimWormhole的值为1),并赋予相应的阈值
             */
            if (wormholeFragment.ThresholdDetla == 0)
            {
                return;
            }

            Material material = GameObjectOperation.GetMaterial(preGameObject);
            if (material == null || material.shader.name != "Custom/Leaves")
            {
                return;
            }

            material.SetFloat("_SimWormhole", 1);
            material.SetColor("_Threshold",
                              CellularTexture.DEC2Color(wormholeFragment.InitThreshold + (int)(wormholeFragment.ThresholdDetla * m_AnimationIndex))
                              );
        }
        else //最后一帧
        {
            /*
             * 无需计算
             * 只需设置前一关键帧的对象不可见
             * 后一帧对象可见即可
             */
            preGameObject.SetActive(false);
            curGameObject.SetActive(true);

            GameObjectOperation.ClearMaterials(preGameObject);
            GameObjectOperation.ClearMeshes(preGameObject);

            GameObject.Destroy(preGameObject);
        }
    }