예제 #1
0
    private GameObject CreateShipGroup(ClientShip targetShip, string targetShipResPath, float shipWrapRadius)
    {
        GameObject group = new GameObject();

        group.transform.SetParent(DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform);

        //约定组名为目标舰船在数据索引值,记录之,方便传给战斗布阵单元的坐标
        group.name = PlayerSys.GetPlayerShipList().IndexOf(targetShip).ToString();
        // 初始化阵形
        BattleSys.SetFormation(true, targetShip);
        //成组上阵,组中舰船的数量
        int groupMemberCount = targetShip.Reference.stack ? targetShip.Reference.stack_num : 1;

        BoxCollider tempCollider = null;

        for (int i = 0; i < groupMemberCount; i++)
        {
            Vector3    pos    = targetShip.FormationList == null ? Vector3.zero : targetShip.FormationList[i];
            GameObject member = CreateShip(targetShipResPath, group.transform, GridDrawer.OffsetByWrapRadius(pos, shipWrapRadius));

            if (tempCollider == null)
            {
                tempCollider = member.GetComponent <BoxCollider>();
            }
            Destroy(member.GetComponent <BoxCollider>());
            DestoryTrailEffect(member);
        }

        //添加tag,用于点选式布阵的碰撞检测
        group.tag = "ShipModel";

        return(group);
    }
예제 #2
0
    /// <summary>
    /// 记录布阵情况(索引,对应世界坐标)
    /// </summary>
    public void RecordDeployInfo()
    {
        Transform formationRoot = DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform;

        for (int i = 0; i < formationRoot.childCount; i++)
        {
            Transform t     = formationRoot.transform.GetChild(i);
            int       index = int.Parse(t.name);
            //Debug.Log( string.Format( "<color=green>RecordDeployInfo, index : {0}, position : {1}</color>", index, t.position ) );
            ClientShip cs = PlayerSys.GetPlayerShipList()[index];
            if (cs == null)
            {
                Debugger.LogError("RecordDeployInfo Failed! At index : " + index);
                return;
            }

            PlayerSys.Formation(index, t.position + new Vector3(cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE, 0f, cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE));//纠正偏移
        }
    }
예제 #3
0
파일: DeployPanel.cs 프로젝트: LynnPi/OF
    /// <summary>
    /// 生成玩家可布阵舰船的视图列表
    /// </summary>
    private void GeneratePlayerShipListView()
    {
        List <ClientShip> dataList = PlayerSys.GetPlayerShipList();
        //哈希结构,键--舰船ID,值--拥有该ID的舰船集合
        Dictionary <int, List <int> > hash = new Dictionary <int, List <int> >();

        for (int index = 0; index < dataList.Count; index++)
        {
            int key = dataList[index].Reference.id;
            if (!hash.ContainsKey(key))
            {
                hash.Add(key, new List <int>());
            }
            hash[key].Add(index);
        }

        foreach (var id in hash)
        {
            string log = "";
            foreach (var item in id.Value)
            {
                log += string.Format("{0}, ", item);
            }
            //Debug.Log( string.Format( "<color=yellow>[ID{0}] : {1}</color>", id.Key, log) );
        }

        UnitUIElementList_ = new List <DeployUnitUIElement>();

        foreach (var item in hash)
        {
            GameObject scrollItem = Global.CreateUI("deployitem", ScrollViewRoot.gameObject);
            scrollItem.name = item.Key.ToString();
            DeployUnitUIElement view = scrollItem.AddComponent <DeployUnitUIElement>();
            view.SyncEnergy += SyncEnergy;
            proto.UnitReference unit = GlobalConfig.GetUnitReference(item.Key);
            view.ShipName       = unit.name;
            view.WrapPointCount = unit.warp_cost;
            view.IconName       = unit.iconfile;
            view.Level          = 10;//舰船成长,暂时没得
            foreach (var v in item.Value)
            {
                view.ReadyDeployIndexQueue.Enqueue(v);
            }
            view.UnitCount = item.Value.Count;
            UnitUIElementList_.Add(view);
        }

        foreach (var item in UnitUIElementList_)
        {
            bool cannotDeployThisType = item.WrapPointCount > CurrRemainEnergy_;
            if (cannotDeployThisType)
            {
                item.SetDragAbility(false);
            }
            else
            {
                if (item.ReadyDeployIndexQueue.Count == 0)
                {
                    continue;
                }
                item.SetDragAbility(true);
            }
        }
    }