static int ToString(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector2))) { UnityEngine.Vector2 obj = (UnityEngine.Vector2)ToLua.ToObject(L, 1); string o = obj.ToString(); LuaDLL.lua_pushstring(L, o); return(1); } else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector2), typeof(string))) { UnityEngine.Vector2 obj = (UnityEngine.Vector2)ToLua.ToObject(L, 1); string arg0 = ToLua.ToString(L, 2); string o = obj.ToString(arg0); LuaDLL.lua_pushstring(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Vector2.ToString")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public GameObject InstantiateObject(GameObject instance, Vector2 position) { Vector2Int localPos = WorldToLocal(position); Debug.Log("Creating obj in pos " + position.ToString() + " (tile " + localPos.ToString() + ")"); if (IsValidCoords(localPos) && m_tiles[localPos.x, localPos.y].IsExist) { throw new System.Exception("Cannot create object in pos " + localPos.x + " : " + localPos.y + ". Tile is not vacant."); } GameObject createdObject = Instantiate(instance, position, TileUtils.InitRotation); m_tiles[localPos.x, localPos.y].Object = createdObject; m_tiles[localPos.x, localPos.y].IsExist = true; return(createdObject); }
//Vector2 _dump = Vector2.zero; //Vector3 _delta; //private var lastPos : Vector3 = Vector3.zero; void HandleEvents() { Event e = Event.current; Vector2 mp = e.mousePosition; //bool used = false; if(e.type == EventType.MouseUp && _dragTarget != DragTargetType.Null) { _dragTarget = DragTargetType.Null; e.Use(); } if(e.type == EventType.MouseDown && e.button == 0 && _dragTarget == DragTargetType.Null) { if(_boxNodes[0].Contains(mp)) { _dragTarget = DragTargetType.BoxNode0; } else if(_boxNodes[1].Contains(mp)) { _dragTarget = DragTargetType.BoxNode1; } else if(_boxNodes[2].Contains(mp)) { _dragTarget = DragTargetType.BoxNode2; } else if(_boxNodes[3].Contains(mp)) { _dragTarget = DragTargetType.BoxNode3; } else if(_boxNodes[4].Contains(mp)) { _dragTarget = DragTargetType.BoxNode4; } else if(_boxNodes[5].Contains(mp)) { _dragTarget = DragTargetType.BoxNode5; } else if(_boxNodes[6].Contains(mp)) { _dragTarget = DragTargetType.BoxNode6; } else if(_boxNodes[7].Contains(mp)) { _dragTarget = DragTargetType.BoxNode7; } else if(_boxNodes[8].Contains(mp)) { _dragTarget = DragTargetType.BoxNode8; } if(_dragTarget == DragTargetType.Null) { if(_paperRect.Contains(mp)) { _dragTarget = DragTargetType.SpriteTexture; } } _dragLastPos = mp; e.Use(); } if(e.type == EventType.MouseDrag && e.button == 0 && _dragTarget != DragTargetType.Null) { _dragDelta = mp - _dragLastPos; if(_frame != null && _texture != null && _dragTarget >= DragTargetType.BoxNode0 && _dragTarget <= DragTargetType.BoxNode8) { bool unlockedX = false; bool unlockedY = false; bool unlockedW = false; bool unlockedH = false; if(_dragTarget == DragTargetType.BoxNode0) { unlockedX = true; unlockedY = true; } else if(_dragTarget == DragTargetType.BoxNode1) { unlockedY = true; } else if(_dragTarget == DragTargetType.BoxNode2) { unlockedY = true; unlockedW = true; } else if(_dragTarget == DragTargetType.BoxNode3) { unlockedX = true; } else if(_dragTarget == DragTargetType.BoxNode4) { unlockedX = true; unlockedY = true; unlockedW = true; unlockedH = true; } else if(_dragTarget == DragTargetType.BoxNode5) { unlockedW = true; } else if(_dragTarget == DragTargetType.BoxNode6) { unlockedX = true; unlockedH = true; } else if(_dragTarget == DragTargetType.BoxNode7) { unlockedH = true; } else if(_dragTarget == DragTargetType.BoxNode8) { unlockedX = true; unlockedH = true; } if(unlockedX || unlockedY || unlockedW || unlockedH) { //_dragDelta.x = Mathf.Ceil(_dragDelta.x / _zoom); //_dragDelta.y = Mathf.Ceil(_dragDelta.y / _zoom); //float dx = Mathf.Floor(_dragDelta.x / _zoom); int dxZoomed = Mathf.RoundToInt(_dragDelta.x / _zoom); int dyZoomed = Mathf.RoundToInt(_dragDelta.y / _zoom); //Debug.Log("dxZoomed = " + dxZoomed.ToString()); Debug.Log("_dragDelta = " + _dragDelta.ToString()); if(unlockedX) { if(_frame.X + dxZoomed < 0) { dxZoomed = Mathf.FloorToInt((0 - _frame.X)); } else if(_frame.X + dxZoomed > _frame.MaxX) { dxZoomed = Mathf.FloorToInt((_frame.MaxX - _frame.X)); } _frame.X += dxZoomed; _frame.Width -= dxZoomed; } // if(unlockedY) { if(_frame.Y + dyZoomed < 0) { dyZoomed = Mathf.FloorToInt((0 - _frame.Y)); } else if(_frame.X + dyZoomed > _frame.MaxY) { dyZoomed = Mathf.FloorToInt((_frame.MaxY - _frame.Y)); } _frame.Y += dyZoomed; _frame.Height -= dyZoomed; } if(unlockedW) { if(_frame.MaxX + dxZoomed < _frame.X) { dxZoomed = Mathf.FloorToInt((_frame.X - _frame.MaxX)); } else if(_frame.MaxX + dxZoomed > _texture.width) { dxZoomed = Mathf.FloorToInt((_texture.width - _frame.MaxX)); } _frame.Width += dxZoomed; } if(unlockedH) { if(_frame.MaxY + dyZoomed < _frame.Y) { dyZoomed = Mathf.FloorToInt((_frame.Y - _frame.MaxY)); } else if(_frame.MaxY + dyZoomed > _texture.height) { dyZoomed = Mathf.FloorToInt((_texture.height - _frame.MaxY)); } _frame.Height += dyZoomed; } } } if(_texture != null && _dragTarget == DragTargetType.SpriteTexture) { float tWidthScaled = _texture.width * _zoom; float tHeightScaled = _texture.height * _zoom; if(tWidthScaled > _paperRect.width) { _paperOrigin.x = Mathf.Clamp(_paperOrigin.x - _dragDelta.x, 0, tWidthScaled - _paperRect.width); } else { _paperOrigin.x = 0; } if(tHeightScaled > _paperRect.height) { _paperOrigin.y = Mathf.Clamp(_paperOrigin.y - _dragDelta.y, 0, tHeightScaled - _paperRect.height); } else { _paperOrigin.y = 0; } } //_dragDelta = mp - _dragLastPos; //if(mp.x - _dragLastPos.x >= _zoom || mp.y - _dragLastPos.y >= _zoom) //{ _dragLastPos = mp; //} _dragLastPos = mp; e.Use(); } if(e.type == EventType.ScrollWheel && _paperRect.Contains(mp) && _dragTarget == DragTargetType.Null) { if(e.delta.y < 0f) { ZoomIn(); } else if(e.delta.y > 0f) { ZoomOut(); } e.Use(); } }
/// <summary> /// This will build a structure that fits within the dimensions /// based on the seed passed in. /// </summary> /// <returns>The structure.</returns> /// <param name="dimensions">Dimensions.</param> /// <param name="seed">Seed.</param> /// <param name="theme">Theme.</param> public static GameObject buildStructure(Vector2 dimensions, int seed, AreaBiome theme, float civValue) { // First we begin by determining how many blocks we can fit in the x and y dimensions // plotDimensions is how many modules you can fit in the structure. float blockDimension = 3.0f; Vector2 plotDimensions = new Vector2( Mathf.FloorToInt( dimensions.x / blockDimension ), Mathf.FloorToInt( dimensions.y / blockDimension )); // Create random blueprints int[][] blueprints = generateBoringBlueprints (plotDimensions, seed, civValue); // If there are no blue prints don't go any further if(blueprints == null){ return null; } // Build from the blueprints GameObject structure = new GameObject ("Structure: "+seed+", "+dimensions.ToString()); for(int x = 0; x < blueprints.Length; x ++){ for(int y = 0; y < blueprints[x].Length; y ++){ // Get the number of floors wanted from this module's position. int floors = blueprints[x][y]; // Move to the next portion if there's nothin to build here. if(floors <= 0){ continue; } int[][] wallInformation = wallsModuleIsTouching(blueprints, x, y); // Build a module for each floor for(int f = 0; f < floors; f ++){ // Whether or not to create a turret on this floor bool createTurret = false; // Just use a cube for now GameObject module = null; // The number of walls that are touching this floor int numOfWallsTouchingThisFloor = 0; List<int> neighboringWallDirections = new List<int>(); // Find the walls touching this floor for(int w = 0; w < wallInformation.Length; w ++){ if(wallInformation[w][1] >= f + 1){ numOfWallsTouchingThisFloor ++; neighboringWallDirections.Add(wallInformation[w][0]); } } if(numOfWallsTouchingThisFloor == 0){ module = Resources.Load("Structures/Civilization/Basic/0STop") as GameObject; module = GameObject.Instantiate(module); } else if(numOfWallsTouchingThisFloor == 1){ if(f == floors-1){ module = Resources.Load("Structures/Civilization/Basic/1STop") as GameObject; } else { module = Resources.Load("Structures/Civilization/Basic/1SMid") as GameObject; } module = GameObject.Instantiate(module); // Find the correct rotation. switch(neighboringWallDirections[0]){ // East case 0: module.transform.Rotate(new Vector3(0,270,0)); break; // West case 1: module.transform.Rotate(new Vector3(0,90,0)); break; // North case 2: module.transform.Rotate(new Vector3(0,180,0)); break; } } else if(numOfWallsTouchingThisFloor == 2){ // Grab the correct type of 2 sided wall string typeOfWall = "I"; float chancesOfTurret = .05f; // Don't think about it just roll w/ it int nwd = neighboringWallDirections[0] + neighboringWallDirections[1]; if(nwd > 1 && nwd < 5){ typeOfWall = "L"; } // Instantiate the correct module if(f == floors-1){ module = Resources.Load("Structures/Civilization/Basic/2S"+typeOfWall+"Top") as GameObject; if(Random.Range(0f,1f) < chancesOfTurret && typeOfWall == "L"){ createTurret = true; } } else { module = Resources.Load("Structures/Civilization/Basic/2S"+typeOfWall+"Mid") as GameObject; } module = GameObject.Instantiate(module); // Set the correct rotation if(typeOfWall.Equals("I")){ if(nwd == 5){ module.transform.Rotate(new Vector3(0,90,0)); } } else { if(neighboringWallDirections[0] == 0){ if(neighboringWallDirections[1] == 2){ module.transform.Rotate(new Vector3(0,180,0)); } else { module.transform.Rotate(new Vector3(0,-90,0)); } } else if( nwd == 3) { module.transform.Rotate(new Vector3(0,90,0)); } else { module.transform.Rotate(new Vector3(0,-0,0)); } } } else if(numOfWallsTouchingThisFloor == 3){ if(f == floors-1){ module = Resources.Load("Structures/Civilization/Basic/3STop") as GameObject; } else { module = Resources.Load("Structures/Civilization/Basic/3SMid") as GameObject; } module = GameObject.Instantiate(module); // rotate appropriately // find wall it's not touching int direction = 1234; for(int w = 0; w < neighboringWallDirections.Count; w ++){ if(neighboringWallDirections[w] == 0){ direction -= 1000; } if(neighboringWallDirections[w] == 1){ direction -= 200; } if(neighboringWallDirections[w] == 2){ direction -= 30; } if(neighboringWallDirections[w] == 3){ direction -= 4; } } switch(direction){ case 1000: module.transform.Rotate(new Vector3(0,90,0)); break; case 200: module.transform.Rotate(new Vector3(0,-90,0)); break; case 30: module.transform.Rotate(new Vector3(0,0,0)); break; case 4: module.transform.Rotate(new Vector3(0,180,0)); break; } } else if(numOfWallsTouchingThisFloor == 4){ if(f == floors-1){ module = Resources.Load("Structures/Civilization/Basic/4STop") as GameObject; module = GameObject.Instantiate(module); } } else { module = GameObject.CreatePrimitive(PrimitiveType.Cube); module.transform.localScale = Vector3.one*blockDimension; } if(module != null){ // Make sure the cube is apart of the parent module.transform.SetParent(structure.transform); Vector3 positionForModule = (new Vector3(x,f,y))*blockDimension; // Set the appropriate position nd scale module.transform.localPosition = positionForModule; // Spawn a turret if(createTurret){ GameObject turret = EliDavis.Characters.Enemy.EnemyFactory.CreateTurret(positionForModule + new Vector3(0, 1.5f, 0)); turret.transform.SetParent(module.transform); } } } } } return structure; }
/// <summary> /// Generates terrain and the buildings that occupy the terrain. /// </summary> /// <param name="sectionsInXDirection">Sections in X direction.</param> /// <param name="sectionsInYDirection">Sections in Y direction.</param> /// <param name="border">Border of sections passed in. if you pass in 10*10 sections /// and a border of 2, your final result will be a 14*14 /// </param> void CreateArea(int sectionsInXDirection, int sectionsInYDirection, int border) { // Clear what we have defined as 'free area', array of area that AI can move through freeArea.Clear (); // Choose the maps dimensions int mapHeight = 1025; int mapWidth = 1025; // Create a seed for our generation, useful for generating the same map over and over if we so choose to Vector2 civSeed = new Vector2 (Random.Range (0, 10000), Random.Range (0, 10000)); // Produce a civilization map, with alpha being civilization Texture2D civMap = MapGen.GetInstance ().CreateMap (mapWidth, mapHeight, (int)civSeed.x, (int)civSeed.y); civMap = MapGen.GetInstance ().SmoothEdges (civMap); guiMapRenderOne = civMap;//for guiPurposes. // Create our terrain object and position and scale it correctely GameObject terrain = GameObject.CreatePrimitive(PrimitiveType.Plane); terrain.transform.position = new Vector3 ( (dimensionOfSection*(sectionsInXDirection))/2, 0, (dimensionOfSection*(sectionsInYDirection))/2); terrain.transform.Rotate (new Vector3 (0, 180, 0)); terrain.transform.localScale = new Vector3 ( (dimensionOfSection*(sectionsInXDirection))/10, 1, (dimensionOfSection*(sectionsInYDirection))/10); // Set the material on the terrain that will make it look like terain Material material = new Material(Shader.Find("MyShaders/TerrainTwoLayer")); // Set the texture on the terrain that will represent civilization material.SetTexture ("_MainTex", civArea); material.SetTextureScale ("_MainTex", new Vector2(70,70)); // Set the texture on the terrain that will represent the wild. material.SetTexture ("_PathTex", uncivArea); material.SetTextureScale ("_PathTex", new Vector2(70,70)); // Set the alpha that determines whether or not to render the wild or the civilization texture. material.SetTexture ("_PathMask", civMap); // Set the material to the terrain terrain.GetComponent<Renderer> ().material = material; // Create the area object currentArea = new Area ("Civ Seed: "+civSeed.ToString(), AreaBiome.Test, civSeed); // Create structures by splitting up the civilization map into multiple sections to be generated. for (int curXSec = 0; curXSec < sectionsInXDirection; curXSec++) { for (int curYSec = 0; curYSec < sectionsInYDirection; curYSec++) { int sectionMapWidth = mapWidth / sectionsInXDirection; int sectionMapHeight = mapHeight / sectionsInYDirection; Texture2D sectionMap = new Texture2D (sectionMapWidth, sectionMapHeight); sectionMap.SetPixels (civMap.GetPixels (curXSec * sectionMapWidth, curYSec * sectionMapHeight, sectionMapWidth, sectionMapHeight)); sectionMap.Apply (); createSection (curXSec, curYSec, sectionMap); } } // Spawn trees to make things look more full spawnUncivilizedObjects (sectionsInXDirection, sectionsInYDirection, civMap); }
/// <summary> /// Returns a nicely formatted string for the bounds. /// </summary> /// <param name="format"></param> public string ToString(string format) { return(string.Format(CultureInfo.InvariantCulture.NumberFormat, "Center: {0}, Extents: {1}", m_center.ToString(format), m_extents.ToString(format))); }
public virtual void DebugLog(Vector2 message) { if (_showDebug) Debug.Log(message.ToString()); }
static bool Vector2_ToString(JSVCall vc, int argc) { int len = argc; if (len == 0) { UnityEngine.Vector2 argThis = (UnityEngine.Vector2)vc.csObj; JSApi.setStringS((int)JSApi.SetType.Rval, argThis.ToString()); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
static bool Vector2_ToString__String(JSVCall vc, int argc) { int len = argc; if (len == 1) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); UnityEngine.Vector2 argThis = (UnityEngine.Vector2)vc.csObj; JSApi.setStringS((int)JSApi.SetType.Rval, argThis.ToString(arg0)); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = "F2"; } if (formatProvider == null) { formatProvider = CultureInfo.InvariantCulture.NumberFormat; } return(UnityString.Format("Origin: {0}, Dir: {1}", m_Origin.ToString(format, formatProvider), m_Direction.ToString(format, formatProvider))); }
void DrawNode(Node node) { Color originalColor = GUI.color; if(brain.defaultNode == node) GUI.color = Color.yellow; if(brain.anyNode == node) GUI.color = Color.magenta; if(selectedNode == node) GUI.color = Color.green; Vector2 originalPosition = new Vector2(node.position.x, node.position.y); node.position.x += scrollPosition.x; node.position.y += scrollPosition.y; if(selectedNode == node) { Rect positionLabelRect = new Rect(node.position); positionLabelRect.y += node.position.height; GUI.Label(positionLabelRect, originalPosition.ToString()); } GUILayout.BeginArea(node.position); GUI.Box(new Rect(0, 0, node.position.width, node.position.height), ""); GUIStyle labelStyle = new GUIStyle(GUI.skin.label); labelStyle.fontSize = brain.anyNode == node ? 48 : 12; labelStyle.fontStyle = FontStyle.Bold; labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.wordWrap = true; GUI.Label(new Rect(0, 0, node.position.width, node.position.height), node.name, labelStyle); GUILayout.EndArea(); if(Event.current.button == 0) { switch(Event.current.type) { case EventType.MouseDown: if(node.position.Contains(Event.current.mousePosition)) { if(linkNode != null && linkNode != node) { if(node == brain.anyNode) { ShowNotification(new GUIContent("Can not connect to the Ω node.")); } else if(linkNode.HasConnectionTo(node)) { ShowNotification(new GUIContent("Can not connect to the same node twice.")); } else { selectedConnection = brain.CreateConnection(linkNode, node); AddToBrainAsset(selectedConnection); } linkNode = null; } dragNode = node; selectedNode = node; Event.current.Use(); Save(); } break; case EventType.MouseDrag: if(dragNode == node) { originalPosition.x += Event.current.delta.x; originalPosition.y += Event.current.delta.y; Event.current.Use(); Repaint(); } break; case EventType.MouseUp: if(dragNode == node) { dragNode = null; int snap = 64; originalPosition.x = Mathf.RoundToInt(originalPosition.x / snap) * snap; originalPosition.y = Mathf.RoundToInt(originalPosition.y / snap) * snap; Event.current.Use(); Repaint(); } break; } } node.position.x = originalPosition.x; node.position.y = originalPosition.y; GUI.color = originalColor; }
public string ToString(string format, IFormatProvider formatProvider) { return(UnityString.Format("Origin: {0}, Dir: {1}", m_Origin.ToString(format, formatProvider), m_Direction.ToString(format, formatProvider))); }
// Returns a nicely formatted string for this ray. public string ToString(string format) { return(String.Format("Origin: {0}, Dir: {1}", m_Origin.ToString(format), m_Direction.ToString(format))); }