Esempio n. 1
0
        public PropCell GetTableCell()
        {
            var tableCell = (PropCell)tableView.DequeueReusableCellForIdentifier(reuseIdentifier);

            if (!tableCell)
            {
                if (_propCellPrefab == null)
                {
                    var cellGameObject = new GameObject("teset");
                    tableCell = cellGameObject.AddComponent <PropCell>();
                    BSMLParser.instance.Parse(
                        Utilities.GetResourceContent(Assembly.GetExecutingAssembly(),
                                                     "SaberFactory.UI.Lib.PropCell.bsml"),
                        cellGameObject, tableCell);
                    _propCellPrefab = tableCell;
                }
                else
                {
                    tableCell = Instantiate(_propCellPrefab);
                }
            }

            tableCell.reuseIdentifier = reuseIdentifier;
            return(tableCell);
        }
    //执行三角格上对应的脚本
    private void DoTriCellFunc(GameObject triCell)
    {
        string instantiateItem = "";

        if (triCell.tag == "RandomCell")
        {
            RandomCell randomCell = triCell.GetComponent <RandomCell>();
            instantiateItem = randomCell.GetRandom(this);

            //获得了点数
            int result;
            if (int.TryParse(instantiateItem, out result))
            {
                StartCoroutine(GetCellEffect(InitNormalCells.pointSpriteDic[result]));
            }
            //获得了普通道具
            else
            {
                StartCoroutine(GetCellEffect(InitPropsCells.propSpriteDic[instantiateItem]));
            }
        }
        else if (triCell.tag == "PropCell")
        {
            PropCell proCell = triCell.GetComponent <PropCell>();
            instantiateItem = proCell.GetProp(this);
            StartCoroutine(GetCellEffect(PropCell.propSpriteDic[instantiateItem]));
        }
        else if (triCell.tag == "EventCell")
        {
            EventCell eventCell = triCell.GetComponent <EventCell>();
            eventCell.ExecuteEvent();

            AudioSource audioSource = triCell.GetComponent <AudioSource>();
            if (audioSource != null)
            {
                audioSource.Play();
            }
        }
    }
    //初始化道具格
    private void InitCellProps()
    {
        for (int i = 0; i < propsCells.Length; i++)
        {
            //获取父物体
            Transform propTrf = propsCells[i].transform;
            //每个格子生成道具
            for (int j = 0; j < propTrf.childCount; j++)
            {
                Transform propCellTrsf = propTrf.GetChild(j);
                PropCell  propCell     = propCellTrsf.GetComponent <PropCell>();
                propCellTrsf.tag = propTag[i];

                Vector3 scaleFactor = (propCellTrsf.rotation.z != 0) ?
                                      new Vector3(0.55f, 0.5f, 0) : new Vector3(0.5f, 0.55f, 0);

                GameObject propSprite = InstantiateSprite(propCellTrsf.gameObject, sprites[i], scaleFactor);
                if (!propSpriteDic.ContainsKey(propSprite.tag))
                {
                    propSpriteDic.Add(propSprite.tag, propSprite);
                }
            }
        }
    }