Beispiel #1
0
 void CreateAnimal()
 {
     int id = GameCenter.mercenaryMng.curPetId;   
     int index = 0;
     foreach (MercenaryInfo item in mercenaryInfoList.Values)
     {
         if (!singleSpritAnimalList.ContainsKey(item.ConfigId))
         {
             singleSpritAnimalList[item.ConfigId] = SingleSpritAnimal.CeateNew(animaListParent, index);
         }
         SingleSpritAnimal animal = singleSpritAnimalList[item.ConfigId] as SingleSpritAnimal;
         animal.gameObject.SetActive(true);
         animal.transform.localPosition = new Vector3(0, -index * 110, 0);
         animal.SetInfo(item);
         UIEventListener.Get(animal.gameObject).onClick -= OnClickSingleAnimal;
         UIEventListener.Get(animal.gameObject).onClick += OnClickSingleAnimal;
         index++;
     }
     if (id != MercenaryMng.noPet)
     {
         SingleSpritAnimal animal = singleSpritAnimalList[id] as SingleSpritAnimal;
         if (animal != null)
         {
             UIToggle tog = animal.GetComponent<UIToggle>();
             if (tog != null) tog.value = true;
         }
     }
 }
Beispiel #2
0
    public static SingleSpritAnimal CeateNew(GameObject _parent, int _index)
    {
        if (_index < 0)
        {
            GameSys.LogError("位置序数不能为负数!");
            return(null);
        }
        Object prefab = null;

        if (prefab == null)
        {
            prefab = exResources.GetResource(ResourceType.GUI, "SpiritAnimal/Single_Congwu");
        }
        if (prefab == null)
        {
            GameSys.LogError("找不到预制:SpiritAnimal/Single_Congwu");
            return(null);
        }
        GameObject obj = Instantiate(prefab) as GameObject;

        prefab = null;
        obj.transform.parent        = _parent.transform;
        obj.transform.localPosition = new Vector3(0, -_index * 110, 0);
        obj.transform.localScale    = Vector3.one;
        SingleSpritAnimal itemUI = obj.GetComponent <SingleSpritAnimal>();

        if (itemUI == null)
        {
            GameSys.LogError("预制上找不到组件:<SingleSpritAnimal>");
            return(null);
        }
        return(itemUI);
    }