Exemplo n.º 1
0
 public static string GetProperty(PropertyDict properties, string property)
 {
     if (properties != null && properties.ContainsKey(property))
     {
         return(properties[property]);
     }
     return(null);
 }
Exemplo n.º 2
0
 public ExPropertyInfo GetExProperty(string name)
 {
     if (PropertyDict.ContainsKey(name))
     {
         return(new ExPropertyInfo(PropertyDict[name].GetProperty(), true));
     }
     return(null);
 }
Exemplo n.º 3
0
        public EntityPropertyDef?GetPropertyDef(string propertyName)
        {
            if (PropertyDict.ContainsKey(propertyName))
            {
                return(PropertyDict[propertyName]);
            }

            return(null);
        }
Exemplo n.º 4
0
 public void Init(int xPos, float yPos, int zPos, ObjectType objectType, PropertyDict properties)
 {
     originalRotation = transform.rotation;
     this.objectType  = objectType;
     this.xPos        = xPos;
     this.zPos        = zPos;
     if (this.objectType == ObjectType.ProjectileShooter)
     {
         ProjectileShooter projectileShooter = GetComponent <ProjectileShooter>();
         projectileShooter.Init((ProjectileHeading)GameManager.IntParseFast(properties["ObjectRotation"]));
     }
     else if (properties.ContainsKey("ObjectRotation"))
     {
         transform.eulerAngles = new Vector3(transform.eulerAngles.x, GameManager.Rotations[GameManager.IntParseFast(properties["ObjectRotation"])], transform.eulerAngles.z);
     }
     transform.position = new Vector3(xPos, yPos, zPos);
     currentTile        = TileManager.main.GetTile(xPos, zPos);
     currentTile.AddObject(this);
 }
Exemplo n.º 5
0
 public object GetValue(object obj, string name)
 {
     if (obj.GetType() == typeof(TableInfo))
     {
         TableInfo ti = obj as TableInfo;
         if (name.ToUpper() == ti.PrimaryKeyName)
         {
             return(ti.ID);
         }
         return(ti.GetFieldValue(name));
     }
     else
     {
         if (!PropertyDict.ContainsKey(name))
         {
             throw new DataException(ErrorCodes.UnkownProperty);
         }
         Property p = PropertyDict[name];
         return(p.Info.GetValue(obj, null));
     }
 }
Exemplo n.º 6
0
    public void GenerateObjects(TmxObjectGroupList objectGroupList)
    {
        int objectGroupCount = objectGroupList.Count;

        for (int i = 0; i < objectGroupCount; i += 1)
        {
            TmxObjectGroup objectGroup = objectGroupList[i];
            int            objectCount = objectGroup.Objects.Count;
            PropertyDict   properties  = objectGroup.Properties;

            Transform layerContainer = new GameObject(objectGroup.Name).transform;
            layerContainer.rotation = Quaternion.identity;
            layerContainer.transform.SetParent(objectContainer);
            for (int j = 0; j < objectCount; j += 1)
            {
                if (!properties.ContainsKey("Type"))
                {
                    Debug.Log("ERROR: Object Layer \"" + objectGroup.Name + "\" doesn't have a Type property!");
                    continue;
                }
                string objectType = properties["Type"];
                TmxObjectGroup.TmxObject tmxObject = objectGroup.Objects[j];

                int xpos = (int)tmxObject.X / tile_width;
                int ypos = (int)tmxObject.Y / tile_height - 1;

                Vector3    worldPos      = new Vector3(-xpos + 0.5f, 0.5f, ypos - 0.5f);
                GameObject spawnedObject = (GameObject)GameObject.Instantiate(Resources.Load("Objects/" + objectType), worldPos, Quaternion.identity);
                spawnedObject.name = tmxObject.ToString();

                spawnedObject.transform.position = worldPos;
                spawnedObject.transform.parent   = layerContainer;

                if (objectType == "Hero")
                {
                    hero = spawnedObject.GetComponent <Hero>();
                    hero.Init(tileMap, xpos, ypos);
                }
                if (objectType == "End")
                {
                    endX = xpos;
                    endY = ypos;
                }

                /*TmxObjectGroup.TmxObject startEnd = ObjectGroups[i].Objects[j];
                 *
                 * int startEndX = (int)startEnd.X / tile_width;
                 * int startEndY = (int)startEnd.Y / tile_height;
                 * Vector3 worldPos = new Vector3(-startEndX + 0.5f, 1f, startEndY - 1.5f);
                 *
                 * if (startEnd.Name == "Start")
                 * {
                 *  //player.Spawn(worldPos, tile_width, tile_height);
                 *  GameObject startObject = (GameObject)GameObject.Instantiate(Resources.Load("SpawnPoint"), worldPos, Quaternion.identity);
                 * }
                 * else if (startEnd.Name == "End")
                 * {
                 *  GameObject endObjectPrefab = (GameObject)GameObject.Instantiate(Resources.Load("LevelEndTrigger"));
                 *  endObjectPrefab.transform.position = worldPos;
                 * }*/
            }
        }
    }
Exemplo n.º 7
0
/*        int wallCount = map.ObjectGroups[2].Objects.Count;
 *      CreateWall(tileSheet);
 *
 *      for (int i = 0; i < wallCount; i++)
 *      {
 *          TmxObjectGroup.TmxObject wall = map.ObjectGroups[2].Objects[i];
 *          //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]");
 *          int startEndX = (int)wall.X / tile_width;
 *          int startEndY = (int)wall.Y / tile_height;
 *          Vector3 worldPos = new Vector3(-startEndX, 0.5f, startEndY);
 *
 *          GameObject wallObject = (GameObject)GameObject.Instantiate(wallPref, worldPos, Quaternion.identity);
 *          //wallObject.transform.parent = wallContainer.transform;
 *          wallObject.transform.localPosition = worldPos;
 *      }
 *      if (Application.isPlaying)
 *      {
 *          GameObject.Destroy(wallPref);
 *      }*/

    /*
     * int objectCount = map.ObjectGroups[3].Objects.Count;
     *
     * for (int i = 0; i < objectCount; i++)
     * {
     *  TmxObjectGroup.TmxObject genericObject = map.ObjectGroups[3].Objects[i];
     *  //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]");
     *  int startEndX = (int)genericObject.X / tile_width;
     *  int startEndY = (int)genericObject.Y / tile_height;
     *  Vector3 worldPos = new Vector3(-startEndX + 0.5f, 0.5f, startEndY -1.5f);
     *
     * }*/


    public void GenerateTiles(TmxLayerList layerList)
    {
        int layerCount = layerList.Count;

        for (int i = 0; i < layerCount; i += 1)
        {
            TmxLayer     layer      = layerList[i];
            int          tileCount  = layer.Tiles.Count;
            PropertyDict properties = layer.Properties;

            string tileType = "Ground";
            if (properties.ContainsKey("Type"))
            {
                tileType = properties["Type"];
            }
            if (tileType == "Ground")
            {
                tiles = new MapSquare[layer.Tiles.Count];
            }
            Transform layerContainer = new GameObject(layer.Name).transform;
            layerContainer.rotation = Quaternion.identity;
            layerContainer.transform.SetParent(tileContainer);

            //Debug.Log(tileCount);

            for (int j = 0; j < tileCount; j += 1)
            {
                TmxLayerTile tmxTile   = layer.Tiles[j];
                int          tileSetId = FindTileSetId(tmxTile.Gid);

                if (tileSetId == -1)
                {
                    continue;
                }
                if (tileType == "Wall")
                {
                    if (tmxTile.Gid == 0)
                    {
                        continue;
                    }
                    tileMap.AddNode(tmxTile.X, tmxTile.Y, false);

                    int     xpos     = (int)tmxTile.X;
                    int     ypos     = (int)tmxTile.Y;
                    Vector3 worldPos = new Vector3(-xpos + 0.5f, 0.5f, ypos - 0.5f);
                    //Debug.Log("[" + tmxTile.X + ", " + tmxTile.Y + "]");
                    GameObject spawnedTile;
                    if (wallPref == null)
                    {
                        CreateWall();
                    }
                    spawnedTile      = (GameObject)Instantiate(wallPref, worldPos, Quaternion.identity);
                    spawnedTile.name = "Wall_" + tmxTile.Gid;
                    spawnedTile.transform.position = worldPos;
                    spawnedTile.transform.parent   = layerContainer;
                }
                if (tileType == "Ground")
                {
                    if (tmxTile.Gid != 0)
                    {
                        tileMap.AddNode(tmxTile.X, tmxTile.Y);
                    }
                    tiles[j] = new MapSquare(tmxTile);
                }
            }
        }
    }