Beispiel #1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            for (int i = this.Controls.Count - 1; i >= 0; i--)
            {
                Control control = this.Controls[i];
                control.Focus();
                if (!Validate())
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (_mapColumn == null)
            {
                Relationship[] relationshipPath = new Relationship[1] {
                    (Relationship)comboBoxRelationship.SelectedItem
                };
                Column column = (Column)comboBoxMapColumn.SelectedItem;
                _mapColumn              = new MapColumn(textBoxName.Text, true, relationshipPath, column, _parent.Columns.Length, column.IsNullable, column.DataType, column.CharacterMaximumLength);
                _mapColumn.Alias        = textBoxAlias.Text;
                _mapColumn.AliasDisplay = textBoxAliasDisplay.Text;
            }
            else
            {
                _mapColumn.ForeignColumn = (Column)comboBoxMapColumn.SelectedItem;

                _mapColumn.Name         = textBoxName.Text;
                _mapColumn.Alias        = textBoxAlias.Text;
                _mapColumn.AliasDisplay = textBoxAliasDisplay.Text;
            }
        }
Beispiel #2
0
    public int NearestZLevel(int x, int y, int z)
    {
        MapColumn c       = TileColumnAt(x, y);
        int       dz      = int.MaxValue;
        MapTile   closest = null;

        if (c == null || c.Count == 0)
        {
            return(0);
        }
        for (int i = 0; i < c.Count; i++)
        {
            MapTile s    = c.At(i);
            MapTile next = i + 1 >= c.Count ? null : c.At(i + 1);
            if (next == null || next.z > s.maxZ)
            {
                int thisDz = (int)Mathf.Abs((s.avgZ) - z);
                if (thisDz < dz)
                {
                    dz      = thisDz;
                    closest = s;
                }
            }
        }
        return(closest.avgZ);
    }
        /// <summary>
        /// 检查列;获取DataTable有列的属性集合
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="Properties">属性集合</param>
        /// <returns>有列的属性集合</returns>
        private static MapColumn[] CheckProperty(DataTable dt, PropertyInfo[] Properties)
        {
            List <MapColumn> lst = new List <MapColumn>(Properties.Length);

            foreach (var property in Properties)
            {
                string            colName  = property.Name;
                NoColumnAttribute noColumn = property.GetCustomAttribute <NoColumnAttribute>();
                if (noColumn != null)
                {
                    continue;
                }
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (dt.Columns.Contains(colName))
                {
                    MapColumn column = new MapColumn()
                    {
                        ColumnName = colName, Property = property
                    };
                    lst.Add(column);
                }
            }
            return(lst.ToArray());
        }
        /// <summary>
        /// 检查可匹配的列
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="Properties"></param>
        /// <returns></returns>
        private static MapColumn[] CheckProperty(IDataReader reader, PropertyInfo[] Properties)
        {
            List <MapColumn> lst    = new List <MapColumn>(Properties.Length);
            List <string>    lstCol = new List <string>(reader.FieldCount);

            for (int i = 0; i < reader.FieldCount; i++)
            {
                lstCol.Add(reader.GetName(i));
            }
            foreach (var property in Properties)
            {
                string             colName   = property.Name;
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (lstCol.Contains(colName))
                {
                    MapColumn column = new MapColumn()
                    {
                        ColumnName = colName, Property = property
                    };
                    lst.Add(column);
                }
            }
            return(lst.ToArray());
        }
Beispiel #5
0
    public MapTile TileAt(int x, int y, int z)
    {
        if (x < 0 ||
            y < 0 ||
            x >= _size.x ||
            y >= _size.y ||
            z < 0)
        {
            return(null);
        }
        if (stacks == null)
        {
            return(null);
        }
        MapColumn c = TileColumnAt(x, y);

        if (c == null)
        {
            return(null);
        }
        for (int i = 0; i < c.Count; i++)
        {
            MapTile t = c.At(i);
            if (t.ContainsZ(z))
            {
                return(MapTileIsNull(t) ? null : t);
            }
            if (t.IsAboveZ(z))
            {
                return(null);
            }
        }
        return(null);
    }
        /// <summary>
        /// 检查列,获取DataTable有列的属性集合
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="Properties">属性集合</param>
        /// <returns>有列的属性集合</returns>
        private static MapColumn[] CheckProperty(DataTable dt, PropertyInfo[] Properties, bool ignore)
        {
            List <MapColumn>            lst     = new List <MapColumn>(Properties.Length);
            Dictionary <string, string> dicCols = new Dictionary <string, string>();
            Dictionary <string, string> dicType = new Dictionary <string, string>();

            //遍历列
            foreach (DataColumn col in dt.Columns)
            {
                dicCols[col.ColumnName.ToLower()] = col.ColumnName;
                dicType[col.ColumnName]           = col.DataType.Name;
            }

            foreach (var property in Properties)
            {
                if (!property.CanWrite)
                {
                    continue;//去除只读属性
                }
                string            colName  = property.Name;
                NoColumnAttribute noColumn = property.GetCustomAttribute <NoColumnAttribute>();
                if (noColumn != null)
                {
                    continue;
                }
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (ignore)
                {
                    if (dicCols.ContainsKey(colName.ToLower()))
                    {
                        MapColumn column = new MapColumn()
                        {
                            ColumnName = dicCols[colName.ToLower()], Property = property
                        };
                        column.ColType = dicType[column.ColumnName];
                        lst.Add(column);
                    }
                }
                else
                {
                    if (dicType.ContainsKey(colName))
                    {
                        MapColumn column = new MapColumn()
                        {
                            ColumnName = colName, Property = property
                        };
                        column.ColType = dt.Columns[colName].DataType.Name;
                        lst.Add(column);
                    }
                }
            }
            return(lst.ToArray());
        }
Beispiel #7
0
    public void AddIsoTileAt(int x, int y, int z)
    {
        if (stacks == null)
        {
            ResetStacks(Vector2.zero);
        }
        MapColumn stackC = TileColumnAt(x, y);
        MapTile   stack  = null;
        bool      added  = false;

        if (stackC == null || stackC.Count == 0)
        {
            stack = new MapTile(x, y, z);
            stack.serializeHackUsable = true;
            SetTileStackAt(stack, x, y);
            added = true;
        }
        else
        {
            MapTile newStack = new MapTile(x, y, z);
            newStack.serializeHackUsable = true;
            bool present = false;
            for (int i = 0; i < stackC.Count; i++)
            {
                stack = stackC.At(i);
                if (stack.IsAboveZ(z))
                {
                    stackC.Insert(i, newStack);
                    present = true;
                    added   = true;
                    break;
                }
                else if (stack.ContainsZ(z))
                {
                    present = true;
                    break;
                }
            }
            if (!present)
            {
                if (stack.maxZ == z && stack.maxHeight != 1)
                {
                    //don't propagate heights, just clobber the old ones
                    int max = stack.maxHeight;
                    //stack.next.heights = stack.heights;
                    //stack.heights = new int[]{1,1,1,1};
                    stack.heights = new int[] { max, max, max, max };
                }
                stackC.Add(newStack);
                added = true;
            }
        }
        if (added)
        {
            RemakeMesh();
        }
    }
        public FormMapColumn(ScriptObject parent, MapColumn mapColumn)
        {
            InitializeComponent();
            BackColor = Slyce.Common.Colors.BackgroundColor;

            _parent         = parent;
            _mapColumn      = mapColumn;
            ucHeading1.Text = "";
            Interfaces.Events.ShadeMainForm();
        }
Beispiel #9
0
        public FormMapColumn(ScriptObject parent, MapColumn mapColumn)
        {
            InitializeComponent();
            this.BackColor = Slyce.Common.Colors.BackgroundColor;

            _parent         = parent;
            _mapColumn      = mapColumn;
            ucHeading1.Text = "";
            Controller.ShadeMainForm();
        }
        /// <summary>
        /// 检查可匹配的列
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="Properties"></param>
        /// <returns></returns>
        private static MapColumn[] CheckProperty(IDataReader reader, PropertyInfo[] Properties, bool ignore = false)
        {
            List <MapColumn> lst = new List <MapColumn>(Properties.Length);

            Dictionary <string, string> dicCol  = new Dictionary <string, string>();
            Dictionary <string, string> dicType = new Dictionary <string, string>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                dicType[reader.GetName(i)] = reader.GetDataTypeName(i);
                if (ignore)
                {
                    dicCol[reader.GetName(i).ToLower()] = reader.GetName(i);
                }
            }
            foreach (var property in Properties)
            {
                if (!property.CanWrite)
                {
                    continue;
                }
                string             colName   = property.Name;
                DataFieldAttribute aliasAttr = property.GetCustomAttribute <DataFieldAttribute>();
                if (aliasAttr != null)
                {
                    colName = aliasAttr.ColumnName;
                }
                if (ignore)
                {
                    if (dicCol.ContainsKey(colName.ToLower()))
                    {
                        MapColumn column = new MapColumn()
                        {
                            ColumnName = dicCol[colName.ToLower()], Property = property
                        };
                        column.ColType = dicType[column.ColumnName];
                        lst.Add(column);
                    }
                }
                else
                {
                    if (dicType.ContainsKey(colName))
                    {
                        MapColumn column = new MapColumn()
                        {
                            ColumnName = colName, Property = property
                        };
                        column.ColType = dicType[column.ColumnName];
                        lst.Add(column);
                    }
                }
            }
            return(lst.ToArray());
        }
 public static void Initialize()
 {
     Language = "PtBr";
     if (MapColumn.Equals(0))
     {
         MapColumn = 3;
     }
     if (MapRow.Equals(0))
     {
         MapRow = 3;
     }
 }
Beispiel #12
0
        private void InitialUpdateMapColumns(IList <Model.Table> tables)
        {
            foreach (Model.Table table in tables)
            {
                foreach (ManyToOneRelationship manyToOneRelationship in table.ManyToOneRelationships)
                {
                    Column dataDisplayColumn = GetDataDisplayColumn((Model.Table)manyToOneRelationship.ForeignScriptObject);

                    if (dataDisplayColumn != null)
                    {
                        MapColumn mapColumn = new MapColumn(manyToOneRelationship.Name, false, new Relationship[] { manyToOneRelationship }, dataDisplayColumn, table.Columns.Length, manyToOneRelationship.PrimaryColumns[0].IsNullable || manyToOneRelationship.ForeignColumns[0].IsNullable, dataDisplayColumn.DataType, dataDisplayColumn.Size, dataDisplayColumn.Precision, dataDisplayColumn.Scale);
                        table.AddColumn(mapColumn);
                    }
                }
            }
        }
Beispiel #13
0
    private void Start()
    {
        map         = FindObjectOfType <MapColumn>();
        myRigidBody = GetComponent <Rigidbody2D>();
        NameSelector nameSelector = FindObjectOfType <NameSelector>();

        entity.SetName(nameSelector.GetRandom("BOSS"));

        gravity = 9.81f;

        Vector3 pos = transform.position;

        pos.x = map.transform.position.x;
        transform.position = pos;
        JumpTo(map.GetNbrColumn() - 1);
        currentTime = intervalSpawn;
    }
Beispiel #14
0
    void SetTileStackAt(MapTile stack, int x, int y)
    {
        int idx = y * (int)_size.x + x;

        if (idx >= stacks.Length)
        {
            Array.Resize(ref stacks, idx + 1);
        }
        if (stacks[idx] == null)
        {
            stacks[idx] = new MapColumn();
        }
        if (stacks[idx].Count > 0)
        {
            stacks[idx].Clear();
        }
        stacks[idx].Add(stack);
    }
Beispiel #15
0
 public MapColumn GenerateColumn(Vector3 Coordinates, Region Region, Dimension Dimension, long Seed)
 {
     MapColumn mc = new MapColumn(Region, Coordinates);
     // Floor of glass
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             mc.SetBlock(new Vector3(x, 0, z), new GlassBlock());
             mc.SetBlock(new Vector3(x, 15, z), new GlassBlock());
         }
         //mc.SetBlock(new Vector3(x, 0, 0), new WoolBlock(Wool.Red));
         //mc.SetBlock(new Vector3(x, 0, 15), new WoolBlock(Wool.Red));
         //mc.SetBlock(new Vector3(0, 0, x), new WoolBlock(Wool.Red));
         //mc.SetBlock(new Vector3(15, 0, x), new WoolBlock(Wool.Red));
         mc.SetBlock(new Vector3(15, 0, x), new WoolBlock(Wool.Pink));
     }
     return mc;
 }
Beispiel #16
0
    MapTile NextTile(MapTile t)
    {
        MapColumn stack = TileColumnAt(t.x, t.y);

        if (stack == null)
        {
            return(null);
        }
        int tidx = stack.IndexOf(t);

        if (tidx == -1)
        {
            return(null);
        }
        if (tidx + 1 >= stack.Count)
        {
            return(null);
        }
/*		Debug.Log("next after "+t+" at "+tidx+" is "+stack.At(tidx+1)+" where count is "+stack.Count);*/
        return(stack.At(tidx + 1));
    }
Beispiel #17
0
 public void RemoveTileSpecAt(int i)
 {
     for (int mi = 0; mi < stacks.Length; mi++)
     {
         MapColumn tl = stacks[mi];
         if (tl == null)
         {
             continue;
         }
         for (int ti = 0; ti < tl.Count; ti++)
         {
             MapTile t = tl.At(ti);
             if (!MapTileIsNull(t))
             {
                 t.AdjustTileSpecsAfterRemoving(i);
             }
         }
     }
     tileSpecs.RemoveAt(i);
     RemakeTexture();
 }
Beispiel #18
0
 void ResetStacks(Vector2 oldSize)
 {
     MapColumn[] newStacks = new MapColumn[(int)_size.x * (int)_size.y];
     // Debug.Log("reset new sz "+_size+" old sz "+oldSize);
     for (int i = 0; i < newStacks.Length; i++)
     {
         if (oldSize != Vector2.zero)
         {
             if (oldSize == _size)
             {
                 newStacks[i] = stacks[i];
             }
             else
             {
                 int y    = i / (int)_size.x;
                 int x    = i - y * (int)_size.x;
                 int oldI = y * (int)oldSize.x + x;
                 if (x >= 0 && x < oldSize.x && x < _size.x &&
                     y >= 0 && y < oldSize.y && y < _size.y &&
                     stacks != null &&
                     oldI < stacks.Length)
                 {
                     newStacks[i] = stacks[oldI];
                 }
                 else
                 {
                     // Debug.Log("("+x+","+y+")"+" new i "+i+" old i "+oldI+" out of range "+stacks.Length);
                     newStacks[i] = null;
                 }
             }
         }
         else
         {
             newStacks[i] = null;
         }
     }
     this.stacks = newStacks;
     RemakeMesh();
 }
Beispiel #19
0
    public int NextZLevel(int x, int y, int z, bool wrap = false)
    {
        MapColumn mc = TileColumnAt(x, y);

        if (mc == null)
        {
            return(-1);
        }
        MapTile ret = null;

        for (int i = 0; i < mc.Count; i++)
        {
            MapTile t = mc.At(i);
            if (MapTileIsNull(t))
            {
                continue;
            }
            if (i < mc.Count - 1 && mc.At(i + 1).z == t.maxZ)
            {
                //skip, we're in the middle of a stack
                continue;
            }
            if (ret == null && wrap)
            {
                ret = t;
            }                                                //get bottom
            //if t's maxZ is above z, set ret to it and break
            if (t.maxZ > z)
            {
                ret = t;
                break;
            }
        }
        if (ret == null)
        {
            return(-1);
        }
        return(ret.maxZ - 1);
    }
Beispiel #20
0
    public int PrevZLevel(int x, int y, int z, bool wrap = true)
    {
        MapColumn mc = TileColumnAt(x, y);

        if (mc == null)
        {
            return(-1);
        }
        MapTile ret = null;

        for (int i = mc.Count - 1; i >= 0; i--)
        {
            MapTile t = mc.At(i);
            if (MapTileIsNull(t))
            {
                continue;
            }
            if (i < mc.Count - 1 && mc.At(i + 1).z == t.maxZ)
            {
                //skip, we're in the middle of a stack
                continue;
            }
            if (ret == null && wrap)
            {
                ret = t;
            }                                                //get top
            //if t's maxZ is below z, set ret to it and break
            if (t.maxZ < z)
            {
                ret = t;
                break;
            }
        }
        if (ret == null)
        {
            return(-1);
        }
        return(ret.maxZ - 1);
    }
Beispiel #21
0
    void SetNextTile(MapTile prev, MapTile next)
    {
        int idx = prev.y * (int)_size.x + prev.x;

        if (idx >= stacks.Length)
        {
            return;
        }
        MapColumn stack = stacks[idx];

        if (stack == null)
        {
            return;
        }
        int tidx = stack.IndexOf(prev);

        if (tidx == -1)
        {
            return;
        }
        stack.Insert(tidx, next);
    }
Beispiel #22
0
    public int[] ZLevelsWithinLimits(int x, int y, int minZ, int maxZ)
    {
        if (x < 0 || y < 0 || x >= size.x || y >= size.y)
        {
            return(new int[0]);
        }
        MapColumn c = TileColumnAt(x, y);

        if (c == null || c.Count == 0)
        {
            return(new int[0]);
        }
        List <int> zLevels = new List <int>();

        for (int i = 0; i < c.Count; i++)
        {
            MapTile t = c.At(i);
            //skip anybody with a tile immediately above them
            if (i + 1 < c.Count)
            {
                if (c.At(i + 1).z <= t.maxZ)
                {
                    continue;
                }
                else
                {
                    //it's fine, keep going
                }
            }
            //skip tiles that are not within range
            if (minZ < 0 || maxZ < 0 || (t.avgZ > minZ && t.avgZ <= maxZ))
            {
                zLevels.Add(t.avgZ);
            }
        }
        return(zLevels.ToArray());
    }
Beispiel #23
0
        public static string GetSQLParentAlias(MapColumn mapColumn)
        {
            // TODO: Add in one to one support
            string parentName = mapColumn.Parent.Name;

            List <string> foreignTableNames = new List <string>();

            foreignTableNames.Add(parentName);

            Table table = (Table)mapColumn.Parent;

            foreach (MapColumn tempMapColumn in table.MapColumns)
            {
                foreignTableNames.Add(tempMapColumn.ForeignColumn.Parent.Name);

                if (tempMapColumn == mapColumn)
                {
                    break;
                }
            }

            int count = -1;

            foreach (string name in foreignTableNames)
            {
                if (name == mapColumn.ForeignColumn.Parent.Name)
                {
                    count++;
                }
            }

            if (count <= 0)
            {
                return(GetSQLName(mapColumn.ForeignColumn.Parent.Name));
            }
            return(GetSQLName(mapColumn.ForeignColumn.Parent.Name + "_" + count));
        }
Beispiel #24
0
  void OnWizardCreate () {
		if(!map) { return; }
		StringBuilder exportStr = new StringBuilder(1024);
		Vector2 size = map.size;
		exportStr.Append("[\n");
		for(int y = 0; y < size.y; y++) {
			exportStr.Append("\t[");
			for(int x = 0; x < size.x; x++) {
				MapColumn tc = map.TileColumnAt(x,y);
				if(tc.Count == 0) { exportStr.Append("[]"); }
				else {
					exportStr.Append("[");
					//emit Z range and tile, Z range and tile, Z range and tile...
					for(int i = 0; i < tc.Count; i++) {
						MapTile t = tc.At(i);
						int zMin = t.z;
						int h = t.maxHeight;
						exportStr.AppendFormat("{{{0},{1},cube}}",zMin,h);
						if(i < tc.Count-1) {
							exportStr.Append(",");
						}
					}
					exportStr.Append("]");
				}
				if(x < size.x-1) {
					exportStr.Append(", ");
				}
			}
			exportStr.Append("]");
			if(y < size.y-1) { exportStr.Append(","); }
			exportStr.Append("\n");
		}
		exportStr.Append("].");
		File.WriteAllText(Application.dataPath + "/"+map.name+"_export.txt", exportStr.ToString());
    AssetDatabase.Refresh();
  }
Beispiel #25
0
    public void RemoveIsoTileAt(int x, int y, int z)
    {
        if (stacks == null)
        {
            //no tile to remove
            return;
        }
        MapColumn stackC = TileColumnAt(x, y);
        MapTile   stack;

        if (stackC == null || stackC.Count == 0)
        {
            //no tile to remove
            return;
        }
        bool removed = false;

        for (int i = 0; i < stackC.Count; i++)
        {
            stack = stackC.At(i);
            if (stack.IsAboveZ(z))
            {
                return;
            }
            if (stack.ContainsZ(z))
            {
                stackC.RemoveAt(i);
                removed = true;
                break;
            }
        }
        if (removed)
        {
            RemakeMesh();
        }
    }
Beispiel #26
0
    public void resizeMap( int width = 0, int height = 0 )
    {
        // START resizeMap X, Y.

            // Setting the size variables:
            if( width == 0 || height == 0 )
            {
                _mapWidth = (int)MazeGlobals.SMALL_MAP_SIZE.x;
                _mapHeight = (int)MazeGlobals.SMALL_MAP_SIZE.y;

            }
            else
            {

                _mapWidth = width;
                _mapHeight = height;

            }

            // A Temp Column contaning a lsit of map cells:
            MapColumn tempColumnList;

            // If the map is null then initalize it:
            if( _mapData == null )
            {
                _mapData = new List<MapColumn>();
            }

            //If the map is to be resized to zero then do so then return:
            if( _mapWidth == 0 && _mapData.Count != 0 )
            {
                _mapData.Clear();
                return;
            }

            // Initalizing evry cell in the map:
            for ( x = 0; x < _mapWidth; x++ )
            {
                // Initializing the temp Map Row:
                tempColumnList = new MapColumn();

                for ( y = 0; y < _mapHeight; y++ )
                {
                    tempColumnList._columnList.Add( new MapCell() );
                }

                _mapData.Add( tempColumnList );
            }
    }
Beispiel #27
0
    public bool HasTileAt(int x, int y)
    {
        MapColumn c = null;

        return(x >= 0 && x < size.x && y >= 0 && y < size.y && (c = TileColumnAt(x, y)) != null && c.Count > 0);
    }
Beispiel #28
0
    void RemakeMesh()
    {
        if (stacks == null)
        {
            return;
        }

        MeshFilter mf = GetComponent <MeshFilter>();

        if (mf == null)
        {
            mf = gameObject.AddComponent <MeshFilter>();
        }
        MeshRenderer mr = GetComponent <MeshRenderer>();

        if (mr == null)
        {
            mr = gameObject.AddComponent <MeshRenderer>();
        }
        MeshCollider mc = GetComponent <MeshCollider>();

        if (mc == null)
        {
            mc = gameObject.AddComponent <MeshCollider>();
        }

        if (mr.sharedMaterials.Length < 2 || mr.sharedMaterials[0] == null || mr.sharedMaterials[1] == null)
        {
            mr.sharedMaterials = new Material[] {
                new Material(Shader.Find("Transparent/Cutout/Diffuse")),
                new Material(Shader.Find("Transparent/Diffuse"))
            };
            mr.sharedMaterials[1].color = Application.isPlaying ? Color.clear : new Color(0.7f, 0.7f, 1.0f, 0.5f);
        }
        if (mr.sharedMaterials[0].mainTexture != mainAtlas)
        {
            mr.sharedMaterials[0].mainTexture = mainAtlas;
        }
        if (mr.sharedMaterials[1].mainTexture != mainAtlas)
        {
            mr.sharedMaterials[1].mainTexture = mainAtlas;
        }
        Mesh mesh = mf.sharedMesh != null ? mf.sharedMesh : new Mesh();

        mesh.Clear();

        float height = _tileHeight;

        //FIXME: height assumption may be higher than necessary
        //24 vertices per so each gets a uv, we will say 20 units high
        Vector3[] vertices = new Vector3[(int)(_size.x * _size.y * 20 * 24)];
        //10 tris, 3 indices per, we will say 20 units high
        int[]     opaqueTriangles = new int[(int)(_size.x * _size.y * 20 * 10 * 3)];
        Vector2[] uvs             = new Vector2[vertices.Length];

        int vertIdx      = 0;
        int opaqueTriIdx = 0;

        //10 tris, 3 indices per, we will say 20 units high
        int[] transparentTriangles = new int[(int)(_size.x * _size.y * 20 * 10 * 3)];

        int transparentTriIdx = 0;

        for (int i = 0; i < stacks.Length; i++)
        {
            MapColumn tlist = stacks[i];
            if (tlist == null)
            {
                continue;
            }
            int y = i / (int)_size.x;
            int x = i - (y * (int)_size.x);
            for (int ti = 0; ti < tlist.Count; ti++)
            {
                MapTile t = tlist.At(ti);
                if (MapTileIsNull(t))
                {
                    Debug.Log("tile " + t + " at " + ti + " is null somehow");
                }
                int   z         = t.z;
                int[] triangles = t.invisible ? transparentTriangles : opaqueTriangles;
                int   triIdx    = t.invisible ? transparentTriIdx : opaqueTriIdx;

                bool  avoidNeighbors = t.maxHeight == 1 && t.noInsets && !t.invisible && NoInsetOrInvisibleNeighbors(x, y, t);
                float lx             = (x + 0 + t.sideInsets[(int)Neighbors.FrontLeftIdx]) * _sideLength - _sideLength / 2;
                float fx             = (x + 0 + t.sideInsets[(int)Neighbors.FrontLeftIdx]) * _sideLength - _sideLength / 2;
                float rx             = (x + 1 - t.sideInsets[(int)Neighbors.BackRightIdx]) * _sideLength - _sideLength / 2;
                float bx             = (x + 1 - t.sideInsets[(int)Neighbors.BackRightIdx]) * _sideLength - _sideLength / 2;
                float fy             = (y + 0 + t.sideInsets[(int)Neighbors.FrontRightIdx]) * _sideLength - _sideLength / 2;
                float ry             = (y + 0 + t.sideInsets[(int)Neighbors.FrontRightIdx]) * _sideLength - _sideLength / 2;
                float ly             = (y + 1 - t.sideInsets[(int)Neighbors.BackLeftIdx]) * _sideLength - _sideLength / 2;
                float by             = (y + 1 - t.sideInsets[(int)Neighbors.BackLeftIdx]) * _sideLength - _sideLength / 2;

                //TODO: include corner insets and their extra geometry


                //TODO: stairs and their extra geometry

                float     zMinL = (z + 0 + t.sideInsets[(int)Neighbors.BottomIdx] + t.baselines[(int)Corners.Left] - 1) * height;
                float     zMaxL = (z - t.sideInsets[(int)Neighbors.TopIdx] + t.heights[(int)Corners.Left] - 1) * height;
                float     zMinF = (z + 0 + t.sideInsets[(int)Neighbors.BottomIdx] + t.baselines[(int)Corners.Front] - 1) * height;
                float     zMaxF = (z - t.sideInsets[(int)Neighbors.TopIdx] + t.heights[(int)Corners.Front] - 1) * height;
                float     zMinB = (z + 0 + t.sideInsets[(int)Neighbors.BottomIdx] + t.baselines[(int)Corners.Back] - 1) * height;
                float     zMaxB = (z - t.sideInsets[(int)Neighbors.TopIdx] + t.heights[(int)Corners.Back] - 1) * height;
                float     zMinR = (z + 0 + t.sideInsets[(int)Neighbors.BottomIdx] + t.baselines[(int)Corners.Right] - 1) * height;
                float     zMaxR = (z - t.sideInsets[(int)Neighbors.TopIdx] + t.heights[(int)Corners.Right] - 1) * height;
                Vector3   bl    = new Vector3(lx, zMinL, ly);
                Vector3   bf    = new Vector3(fx, zMinF, fy);
                Vector3   bb    = new Vector3(bx, zMinB, by);
                Vector3   br    = new Vector3(rx, zMinR, ry);
                Vector3   tl    = new Vector3(lx, zMaxL, ly);
                Vector3   tf    = new Vector3(fx, zMaxF, fy);
                Vector3   tb    = new Vector3(bx, zMaxB, by);
                Vector3   tr    = new Vector3(rx, zMaxR, ry);
                Neighbors mask  = NeighborsOfTile(x, y, z);
                if ((mask & Neighbors.Top) == 0 || !avoidNeighbors)
                {
                    vertices[vertIdx + 0] = tf;                   //5
                    vertices[vertIdx + 1] = tl;                   //4
                    vertices[vertIdx + 2] = tr;                   //7
                    vertices[vertIdx + 3] = tb;                   //6
                    UVMap(t, Neighbors.Top, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if ((mask & Neighbors.BackLeft) == 0 || !avoidNeighbors)
                {
                    vertices[vertIdx + 0] = tl;                   //4
                    vertices[vertIdx + 1] = bl;                   //0
                    vertices[vertIdx + 2] = tb;                   //6
                    vertices[vertIdx + 3] = bb;                   //2
                    UVMap(t, Neighbors.BackLeft, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if ((mask & Neighbors.FrontRight) == 0 || !avoidNeighbors)
                {
                    vertices[vertIdx + 0] = bf;                   //1
                    vertices[vertIdx + 1] = tf;                   //5
                    vertices[vertIdx + 2] = br;                   //3
                    vertices[vertIdx + 3] = tr;                   //7
                    UVMap(t, Neighbors.FrontRight, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if ((mask & Neighbors.FrontLeft) == 0 || !avoidNeighbors)
                {
                    vertices[vertIdx + 0] = tl;                   //4
                    vertices[vertIdx + 1] = tf;                   //5
                    vertices[vertIdx + 2] = bl;                   //0
                    vertices[vertIdx + 3] = bf;                   //1
                    UVMap(t, Neighbors.FrontLeft, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if ((mask & Neighbors.BackRight) == 0 || !avoidNeighbors)
                {
                    vertices[vertIdx + 0] = bb;                   //2
                    vertices[vertIdx + 1] = br;                   //3
                    vertices[vertIdx + 2] = tb;                   //6
                    vertices[vertIdx + 3] = tr;                   //7
                    UVMap(t, Neighbors.BackRight, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if (usesBottomFace && (((mask & Neighbors.Bottom) == 0) || !avoidNeighbors))
                {
                    vertices[vertIdx + 0] = bl;                   //0
                    vertices[vertIdx + 1] = bf;                   //1
                    vertices[vertIdx + 2] = bb;                   //2
                    vertices[vertIdx + 3] = br;                   //3
                    UVMap(t, Neighbors.Bottom, uvs, vertIdx);

                    triangles[triIdx + 0 * 3 + 0] = vertIdx + 0;
                    triangles[triIdx + 0 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 0 * 3 + 2] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 0] = vertIdx + 2;
                    triangles[triIdx + 1 * 3 + 1] = vertIdx + 1;
                    triangles[triIdx + 1 * 3 + 2] = vertIdx + 3;
                    triIdx  += 2 * 3;
                    vertIdx += 4;
                }
                if (t.invisible)
                {
                    transparentTriIdx = triIdx;
                }
                else
                {
                    opaqueTriIdx = triIdx;
                }
            }
        }
        Array.Resize <Vector3>(ref vertices, vertIdx);
        Array.Resize <Vector2>(ref uvs, vertIdx);
        Array.Resize <int>(ref opaqueTriangles, opaqueTriIdx);
        Array.Resize <int>(ref transparentTriangles, transparentTriIdx);

        mesh.vertices     = vertices;
        mesh.uv           = uvs;
        mesh.subMeshCount = 2;
        mesh.SetTriangles(opaqueTriangles, 0);
        mesh.SetTriangles(transparentTriangles, 1);
        mesh.RecalculateNormals();
        mesh.Optimize();
        mf.sharedMesh = mesh;
        mc.convex     = false;

        InvalidateOverlayMesh();
    }
Beispiel #29
0
 void ResetStacks(Vector2 oldSize)
 {
     MapColumn[] newStacks = new MapColumn[(int)_size.x*(int)_size.y];
     // Debug.Log("reset new sz "+_size+" old sz "+oldSize);
     for(int i = 0; i < newStacks.Length; i++) {
         if(oldSize != Vector2.zero) {
             if(oldSize == _size) {
                 newStacks[i] = stacks[i];
             } else {
                 int y = i/(int)_size.x;
                 int x = i-y*(int)_size.x;
                 int oldI = y*(int)oldSize.x+x;
                 if(x >= 0 && x < oldSize.x && x < _size.x &&
                    y >= 0 && y < oldSize.y && y < _size.y &&
                      stacks != null &&
                      oldI < stacks.Length) {
                     newStacks[i] = stacks[oldI];
                 } else {
                     // Debug.Log("("+x+","+y+")"+" new i "+i+" old i "+oldI+" out of range "+stacks.Length);
                     newStacks[i] = null;
                 }
             }
         } else {
             newStacks[i] = null;
         }
     }
     this.stacks = newStacks;
     RemakeMesh();
 }
Beispiel #30
0
 void SetTileStackAt(MapTile stack, int x, int y)
 {
     int idx = y*(int)_size.x+x;
     if(idx >= stacks.Length) {
         Array.Resize(ref stacks, idx+1);
     }
     if(stacks[idx] == null) {
         stacks[idx] = new MapColumn();
     }
     if(stacks[idx].Count > 0) {
         stacks[idx].Clear();
     }
     stacks[idx].Add(stack);
 }
Beispiel #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Chunk"/> class.
 /// </summary>
 /// <param name="world">The column to initialize to.</param>
 /// <remarks></remarks>
 public Chunk(MapColumn column, Vector3 Location)
     : this(Location)
 {
     this.Column = column;
 }