示例#1
0
    //public void SelectTurret(int index)
    //{
    //    if (index < 0 || index >= turretCount) return;
    //    selectedTurret = index;
    //    for(int i = 0; i < turretCount; i++)
    //    {
    //        if (i == index) buttons[i].SetSelected(true);
    //        else buttons[i].SetSelected(false);
    //    }

    //}

    //public void SelectTurret(TurretSelectButton tsb)
    //{
    //    SelectTurret(tsb.index);
    //}

    //public void CancelSelect()
    //{
    //    selectedTurret = -1;
    //    for (int i = 0; i < turretCount; i++)
    //    {
    //        buttons[i].SetSelected(false);
    //    }
    //}

    public bool CanCreateTurret(Vector3 wPos)
    {
        Vector3Int cPos = mapController.WorldToCell(wPos);
        Vector3    aPos = mapController.CellToArray(cPos);

        if (stageController.gold < TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).price [0])
        {
            //AudioManager.instance.PlaySound("se_invalid");
            return(false);
        }

        if (mapController.CellOutOfBound(cPos))
        {
            return(false);
        }

        int i = mapController.GetMapArray()[(int)aPos.x, (int)aPos.y];//地块的标记

        if (i == Utils.GROUND || i == Utils.PLATFORM)
        {
            if (!mapController.gameObject.GetComponent <PathFinder>().CanPlaceTurret(new Vector2Int((int)aPos.x, (int)aPos.y)))
            {
                Debug.Log("不能把路堵死");
                //AudioManager.instance.PlaySound("se_invalid");
                return(false);
            }


            return(true);
        }

        return(false);
    }
示例#2
0
    public GameObject CreateTurret(Vector3 pos)
    {
        GameObject newTurret = null;

        int price = TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).price[0];

        if (stageController.gold >= price)
        {
            newTurret = Instantiate(selectablePrefabs[selectedTurret]);

            TurretScript ts = newTurret.GetComponent <TurretScript>();
            ts.SetPosition(pos);

            list_turret.Add(ts);

            if (ts.turretID == TurretInfo.TURRET_MINORIKO)
            {
                MinorikoScript ms = newTurret.GetComponent <MinorikoScript>();
                if (ms != null)
                {
                    list_minoriko.Add(ms);
                }
            }

            stageController.gold -= price;
        }

        return(newTurret);
    }
示例#3
0
 void addStatsToTurret(Stat[] stats, TurretInfo turret)
 {
     foreach (Stat stat in stats)
     {
         turret.IncrementStat(stat.Type, stat.Value);
     }
 }
 public void ShowTurretInfo(int id)
 {
     show_image.sprite = TurretInfo.GetTurretInfo(id).buttonImage;
     show_name.text    = TurretInfo.GetTurretInfo(id).name;
     show_intro.text   = TurretInfo.GetTurretInfo(id).intro;
     show_msg1.text    = "价格:" + TurretInfo.GetTurretInfo(id).price[0];
     show_msg2.text    = "";
 }
示例#5
0
    private void spawnTargetEntity(float x, float y, float z)
    {
        var info = new TurretInfo();

        info.definition = turret;
        info.facing     = transform.forward;
        info.position   = new float3(x, y, z);
        TurretInstantiator.instantiate(team, info, null);
    }
示例#6
0
    public void UpdateTurretInfo(TurretInfo buildingInfo)
    {
        Transform objectUI = ListUIObject.Find(buildingInfo.name);

        if (objectUI != null)
        {
            setTurretInfo(objectUI, buildingInfo);
        }
    }
示例#7
0
    public void AddTurretToSlot(TurretInfo buildingInfo, int slot)
    {
        if (slot >= turretsSlots.Count)
        {
            return;
        }

        turretsSlots[slot] = new KeyValuePair <Transform, TurretInfo>(turretsSlots[slot].Key, buildingInfo);
        setTurretInfo(turretsSlots[slot].Key, turretsSlots[slot].Value);
    }
示例#8
0
    Transform addTurretToUI(TurretInfo turretInfo)
    {
        Transform objectUI = Instantiate(ObjectUIPrefab, ListUIObject.position, ListUIObject.rotation).transform;

        setTurretInfo(objectUI, turretInfo, (currentKey + 1).ToString());
        UI.AddKey(keys[currentKey], () => Master.StartBuilding(turretInfo));
        currentKey++;
        objectUI.SetParent(ListUIObject, false);

        return(objectUI);
    }
示例#9
0
 // Update is called once per frame
 void Update()
 {
     if (clickGO != null)
     {
         info       = clickGO.GetComponent <Turret>().turretInfo;
         name.text  = info.name;
         lv.text    = info.lv.ToString();
         attck.text = info.attack.ToString();
         money.text = info.money.ToString();
         desc.text  = info.desc;
     }
 }
示例#10
0
    public bool ExistsTurret(TurretInfo turret)
    {
        foreach (KeyValuePair <Transform, TurretInfo> turretSlot in turretsSlots)
        {
            if (turretSlot.Value == turret)
            {
                return(true);
            }
        }

        return(false);
    }
示例#11
0
 public void SetID(int id)
 {
     this.turretID     = id;
     this.image.sprite = TurretInfo.GetSelectButtonImage(id);
     if (id == 0)
     {
         this.image.color = Color.clear;
     }
     else
     {
         this.image.color = Color.white;
     }
 }
示例#12
0
 void setTurretInfo(Transform objectUI, TurretInfo turretInfo, string key = "None")
 {
     objectUI.name = turretInfo.name;
     objectUI.GetComponent <Button>().onClick.RemoveAllListeners();
     objectUI.GetComponent <Button>().onClick.AddListener(() => Master.StartBuilding(turretInfo));
     objectUI.GetComponent <HoverElement>().SetHoverText(turretInfo.Description);
     objectUI.Find("Name").GetComponent <Text>().text = string.Format("{0}", turretInfo.name);
     objectUI.Find("Cost").GetComponent <Text>().text = string.Format("{0}", turretInfo.GetStat(StatType.PRICE));
     if (key != "None")
     {
         objectUI.Find("Key").GetComponent <Text>().text = string.Format("{0}", key);
     }
     objectUI.Find("Icon").GetComponent <Image>().sprite = turretInfo.Icon;
 }
示例#13
0
        private GameObject CreateTurretAssets()
        {
            List <TurretInfo> turrets = model.turrets;

            if (turrets.Count == 0)
            {
                return(null);
            }
            GameObject turretRoot = new GameObject("Turrets");

            for (int i = 0; i < turrets.Count; i++)
            {
                TurretInfo turret    = turrets[i];
                SubObject  obj       = model.GetSubObjectByIndex(turret.parentSubObjectIndex);
                GameObject turretObj = CreateRenderableGameObject(obj);

                if (turret.type == TurretType.Gun)
                {
                    turretObj.name = "[gun] " + turretObj.name;
                }
                else
                {
                    turretObj.name = "[missile] " + turretObj.name;
                }

                BoxCollider collider = turretObj.AddComponent <BoxCollider>();
                collider.size = obj.boundingBoxMax - obj.boundingBoxMin;
                turretObj.transform.parent        = turretRoot.transform;
                turretObj.transform.localPosition = obj.offset;
                // todo turn this back on
//                Turret turretComponent = turretObj.AddComponent<Turret>();
//                turretComponent.normal = turret.turretNormal;
//                turretComponent.firingPoints = turret.firingPoints;

                List <SubObject> children = GetChildSubObjects(obj);

                for (int j = 0; j < children.Count; j++)
                {
                    SubObject  child       = children[j];
                    GameObject turretChild = CreateRenderableGameObject(child);
                    turretChild.transform.parent        = turretObj.transform;
                    turretChild.transform.localPosition = new Vector3(); // not offset for some reason
                }
            }

            return(turretRoot);
        }
示例#14
0
    List <TurretInfo> LoadTurret()
    {
        List <TurretInfo> turret  = new List <TurretInfo>();
        XmlNodeList       xmlList = xmlDoc.SelectSingleNode("/game/turret").ChildNodes;


        foreach (XmlElement item in xmlList)
        {
            TurretInfo tur = new TurretInfo();
            tur.name        = item.Attributes["name"].Value;
            tur.attack      = int.Parse(item.Attributes["attack"].Value);
            tur.attackSpeed = float.Parse(item.Attributes["attackSpeed"].Value);
            tur.money       = int.Parse(item.Attributes["money"].Value);
            tur.desc        = item.Attributes["desc"].Value;
            turret.Add(tur);
        }
        //mon.money = int.Parse(xmlList[_index].Attributes["money"].Value);
        return(turret);
    }
示例#15
0
    public void CreateUIObjects()
    {
        HorizontalLayoutGroup layout = GetComponent <HorizontalLayoutGroup>();

        layout.spacing = turretCount;
        RectTransform rt = GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2((turretCount) * 150 + 100, 150);

        buttons = new TurretSelectButton[turretCount];


        for (int i = 0; i < turretCount; i++)
        {
            GameObject         newButton = Instantiate(buttonPrefab, this.gameObject.transform);
            TurretSelectButton tsb       = newButton.GetComponent <TurretSelectButton>();
            //tsb.image.sprite = images[i];
            tsb.SetID(selectableTurrets[i]);
            tsb.index = i;

            Text price   = newButton.transform.Find("Price").GetComponent <Text>();
            Text keycode = newButton.transform.Find("Keycode").GetComponent <Text>();

            price.text   = ("$" + TurretInfo.GetTurretInfo(tsb.turretID).price [0]);
            keycode.text = i + 1 + "";

            tsb.button.onClick.AddListener(

                delegate {
                updateUI.HideTurretInfo();
                SelectTurret(tsb);
            }

                );

            tsb.SetSelected(false);

            buttons[i] = tsb;
        }
    }
示例#16
0
        public DynamicVehicleStats(ListVehicleProfile profile, StaticVehicleStats staticStats)
        {
            List <int> ids = profile.profile_id.Split('-').Select(i => Convert.ToInt32(i)).ToList();

            ids.Remove(staticStats.EngineID);
            ids.Remove(staticStats.SuspensionID);
            int gunID = ids.First(i => staticStats.Guns.Contains(i));

            ids.Remove(gunID);
            int turretID = ids.Single();

            ids = null;

            Gun                  = new GunInfo(profile.gun, gunID);
            Turret               = new TurretInfo(profile.turret, turretID);
            AmmoCapacity         = profile.max_ammo;
            HP                   = Turret.HP + staticStats.BaseHP;
            Weight               = staticStats.BaseWeight + Gun.Weight + Turret.Weight;
            TraverseSpeed        = staticStats.BaseTraverse * (staticStats.StockWeight / Weight);
            Weight              /= 1000;
            HorsePowerToTonRatio = staticStats.HorsePower / Weight;
        }
    void Start()
    {
        images    = new Sprite[8];
        images[0] = s0; images[1] = s1; images[2] = s2; images[3] = s3; images[4] = s4; images[5] = s5; images[6] = s6; images[7] = s7;

        enemyList = GameObject.Find("Map").GetComponent <EnemyController>().enemyList;

        shootCountdown = fireRate / 2;

        stage = GameObject.Find("Map").GetComponent <StageController>();

        //加载塔的信息
        info = TurretInfo.GetTurretInfo(this.turretID);
        //Debug.Log("info is loaded");
        maxLevel = info.maxLevel;

        price = TurretInfo.GetTurretInfo(this.turretID).price[0];
        //Debug.Log("name: " + info.name);
        SetLevelData(0);

        //Debug.Log(TextEffectManager.instance);
        //GameObject g = TextEffectManager.instance.ShowTurretLevel(this);
    }
示例#18
0
        private bool CheckDiffTurretInfo(ref TurretInfo info, UnitSide side, int masterId, EntityId uid)
        {
            bool isChanged = false;

            if (info.Side != side)
            {
                info.Side = side;
                isChanged = true;
            }

            if (info.MasterId != masterId)
            {
                info.MasterId = masterId;
                isChanged     = true;
            }

            if (info.EntityId != uid)
            {
                info.EntityId = uid;
                isChanged     = true;
            }

            return(isChanged);
        }
    public static Entity instantiate(Team team, TurretInfo info, Rotation?parentRotation)
    {
        var entityManager = World.Active.EntityManager;
        var definition    = info.definition;

        instantiateData(definition);

        var turretBaseEntity = entityManager.Instantiate(entities[definition.basePrefab.GetHashCode()]);

        entityManager.SetComponentData(
            turretBaseEntity,
            new Translation {
            Value = info.position
        }
            );

        var rotation = quaternion.EulerXYZ(math.radians(info.facing.x), math.radians(info.facing.y), math.radians(info.facing.z));

        entityManager.SetComponentData(
            turretBaseEntity,
            new Rotation {
            Value = rotation
        }
            );

        var     gun             = definition.gun;
        var     turretGunEntity = entityManager.Instantiate(entities[gun.prefab.GetHashCode()]);
        TeamTag tag             = team.toComponent();

        tag.AssignToEntity(entityManager, turretGunEntity);

        entityManager.AddComponent(turretGunEntity, typeof(LocalToParent));
        entityManager.AddComponent(turretGunEntity, typeof(Parent));
        entityManager.SetComponentData <Parent>(
            turretGunEntity,
            new Parent {
            Value = turretBaseEntity
        }
            );

        entityManager.SetComponentData(
            turretGunEntity,
            new Translation {
            Value = definition.gunOffset
        }
            );
        entityManager.SetComponentData(
            turretGunEntity,
            new Rotation {
            Value = rotation
        }
            );
        entityManager.AddComponentData(turretGunEntity, new GunData {
            projectileEntity   = entities[gun.projectile.prefab.GetHashCode()],
            projectileOffset   = gun.barrelOffset,
            muzzleFlashEffect  = gun.muzzleEffectPrefab.GetHashCode(),
            projectileVelocity = gun.muzzleVelocity,
            reloadInterval     = gun.reloadInterval,
            fireInterval       = gun.fireInterval,
            shotsPerReload     = gun.shotsPerReload,
            shotDeviation      = math.radians(gun.shotDeviationDegrees),
            maximumPitchDelta  = math.radians(gun.maximumPitchDeltaDegrees),
            rotationSpeed      = 1f,
            pitchSpeed         = 5f,
            neutralRotation    = rotation,
            parentRotation     = parentRotation,
        });

        entityManager.AddComponentData(turretGunEntity, new GunState {
            currentFireInterval   = 0,
            currentReloadInterval = 0,
            shotsRemaining        = 4,
            currentPitch          = math.PI / 2f,
            targetPitchDelta      = math.PI / 2f,
        });

        return(turretBaseEntity);
    }
示例#20
0
    // Update is called once per frame
    void Update()
    {
        if (stageController.pausing)
        {
            return;
        }


        Vector3    lPos   = Input.mousePosition;
        Vector3Int cPos   = mapController.WorldToCell(Camera.main.ScreenToWorldPoint(lPos));
        Vector3    newPos = mapController.CellToWorld(cPos);

        //如果所选地点不在场景内,不管
        if (mapController.CellOutOfBound(cPos))
        {
            mouseMark.GetComponent <RectTransform>().anchoredPosition = new Vector2(5000, 5000);
            return;
        }
        //如果在场景内
        else
        {
            //获取所选塔
            selectedTurret = ui.selectedTurret;
            //如果已经选取了塔
            if (selectedTurret != -1)
            {
                mouseMark.GetComponent <RectTransform>().anchoredPosition = Utils.GetUIPosition(newPos);
                float r     = TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).range[0];
                float range = Utils.LengthLocalToUI(r * 2 * GameObject.Find("Map").GetComponent <MapController>().cellLocalSize);

                rangeMark.GetComponent <RectTransform>().sizeDelta = new Vector2(range, range);

                //能够造塔
                if (CanCreateTurret(newPos))
                {
                    mouseMark.GetComponent <Image>().color = Color.green;
                    //单击左键建造
                    if (Input.GetMouseButtonDown(0))
                    {
                        CreateTurret(newPos);

                        Vector3Int aPos = mapController.CellToArray(cPos);
                        mapController.mapArray[aPos.x, aPos.y] = Utils.TURRET;    //地图中此位置标记为TURRET

                        //敌人改变默认路径
                        GameObject.Find("Map").GetComponent <PathFinder>().RefreshDefaultPath();
                    }
                }
                //不能造塔
                else
                {
                    mouseMark.GetComponent <Image>().color = Color.red;

                    if (Input.GetMouseButtonDown(0))
                    {
                        AudioManager.instance.PlaySound("se_invalid");
                    }
                }
            }
            //没选中塔
            else
            {
                mouseMark.GetComponent <RectTransform>().anchoredPosition = new Vector2(5000, 5000);
                if (Input.GetMouseButtonDown(0))
                {
                    Vector3      wPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    TurretScript ts   = GetTurret(wPos);

                    if (ts != null && !GameObject.Find("TurretUpdateUI").GetComponent <TurretUpdateUIController>().Selected())
                    {
                        GameObject.Find("TurretUpdateUI").GetComponent <TurretUpdateUIController>().ShowTurretInfo(ts);
                    }
                }
            }
        }


        /*
         * //单机左键:摆放新炮塔或查看已摆放炮塔升级界面
         * if (Input.GetMouseButtonDown(0))
         * {
         *  selectedTurret = ui.selectedTurret;
         *
         *  //若已经选中炮塔:放置炮塔
         *  if(selectedTurret != -1)
         *  {
         *      //获得鼠标点击位置
         *      Vector3 lPos = Input.mousePosition;
         *      Vector3Int cPos = mapController.WorldToCell(Camera.main.ScreenToWorldPoint(lPos));
         *      Vector3 newPos = mapController.CellToWorld(cPos);
         *
         *      //如果所选地点不在场景内,不管
         *      if (mapController.CellOutOfBound(cPos)) return;
         *
         *
         *      //如果能放置,则根据选取的角色放置炮塔
         *      if (CanCreateTurret(newPos))
         *      {
         *          CreateTurret(newPos);
         *
         *          Vector3Int aPos = mapController.CellToArray(cPos);
         *          mapController.mapArray[aPos.x, aPos.y] = Utils.TURRET;    //地图中此位置标记为TURRET
         *
         *          //敌人改变默认路径
         *          GameObject.Find("Map").GetComponent<PathFinder>().RefreshDefaultPath();
         *          //Debug.Log("place a turret");
         *      }
         *      else
         *      {
         *          //AudioSource.PlayClipAtPoint(AudioManager.se_invalid,new Vector3(0,0,0));
         *          //AudioManager.instance.PlaySound("se_invalid");
         *      }
         *
         *      return;
         *  }
         *  //否则查看升级界面
         *  else
         *  {
         *
         *
         *  }
         *
         *
         * }*/

        //右键取消选择
        //if(Input.GetMouseButtonDown(1))
        //{
        //    CancelSelect();
        //}
    }
示例#21
0
 public void SelectTurretToBuild(TurretInfo turret)
 {
     turretToBuild = turret;
 }