void OnGUI() { if (GUILayout.Button("select")) { if (obj != null) { Selection.activeGameObject = obj; } else { TileWorldCreator _c = GameObject.FindObjectOfType <TileWorldCreator>(); obj = _c.gameObject; InitWindow(obj); } } if (window != null) { int _tilesets = 0; for (int tp = 0; tp < twc.configuration.presets.Count; tp++) { _tilesets += twc.configuration.presets[tp].tiles.Count; } scrollPosition = GUI.BeginScrollView(new Rect(0, 25, Screen.width, Screen.height - 50), scrollPosition, new Rect(0, 20, Screen.width - 50, (_tilesets * 295f) + 10f)); TileWorldConfigurationEditor.ShowPresetSettings(twc.configuration); GUI.EndScrollView(); } }
//---------------------------------------------------------------- private void OnEnable() { //get script Reference creator = (TileWorldCreator)target; //SceneView.onSceneGUIDelegate = GridUpdate; LoadResources(); undoStack = new TileWorldUndoStack <bool[]>(); redoStack = new TileWorldUndoStack <bool[]>(); //get all available masks TileWorldMaskLookup.GetMasks(out creator.iMasks, out _maskNames); //get all available algorithms TileWorldAlgorithmLookup.GetAlgorithms(out creator.iAlgorithms, out algorithmNames); #if UNITY_5_3_OR_NEWER || UNITY_5_3 currentScene = EditorSceneManager.GetActiveScene(); #else currentScene = EditorApplication.currentScene; #endif EditorApplication.hierarchyWindowChanged += HierarchyWindowChanged; }
//Save and Load Methods //-------- public static void Save(string _path, TileWorldCreator _creator) { saveMapContent = ""; if (_path == "") { return; } for (int i = 0; i < _creator.configuration.worldMap.Count; i++) { bool[] _tmpMapSingle = new bool[_creator.configuration.worldMap[i].cellMapSingle.Length]; bool[] _tmpMaskMapSingle = new bool[_creator.configuration.worldMap[i].maskMapSingle.Length]; _tmpMapSingle = _creator.configuration.worldMap[i].cellMapSingle; _tmpMaskMapSingle = _creator.configuration.worldMap[i].maskMapSingle; SaveMap _map = new SaveMap(_tmpMapSingle, _tmpMaskMapSingle, _creator.configuration.global.width, _creator.configuration.global.height, _creator.configuration.global.layerPresetIndex[i], _creator.configuration.worldMap[i].useMask, _creator.configuration.worldMap[i].selectedMask); AddData <SaveMap>(_map); } byte[] bytes = SerializationUtility.SerializeValue(saveMapContent, DataFormat.Binary); File.WriteAllBytes(_path, bytes); }
//Save and Load Methods //-------- public static void Save(string _path, TileWorldCreator _creator) { saveMapContent = ""; if (_path == "") { return; } for (int i = 0; i < _creator.configuration.worldMap.Count; i++) { bool[] _tmpMapSingle = new bool[_creator.configuration.worldMap[i].cellMapSingle.Length]; bool[] _tmpMaskMapSingle = new bool[_creator.configuration.worldMap[i].maskMapSingle.Length]; _tmpMapSingle = _creator.configuration.worldMap[i].cellMapSingle; _tmpMaskMapSingle = _creator.configuration.worldMap[i].maskMapSingle; SaveMap _map = new SaveMap(_tmpMapSingle, _tmpMaskMapSingle, _creator.configuration.global.width, _creator.configuration.global.height, _creator.configuration.worldMap[i].useMask, _creator.configuration.worldMap[i].selectedMask); AddData <SaveMap>(_map); } FileStream _fs = new FileStream(_path, FileMode.Create, FileAccess.Write); StreamWriter _sw = new StreamWriter(_fs); _sw.Write(saveMapContent); _sw.Flush(); _sw.Close(); }
public static TileWorldConfiguration Create(string name, TileWorldCreator _creator) { var _path = EditorUtility.SaveFilePanel("new TileWorldCreator configuration file", "Assets", name, "asset"); if (string.IsNullOrEmpty(_path)) { return(null); } var _config = ScriptableObject.CreateInstance <TileWorldConfiguration>(); Path.ChangeExtension(_path, ".asset"); AssetDatabase.CreateAsset(_config, makeRelativePath(_path)); AssetDatabase.Refresh(); if (_creator != null) { _creator.configuration = _config; _creator.firstTimeBuild = true; } else { Selection.activeObject = _config; } //add start preset AddNewPreset(_config); return(_config); }
public static void InitWindow(GameObject _obj) { // Get existing open window or if none, make a new one: window = (TileWorldCreatorEditorPresetsWindow)EditorWindow.GetWindow(typeof(TileWorldCreatorEditorPresetsWindow)); twc = _obj.GetComponent <TileWorldCreator>(); //editor = (TileWorldConfiguration[])Resources.FindObjectsOfTypeAll(typeof(TileWorldConfiguration)); obj = _obj; }
void Start() { if (creator == null) { creator = GameObject.FindObjectOfType <TileWorldCreator>(); if (creator == null) { Debug.LogWarning("No TileWorldCreator prefab in the scene"); } } Init(); }
#pragma warning disable CS0618 void OnEnable() { twos = (TileWorldObjectScatter)target; creator = twos.GetComponent <TileWorldCreator>(); placeLayers = twos.GetLayers(); #if UNITY_5_3_OR_NEWER || UNITY_5_3 currentScene = EditorSceneManager.GetActiveScene(); #else currentScene = EditorApplication.currentScene; #endif EditorApplication.hierarchyWindowChanged += HierarchyWindowChanged; }
public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config) { //create a new temp map bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)]; //set the circle radius float _radius = 5; //loop through the maps x and y length for (int x = 0; x < _config.global.width; x++) { for (int y = 0; y < _config.global.height; y++) { //get center point of the map Vector2 _center = new Vector2(_config.global.width / 2, _config.global.height / 2); //current tile position Vector2 _currPos = new Vector2(x, y); //get distance from its current cell position to the center of the map float _dist = Vector2.Distance(_center, _currPos); //check if the current distance is not to far away from its radius //and set the appropriate values depending of if invert is set to false or true if (_dist <= _radius) { if (!_config.global.invert) { _tmpMap[x, y] = false; } else { _tmpMap[x, y] = true; } } else { if (!_config.global.invert) { _tmpMap[x, y] = true; } else { _tmpMap[x, y] = false; } } } } //return the map return(_tmpMap); }
public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config) { //create a temp map bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)]; //loop through the maps x and y length for (int y = 0; y < _map.GetLength(1); y++) { for (int x = 0; x < _map.GetLength(0); x++) { //here we are using the TileWorldNeighbourCounter to count //the neighbour cells of the current cell from the map. int _c = 0; _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert); //if invert is set to false in the settings of TileWorldCreator if (!_config.global.invert) { //if the current cell has got 8 neighbours //then the cell is not located on the border of the island if (_c == 8 || _map[x, y]) { _tmpMap[x, y] = true; } //else we can be sure that the current cell is a border cell else { _tmpMap[x, y] = false; } } else { //inverted tmpMap values when invert is set to true. if (_c == 8) { _tmpMap[x, y] = false; } else { _tmpMap[x, y] = true; } } } } //return the modified map return(_tmpMap); }
public static void ShowOSConfigurationEditor(TileWorldObjectScatterConfiguration _config, TileWorldObjectScatter _twos, TileWorldCreator _creator, string[] _placeLayers, Texture2D _iconMaskLayerArrow) { if (_config == null) { EditorGUILayout.HelpBox("Please create or load a configuration file.", MessageType.Info); return; } twos = _twos; creator = _creator; placeLayers = _placeLayers; DragDropArea(_config); ShowPaintObjects(_config); ShowPositionBasedObjects(_config); ShowRuleBasedObjects(_config); }
public void Start() { bool _error1 = false; bool _error2 = false; if (creator == null) { //try to find tileworldcreator prefab creator = GameObject.FindObjectOfType(typeof(TileWorldCreator)) as TileWorldCreator; if (creator == null) { _error1 = true; Debug.LogWarning("no TileWorldCreator prefab in the scene"); } else { _error1 = false; } } if (editorCam == null) { editorCam = GameObject.FindObjectOfType(typeof(Camera)) as Camera; if (editorCam == null) { _error2 = true; } else { _error2 = false; } } if (!_error1 && !_error2) { //init Editor and generate map //Init(true); creator.configuration.ui.autoBuild = true; } }
void OnGUI() { if (GUILayout.Button("select")) { if (obj != null) { Selection.activeGameObject = obj; } else { TileWorldCreator _c = GameObject.FindObjectOfType <TileWorldCreator>(); obj = _c.gameObject; InitWindow(obj); } } if (window != null) { TileWorldConfigurationEditor.ShowGlobalSettings(twc.configuration); } }
void OnGUI() { if (GUILayout.Button("select")) { if (obj != null) { Selection.activeGameObject = obj; } else { TileWorldCreator _c = GameObject.FindObjectOfType <TileWorldCreator>(); obj = _c.gameObject; InitWindow(obj); } } if (window != null) { editor[0].ShowEdit(); } }
static void ShowPresetSettingsFoldout(TileWorldConfiguration _config) { // Show preset settings GUI.color = colorGUIFoldout2; EditorGUILayout.BeginVertical("Box"); GUI.color = Color.white; GUILayout.BeginHorizontal("Box"); _config.ui.showPresetSettings = GUILayout.Toggle(_config.ui.showPresetSettings, ("Presets"), GUI.skin.GetStyle("foldout"), GUILayout.ExpandWidth(true), GUILayout.Height(18)); if (GUILayout.Button(iconUndockWindow, "ToolbarButton", GUILayout.Width(25))) { TileWorldCreator _c = GameObject.FindObjectOfType <TileWorldCreator>(); TileWorldCreatorEditorPresetsWindow.InitWindow(_c.gameObject); } GUILayout.EndHorizontal(); if (_config.ui.showPresetSettings) { ShowPresetSettings(_config); } EditorGUILayout.EndVertical(); }
public static void Load(string _path, TileWorldCreator _creator) { if (_path == "") { return; } isLoading = true; byte[] bytes = File.ReadAllBytes(_path); saveMapContent = SerializationUtility.DeserializeValue <string>(bytes, DataFormat.Binary); //split file in several xml maps string[] _sp = new string[] { "---" }; string[] lines = saveMapContent.Split(_sp, System.StringSplitOptions.None); //("---"[0]); _creator.configuration.worldMap = new List <TileWorldConfiguration.WorldMap>(); _creator.configuration.global.layerCount = lines.Length - 1; //clear all settings except presets _creator.ClearSettings(false, lines.Length - 1); //load back map for each layer for (int l = 0; l < lines.Length - 1; l++) { SaveMap _map = GetData <SaveMap>(lines[l]); _creator.configuration.global.width = _map.width; _creator.configuration.global.height = _map.height; _creator.configuration.global.layerPresetIndex[l] = _map.preset; _creator.configuration.worldMap.Add(new TileWorldConfiguration.WorldMap(_creator.configuration.global.width, _creator.configuration.global.height, false, _map.useMask, _map.selectedMask)); //Load back multidimensional array from single dim array _creator.configuration.worldMap[l].cellMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].tileObjects = new GameObject[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].tileTypes = new TileWorldConfiguration.TileInformation.TileTypes[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].maskMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].oldCellMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; int _index = 0; for (int y = 0; y < _creator.configuration.global.height; y++) { for (int x = 0; x < _creator.configuration.global.width; x++) { _creator.configuration.worldMap[l].cellMap[x, y] = _map.map[_index]; // creator.worldMap[l].mapSingle[_index]; if (_map.maskMap.Length > 0) { _creator.configuration.worldMap[l].maskMap[x, y] = _map.maskMap[_index]; } _index++; } } _creator.ResizeIntArray(false, 0); } //_sr.Close(); isLoading = false; }
public static void Load(string _path, TileWorldCreator _creator) { if (_path == "") { return; } isLoading = true; FileStream _file = new FileStream(_path, FileMode.Open, FileAccess.Read); StreamReader _sr = new StreamReader(_file); saveMapContent = _sr.ReadToEnd(); //split file in several xml maps string[] _sp = new string[] { "---" }; string[] lines = saveMapContent.Split(_sp, System.StringSplitOptions.None); //("---"[0]); _creator.configuration.worldMap = new List <TileWorldConfiguration.WorldMap>(); _creator.configuration.global.layerCount = lines.Length - 1; //clear all settings except presets _creator.ClearSettings(false, lines.Length - 1); //load back map for each layer for (int l = 0; l < lines.Length - 1; l++) { SaveMap _map = GetData <SaveMap>(lines[l]); _creator.configuration.global.width = _map.width; _creator.configuration.global.height = _map.height; _creator.configuration.worldMap.Add(new TileWorldConfiguration.WorldMap(_creator.configuration.global.width, _creator.configuration.global.height, false, _map.useMask, _map.selectedMask)); //Load back multidimensional array from single dim array _creator.configuration.worldMap[l].cellMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; //_creator.configuration.worldMap[l].tileInformation = new TileWorldConfiguration.TileInformation[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].tileObjects = new GameObject[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].tileTypes = new TileWorldConfiguration.TileInformation.TileTypes[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].maskMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; _creator.configuration.worldMap[l].oldCellMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height]; //for (int i = 0; i < _creator.configuration.global.height; i++) //{ // for (int j = 0; j < _creator.configuration.global.width; j++) // { // _creator.configuration.worldMap[l].tileInformation[j, i] = new TileWorldConfiguration.TileInformation(); // } //} int _index = 0; for (int y = 0; y < _creator.configuration.global.height; y++) { for (int x = 0; x < _creator.configuration.global.width; x++) { _creator.configuration.worldMap[l].cellMap[x, y] = _map.map[_index]; // creator.worldMap[l].mapSingle[_index]; if (_map.maskMap.Length > 0) { _creator.configuration.worldMap[l].maskMap[x, y] = _map.maskMap[_index]; } _index++; } } _creator.ResizeIntArray(false, 0); } _sr.Close(); isLoading = false; }
void Awake() { creator = GameObject.Find("TileWorldCreator").GetComponent <TileWorldCreator>(); playerRigidbody = GetComponent <Rigidbody> (); }
public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config) { bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)]; //get inner terrain cells for (int y = 0; y < _map.GetLength(1); y++) { for (int x = 0; x < _map.GetLength(0); x++) { int _c = 0; _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert); if (!_config.global.invert) { if (_c == 8) { _tmpMap[x, y] = false; } else { _tmpMap[x, y] = true; } } else { if (_c == 8) { _tmpMap[x, y] = true; } else { _tmpMap[x, y] = false; } } } } //get random cells from inner terrain map bool[,] _newMap = new bool[_config.global.width, _config.global.height]; for (int y = 0; y < _map.GetLength(1); y++) { for (int x = 0; x < _map.GetLength(0); x++) { float _rnd = Random.Range(0f, 1f); if (!_config.global.invert) { //invert map if invert ist set to false _newMap[x, y] = true; } if (_rnd < 0.3f) { if (_config.global.invert) { if (_tmpMap[x, y]) { _newMap[x, y] = true; } } else { if (!_tmpMap[x, y]) { _newMap[x, y] = false; } } } } } return(_newMap); }
public static TileWorldConfiguration CreateConfigFile(TileWorldCreator _creator) { return(Create("TileWorldConfiguration", _creator)); }