void OnEnable(){ //associate all the initial variable InitialiseVariables (); //try to get the vtilesObjects vTilesObjects = GameObject.Find("TilesGroup"); if (vTilesObjects == null) { vTilesObjects = (GameObject)PrefabUtility.InstantiatePrefab (vTilesObject); } //clear old tiles ClearTilesPreview(); oldIndex = 0; grid = (Tds_Grid)target; //increase localscale with a formula if (grid != null) { vFactorScale = (1024 / grid.dimension); grid.width = 4f; grid.height = 4f; } //try to get the last Action or last levels GameObject vGameManagerObject = GameObject.Find("GameManager"); if (vGameManagerObject != null) { //make sure we go the gamemanager component if (vGameManagerObject.GetComponent<Tds_GameManager> () != null) { vGameManager = vGameManagerObject.GetComponent<Tds_GameManager> (); } } //get the teleport tile by default (hardcoded!) Texture2D vTexture2D = Resources.Load<Texture2D> ("Customs/TeleportIcon"); if (vTexture2D != null) { Tds_Texture vTds_Texture = new Tds_Texture(); vTds_Texture.vFilename = "Customs/TeleportIcon"; vTds_Texture.vTexture = vTexture2D; Texture2D vTextSelection = Resources.Load<Texture2D> ("Customs/teleportTile"); Tds_Texture vSelectionTexture = new Tds_Texture(); vSelectionTexture.vFilename = "Customs/teleportTile"; vSelectionTexture.vTexture = vTextSelection; //attach the pixeltexture to the grid if (grid != null) { grid.teleportPrefab = vTds_Texture; grid.selectionPrefab = vSelectionTexture; } } else Debug.Log ("default teleportTile is missing! Default Path = Resources/Custom/TeleportIcon.png"); //showse vAction = ""; TopMenuPickerIndex = -1; }
void OnDrawGizmos() { //teleport line are always red Gizmos.color = Color.red; if (grid == null) { grid = GameObject.Find("AutoTile").GetComponent <Tds_Grid>(); } if (Selection.activeGameObject == this.gameObject) { Event e = Event.current; Ray ray = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight)); Vector3 mousePos = ray.origin; //remove active selection if (e.type == EventType.MouseUp && !IsDragging) //enable drag { IsDragging = true; } else if (e.type == EventType.MouseUp && IsDragging) { IsDragging = false; } else if (IsDragging) { //get the new position Vector3 aligned = new Vector3(Mathf.Floor(mousePos.x / grid.width) * grid.width, Mathf.Floor(mousePos.y / grid.height) * grid.height, 0.0f); //modify current position of this square on the mouse if (this.transform.position != aligned) { this.transform.position = aligned; } } //if teleport, we draw the line bewteen the 2 objects if (vTileType == cTileType.Teleport) { if (vLinkedObject == null) { Debug.Log("Find another linked object because it's missing!"); } else { //draw a line between both Gizmos.DrawLine(this.transform.position, vLinkedObject.transform.position); } } } }
public void init() { grid = (Tds_Grid)FindObjectOfType(typeof(Tds_Grid)); }