Exemplo n.º 1
0
    private void SetBuildingState(int index, int state, Sprite ruinsSprite)
    {
        if (index == 2 || index == 3)//排除动物和载具
        {
            return;
        }
        //状态值 0正常 1损坏 2摧毁
        if (effects != null && ruins != null && index < citySprites.Length)
        {
            if (effects[index] != null)
            {
                effects[index].SetActive(false);
            }
            if (ruins[index] != null)
            {
                ruins[index].gameObject.SetActive(false);
            }

            if (state == 1)
            {
                if (effects[index] != null)
                {
                    effects[index].SetActive(true);
                }
                else
                {
                    string path = FilePathTools.getEffectPath("SmokeLight");
                    AssetBundleLoadManager.Instance.LoadAsset <GameObject>(path, (go) => {
                        GameObject effect = GameUtils.createGameObject(citySprites[index].transform.GetChild(0).gameObject, go);
                        Quaternion q      = Quaternion.identity;
                        q.eulerAngles     = new Vector3(-90, 0, 0);
                        effect.transform.localRotation = q;
                        effect.transform.localPosition = new Vector3(0, 50, -100);
                        effects[index] = effect;
                    });
                }
            }
            else if (state == 2)
            {
                if (ruins[index] != null)
                {
                    ruins[index].gameObject.SetActive(true);
                }
                else
                {
                    GameObject ruinsGo = GameUtils.createGameObject(citySprites[index].transform.GetChild(0).gameObject, "ruins");
                    ruins[index]        = ruinsGo.AddComponent <Image>();
                    ruins[index].sprite = ruinsSprite;
                    ruins[index].SetNativeSize();
                }
            }
            else
            {
            }
        }
    }