コード例 #1
0
    CSUI_PlantGrid _createPlantGrid(FarmPlantLogic p)
    {
        CSUI_PlantGrid pg = Instantiate(m_PlantPart.m_PlantGridPrefab) as CSUI_PlantGrid;

        pg.transform.parent = m_PlantPart.m_Root.transform;
        CSUtils.ResetLoacalTransform(pg.transform);
        pg.m_Plant       = p;
        pg.OnDestroySelf = OnPlantGridDestroySelf;
        //ItemObject itemObj = ItemMgr.Instance.Get( pg.m_Plant.mInstanceId);
        //if (itemObj != null)
        //{
        string[] iconStr = ItemProto.Mgr.Instance.Get(pg.m_Plant.protoTypeId).icon;
        if (iconStr.Length != 0)
        {
            pg.IconSpriteName = iconStr[0];
        }
        else
        {
            pg.IconSpriteName = "";
        }
        //}
        m_PlantGrids.Add(pg);

        UICheckbox cb = pg.gameObject.GetComponent <UICheckbox>();

        cb.radioButtonRoot = m_PlantPart.m_Root.transform;
        cb.startsChecked   = false;

        return(pg);
    }
コード例 #2
0
    public void SetFarm(CSEntity enti)
    {
        if (enti == null)
        {
            Debug.LogWarning("Reference Entity is null.");
            return;
        }

        m_Entity = enti;
        CSFarm farm = enti as CSFarm;

        m_SequentialPlantingCB.isChecked = farm.Data.m_SequentialPlanting;

        if (farm == m_Farm)
        {
            return;
        }

        if (m_Farm != null)
        {
            m_Farm.CreatePlantEvent     -= OnCreatePlant;
            m_Farm.RemovePlantEvent     -= OnRemovePlant;
            m_Farm.CreatePlantListEvent -= OnCreatAllPlants;
            m_Farm.ClearAllPlantEvent   -= OnClearAllPlants;
            m_Farm.RemoveEventListener(OnEntityEvent);
        }

        m_Farm = farm;

        m_Farm.CreatePlantEvent     += OnCreatePlant;
        m_Farm.RemovePlantEvent     += OnRemovePlant;
        m_Farm.CreatePlantListEvent += OnCreatAllPlants;
        m_Farm.ClearAllPlantEvent   += OnClearAllPlants;
        m_Farm.AddEventListener(OnEntityEvent);

        int i = 0;

        foreach (FarmPlantLogic p in farm.Plants.Values)
        {
            if (i < m_PlantGrids.Count)
            {
            }
            else
            {
                CSUI_PlantGrid pg = _createPlantGrid(p);

                UICheckbox cb = pg.gameObject.GetComponent <UICheckbox>();
                if (i == 0)
                {
                    cb.startsChecked = true;
                }
            }
            i++;
        }

        for (int j = i; j < m_PlantGrids.Count;)
        {
            GameObject.Destroy(m_PlantGrids[j].gameObject);
            m_PlantGrids.RemoveAt(j);
        }

        m_PlantPart.m_Root.repositionNow = true;


        // Seed an tool grid
        for (int j = 0; j < CSFarm.PLANTS_SEEDS_COUNT; j++)
        {
            ItemObject io = m_Farm.GetPlantSeed(j);
            m_SeedsGrids[j].m_Grid.SetItem(io);
        }

        for (int j = 0; j < CSFarm.PLANTS_TOOLS_COUNT; j++)
        {
            ItemObject io = m_Farm.GetPlantTool(j);
            m_ToolsGrids[j].m_Grid.SetItem(io);
        }
    }
コード例 #3
0
 void OnPlantGridDestroySelf(CSUI_PlantGrid plantGrid)
 {
     m_PlantGrids.Remove(plantGrid);
     m_PlantPart.m_Root.repositionNow = true;
 }