public void AddObject(int x, int y, GameObject obj) { if (isInitialized) { if (mapBlockData != null) { if (obj != null) { if (obj.transform.parent != this.gameObject.transform) { obj.transform.parent = this.gameObject.transform; MapPosition mapPosition = obj.GetComponent <MapPosition> (); if (mapPosition != null) { mapPosition.originX = x; mapPosition.originY = y; mapPosition.mapBlockView = this; } } MapValue mapValue = obj.GetComponent <MapValue> (); if (mapValue != null) { switch (mapValue.layer) { case MapLayer.Floor: mapBlockData.setFloorInt(x, y, mapValue.strValue); break; case MapLayer.Main: mapBlockData.setMainInt(x, y, mapValue.strValue); break; } } } } } else { throw new UnityException("MapBlockView isn't initialized"); } }
private void CreateMapObject(int x, int y, GameObject mapPrefab, GameObject parent, string resourceName, int resourceInt, MapLayer layer) { if (mapPrefab != null) { if (parent != null) { GameObject prefab = (GameObject)Instantiate(mapPrefab, parent.transform.position + calculateTransformPosition(x, y), Quaternion.identity, parent.transform); MapPosition mapPosition = prefab.GetComponent <MapPosition> (); if (mapPosition != null) { mapPosition.originX = x; mapPosition.originY = y; mapPosition.mapBlockView = this; } MapValue mapValue = prefab.GetComponent <MapValue> (); if (mapValue == null) { mapValue = prefab.AddComponent <MapValue> (); } mapValue.intValue = resourceInt; mapValue.strValue = resourceName; mapValue.layer = layer; PathFindingMovement pathFindingMovement = prefab.GetComponent <PathFindingMovement> (); if (pathFindingMovement != null) { pathFindingMovement.setAsciiMapScript(this.asciiMapScript); pathFindingMovement.player = this.asciiMapScript.player; } } } else { throw new MissingReferenceException("Map Prefab Reference Missing"); } }