Ejemplo n.º 1
0
 // Pop a unit list update; return null if there isn't one.
 public RemoteFortressReader.UnitList PopUnitListUpdate()
 {
     lock (unitListLock)
     {
         RemoteFortressReader.UnitList result = _netUnitList;
         _netViewInfo = null;
         return(result);
     }
 }
Ejemplo n.º 2
0
    void UpdateCreatures()
    {
        unitList = DFConnection.Instance.PopUnitListUpdate();
        if (unitList == null) return;
        foreach (var unit in unitList.creature_list)
        {
            if (creatureList == null)
                creatureList = new Dictionary<int, AtlasSprite>();
            UnitFlags1 flags1 = (UnitFlags1)unit.flags1;
            //UnitFlags2 flags2 = (UnitFlags2)unit.flags2;
            //UnitFlags3 flags3 = (UnitFlags3)unit.flags3;
            if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) ||
                ((flags1 & UnitFlags1.left) == UnitFlags1.left))
            {
                if (creatureList.ContainsKey(unit.id))
                {
                    Destroy(creatureList[unit.id]);
                    creatureList.Remove(unit.id);
                }
            }
            else
            {
                CreatureRaw creatureRaw = null;
                if (DFConnection.Instance.NetCreatureRawList != null)
                    creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type];

                if (!creatureList.ContainsKey(unit.id))
                {
                    creatureList[unit.id] = Instantiate(creatureTemplate);
                    creatureList[unit.id].transform.parent = gameObject.transform;
                    creatureList[unit.id].ClearMesh();

                    Color color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1);

                    if (creatureRaw != null)
                        creatureList[unit.id].AddTile(creatureRaw.creature_tile, color);

                }
                creatureList[unit.id].gameObject.SetActive(unit.pos_z < PosZ && unit.pos_z > (PosZ - cameraViewDist));
                if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible.
                {
                    Vector3 position = DFtoUnityCoord(unit.pos_x, unit.pos_y, unit.pos_z);
                    if((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
                    {
                        creatureList[unit.id].transform.position = position + new Vector3(0, 0.51f, 0);
                        creatureList[unit.id].cameraFacing.enabled = false;
                        creatureList[unit.id].transform.rotation = Quaternion.Euler(90, 0, 0);
                    }
                    else
                    {
                        creatureList[unit.id].transform.position = position + new Vector3(0, 1.5f, 0);
                        creatureList[unit.id].cameraFacing.enabled = true;
                    }
                    creatureList[unit.id].SetColor(0, new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1));
                    if (creatureRaw != null)
                    {
                        if (unit.is_soldier)
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_soldier_tile);
                        else
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_tile);
                    }
                }

            }
        }
    }
Ejemplo n.º 3
0
    void UpdateCreatures()
    {
        unitList = DFConnection.Instance.PopUnitListUpdate();
        if (unitList == null)
        {
            return;
        }
        foreach (var unit in unitList.creature_list)
        {
            if (creatureList == null)
            {
                creatureList = new Dictionary <int, AtlasSprite>();
            }
            UnitFlags1 flags1 = (UnitFlags1)unit.flags1;
            //UnitFlags2 flags2 = (UnitFlags2)unit.flags2;
            //UnitFlags3 flags3 = (UnitFlags3)unit.flags3;
            if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) ||
                ((flags1 & UnitFlags1.left) == UnitFlags1.left))
            {
                if (creatureList.ContainsKey(unit.id))
                {
                    Destroy(creatureList[unit.id]);
                    creatureList.Remove(unit.id);
                }
            }
            else
            {
                CreatureRaw creatureRaw = null;
                if (DFConnection.Instance.NetCreatureRawList != null)
                {
                    creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type];
                }

                if (!creatureList.ContainsKey(unit.id))
                {
                    creatureList[unit.id] = Instantiate(creatureTemplate);
                    creatureList[unit.id].transform.parent = gameObject.transform;
                    creatureList[unit.id].ClearMesh();

                    Color color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1);

                    if (creatureRaw != null)
                    {
                        creatureList[unit.id].AddTile(creatureRaw.creature_tile, color);
                    }
                }
                creatureList[unit.id].gameObject.SetActive(unit.pos_z <PosZ && unit.pos_z> (PosZ - cameraViewDist));
                if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible.
                {
                    Vector3 position = DFtoUnityCoord(unit.pos_x, unit.pos_y, unit.pos_z);
                    if ((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
                    {
                        creatureList[unit.id].transform.position   = position + new Vector3(0, 0.51f, 0);
                        creatureList[unit.id].cameraFacing.enabled = false;
                        creatureList[unit.id].transform.rotation   = Quaternion.Euler(90, 0, 0);
                    }
                    else
                    {
                        creatureList[unit.id].transform.position   = position + new Vector3(0, 1.5f, 0);
                        creatureList[unit.id].cameraFacing.enabled = true;
                    }
                    creatureList[unit.id].SetColor(0, new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1));
                    if (creatureRaw != null)
                    {
                        if (unit.is_soldier)
                        {
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_soldier_tile);
                        }
                        else
                        {
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_tile);
                        }
                    }
                }
            }
        }
    }