public override VisualElement CreateInspectorGUI() { // display the UIElements assets loaded in OnEnable root.Clear(); tree.CloneTree(root); // Add a callback to the inspector button to open a new LevelEditorWindow with the inspectedLevel as an arg Button editButton = root.Q <Button>(name = "open-editor-button"); editButton.clickable.clicked += () => LevelEditorWindow.EditLevel(inspectedLevel); // fill the info labels width = inspectedLevel.gridWidth; height = inspectedLevel.gridHeight; levelName = inspectedLevel.levelName; root.Q <Label>("width-value").text = width.ToString(); root.Q <Label>("height-value").text = height.ToString(); root.Q <Label>("name-value").text = levelName; // display the grid CreateGrid(); // return root to display it return(root); }
static void Init() { // Get existing open window or if none, make a new one: LevelEditorWindow window = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow)); window.Show(); }
static void OpenWindow() { LevelEditorWindow window = (LevelEditorWindow)GetWindow(typeof(LevelEditorWindow)); window.minSize = new Vector2(600, 300); window.Show(); }
public static T OpenEditorWindow <T>(string title) where T : EditorWindow { var window = LevelEditorWindow.GetWindow <T>(); window.titleContent = EditorGUIUtility.TrTextContent(title); return(window); }
public static T OpenEditorWindow <T>(GUIContent title) where T : EditorWindow { var window = LevelEditorWindow.GetWindow <T>(); window.titleContent = title; return(window); }
static void ShowWindow() { LevelEditorWindow window = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow)); window.titleContent = new GUIContent("Level Editor"); window.Show(); }
static void Init() { //Cria uma nova Window caso não tenha uma aberta LevelEditorWindow window = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow)); window.titleContent.text = "Level Editor"; window.minSize = new Vector2(Constants.minWindowWidth, Constants.minWindowHeight); window.Show(); }
public static void ShowLevelEditor() { if (window) { window.Close(); } window = GetWindow <LevelEditorWindow>(); window.titleContent = new GUIContent("LevelEditor"); window.position = new Rect(0, 0, 1600, 1000); window.minSize = new Vector2(1600, 1000); window.maxSize = new Vector2(1600, 1000); //Create Destination folder if (AssetDatabase.IsValidFolder("Assets/Export")) { //Debug.Log("Exists"); } else { string ret; ret = AssetDatabase.CreateFolder("Assets", "Export"); if (AssetDatabase.GUIDToAssetPath(ret) != "") { Debug.Log("Folder asset created"); } else { Debug.Log("Couldn't find the GUID for the path"); } } AssetDatabase.Refresh(); //Create Intermediate Data folder if (AssetDatabase.IsValidFolder("Assets/Export/Data")) { //Debug.Log("Exists"); } else { string ret; ret = AssetDatabase.CreateFolder("Assets/Export", "Data"); if (AssetDatabase.GUIDToAssetPath(ret) != "") { Debug.Log("Folder asset created"); } else { Debug.Log("Couldn't find the GUID for the path"); } } AssetDatabase.Refresh(); }
public static bool OpenEditor(int instanceId, int line) { LevelScriptableObject level = EditorUtility.InstanceIDToObject(instanceId) as LevelScriptableObject; if (level != null) { LevelEditorWindow.EditLevel(level); return(true); } return(false); }
// Entry point public static void EditLevel(LevelScriptableObject levelToEdit) { // calls OnEnable LevelEditorWindow window = GetWindow <LevelEditorWindow>(); window.serializedLevel = new SerializedObject(levelToEdit); // Load values from serializedLevel and build the grid window.LoadAndSetupGrid(); // do the binding and stuff window.SetupEditor(); }
[OnOpenAsset(1)] //當資料夾裡的檔案被點擊時的callback public static bool ShowWindowInfo(int _instanceID, int line) //每個project裡面的檔案都有自己的id { UnityEngine.Object item = EditorUtility.InstanceIDToObject(_instanceID); if (item is LevelMapSO) //點擊這類檔案的資料,開啟對應的編輯視窗 { LevelEditorWindow window = (LevelEditorWindow)GetWindow(typeof(LevelEditorWindow)); window.titleContent = new GUIContent("Level Flow Editor"); window.flowData = item as LevelMapSO; window.minSize = new Vector2(500, 250); window.Load(); } return(false); }
static void Init() { LevelEditorWindow editor = (LevelEditorWindow)EditorWindow.GetWindow <LevelEditorWindow>(); editor.titleContent = new GUIContent("Level Editor"); // Refreshes the AssetDataBase so we get the correct changes and preview images made //AssetDatabase.ImportAsset() editor.m_levelDictionary.Clear(); editor.m_previewTextures.Clear(); // Gets all the Level objects in the scene Level[] levels = GameObject.FindObjectsOfType(typeof(Level)) as Level[]; foreach (Level level in levels) { editor.m_levelDictionary.Add(level.gameObject.name, level); } }
public LevelFlowGraphView(LevelEditorWindow _editorWindow) { editorWindow = _editorWindow; StyleSheet tmpStyleSheet = Resources.Load <StyleSheet>(styleSheetName); styleSheets.Add(tmpStyleSheet); SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); this.AddManipulator(new ContentDragger()); this.AddManipulator(new SelectionDragger()); this.AddManipulator(new RectangleSelector()); this.AddManipulator(new FreehandSelector()); GridBackground grid = new GridBackground(); Insert(0, grid); grid.StretchToParentSize(); AddSearchWindow(); }
public override void OnInspectorGUI() { myLevel.fichierLevel = EditorGUILayout.ObjectField("Level : ", myLevel.fichierLevel, typeof(TextAsset), false) as TextAsset; if (GUILayout.Button("Load Level")) { if (myLevel.fichierLevel != null) { GenerateLevel(); } } if (myLevel.objects != null && myLevel.objects.Count != 0) { if (GUILayout.Button("Show Window")) { LevelEditorWindow.OpenThisWindow(myLevel); } } //base.OnInspectorGUI(); }
public StartNode(Vector2 _position, LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView) { title = "Enter"; SetPosition(new Rect(_position, defaultNodeSize)); UnityEngine.UIElements.Label label_statName = new UnityEngine.UIElements.Label("name"); mainContainer.Add(label_statName); startNameTextField = new TextField(""); //傳入label標籤,會跟對應到的label同行,否則獨立一行 startNameTextField.RegisterValueChangedCallback(value => { startName = value.newValue; }); startNameTextField.SetValueWithoutNotify(startName); mainContainer.Add(startNameTextField); _graphView.AddToClassList("GraphViewStyleSheet"); SetUpPort(); RefreshExpandedState(); RefreshPorts(); }
static void Init() { LevelEditorWindow window = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow)); window.Show(); }
static void Init() { window = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow), true, "关卡编辑"); }
public static void OpenWindow() { instance = (LevelEditorWindow)EditorWindow.GetWindow(typeof(LevelEditorWindow)); //instance.title = "Map Editor"; }
public static void Init() { LevelEditorWindow Window = GetWindow <LevelEditorWindow>("Level editor", true); Window.minSize = new Vector2(400, 150); }
private static void ShowWindow() { LevelEditorWindow window = GetWindow <LevelEditorWindow>(); }
private void tileOnGUI() { tileScrollPosition = EditorGUILayout.BeginScrollView(tileScrollPosition, true, true, GUILayout.Width(tileElement.contentRect.width), GUILayout.Width(tileElement.contentRect.height)); int rows = 0; int cols = 0; switch (layersPopupField.value) { case "Environment": for (int i = 0; i < environmentTiles.Count; i++) { if (i != 0 && i % 6 == 0) { rows++; cols = 0; } Rect drawRect = new Rect(cols * tileCell, rows * tileCell, tileCell, tileCell); Texture t = environmentTiles[i].sprite.sprite.texture; Rect spriteRect = environmentTiles[i].sprite.sprite.rect; spriteRect.x /= t.width; spriteRect.y /= t.height; //spriteRect.y = 1 - spriteRect.y; spriteRect.width /= t.width; spriteRect.height /= t.height; GUI.DrawTextureWithTexCoords(drawRect, t, spriteRect); cols++; } break; case "StaticObjects": for (int i = 0; i < staticObjectTiles.Count; i++) { if (i != 0 && i % 6 == 0) { rows++; cols = 0; } Rect drawRect = new Rect(cols * tileCell, rows * tileCell, tileCell, tileCell); Texture t = staticObjectTiles[i].sprite.sprite.texture; Rect spriteRect = staticObjectTiles[i].sprite.sprite.rect; spriteRect.x /= t.width; spriteRect.y /= t.height; //spriteRect.y = 1 - spriteRect.y; spriteRect.width /= t.width; spriteRect.height /= t.height; GUI.DrawTextureWithTexCoords(drawRect, t, spriteRect); cols++; } break; case "Enemies": for (int i = 0; i < enemySpawnerTiles.Count; i++) { if (i != 0 && i % 6 == 0) { rows++; cols = 0; } Rect drawRect = new Rect(cols * tileCell, rows * tileCell, tileCell, tileCell); Texture t = enemySpawnerTiles[i].sprite.sprite.texture; Rect spriteRect = enemySpawnerTiles[i].sprite.sprite.rect; spriteRect.x /= t.width; spriteRect.y /= t.height; //spriteRect.y = 1 - spriteRect.y; spriteRect.width /= t.width; spriteRect.height /= t.height; GUI.DrawTextureWithTexCoords(drawRect, t, spriteRect); cols++; } break; case "Players": for (int i = 0; i < playerTiles.Count; i++) { if (i != 0 && i % 6 == 0) { rows++; cols = 0; } Rect drawRect = new Rect(cols * tileCell, rows * tileCell, tileCell, tileCell); Texture t = playerTiles[i].sprite.sprite.texture; Rect spriteRect = playerTiles[i].sprite.sprite.rect; spriteRect.x /= t.width; spriteRect.y /= t.height; //spriteRect.y = 1 - spriteRect.y; spriteRect.width /= t.width; spriteRect.height /= t.height; GUI.DrawTextureWithTexCoords(drawRect, t, spriteRect); cols++; } break; } EditorGUILayout.LabelField("", GUILayout.Width(6 * tileCell), GUILayout.Height(rows * tileCell)); MarkDirtyRepaint(); LevelEditorWindow.RepaintWindow(); GUI.EndScrollView(); }
static void ShowEditorWindow() { LevelEditorWindow.OpenWindow(); }
public static void ShowWindow() { instance = EditorWindow.GetWindow <LevelEditorWindow>(); instance.titleContent = new GUIContent("Level Editor"); }
public LevelNode(Vector2 _position, LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView) { SetPosition(new Rect(_position, defaultNodeSize)); CreateSubGraphView(); //Scene Object field sceneField = new ObjectField { objectType = typeof(Scene), allowSceneObjects = false }; sceneField.RegisterValueChangedCallback(ValueTuple => { scene = ValueTuple.newValue; title = ValueTuple.newValue.name; scenAssetGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset)); scenePath = AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset); //SetScenePath(); }); mainContainer.Add(sceneField); //Async? Enum field asyncTypeField = new EnumField() { value = asyncType }; asyncTypeField.Init(asyncType); asyncTypeField.RegisterValueChangedCallback((value) => { //賦予新value asyncType = (AsyncLoadType)value.newValue; }); asyncTypeField.SetValueWithoutNotify(asyncType); mainContainer.Add(asyncTypeField); //Load Type Enum field loadTypeField = new EnumField() { value = loadType }; loadTypeField.Init(loadType); loadTypeField.RegisterValueChangedCallback((value) => { //賦予新value loadType = (SceneLoadType)value.newValue; }); loadTypeField.SetValueWithoutNotify(loadType); mainContainer.Add(loadTypeField); //新增節點須refresh RefreshExpandedState(); RefreshPorts(); }
void OnMapMouseMove(MouseMoveEvent evt) { if (!paint) { return; } if (selectedScriptableObject == null) { return; } if ((evt.localMousePosition.x < mapElement.contentRect.width - 15) && (evt.localMousePosition.y < mapElement.contentRect.height - 15)) { int mapCellStartX = Mathf.FloorToInt(evt.localMousePosition.x + mapScrollPosition.x) / cell; int mapCellStartY = Mathf.FloorToInt(evt.localMousePosition.y + mapScrollPosition.y) / cell; //Debug.Log(evt.localMousePosition + mapScrollPosition); //Debug.Log((evt.localMousePosition + mapScrollPosition) / cell); Vector2Int drawPos = new Vector2Int(mapCellStartX * cell, mapCellStartY * cell); int selectedLayer = 0; switch (layersPopupField.value) { case "Environment": selectedLayer = 0; break; case "StaticObjects": selectedLayer = 1; break; case "Enemies": selectedLayer = 2; break; case "Players": selectedLayer = 3; break; } //for (int i=0;i<level.layers.Length;i++) //{ Event e = Event.current; if (level.layers[selectedLayer].position == null || level.layers[selectedLayer].position.Count <= 0) { level.layers[selectedLayer].position.Add(drawPos); EditorUtility.SetDirty(level); level.layers[selectedLayer].objectOnPosition.Add(selectedScriptableObject); EditorUtility.SetDirty(level); } foreach (Vector2Int vi in level.layers[selectedLayer].position) { if (vi == drawPos) { int index = level.layers[selectedLayer].position.IndexOf(vi); if (e.modifiers == EventModifiers.Shift) { level.layers[selectedLayer].position.RemoveAt(index); EditorUtility.SetDirty(level); level.layers[selectedLayer].objectOnPosition.RemoveAt(index); EditorUtility.SetDirty(level); break; } else { level.layers[selectedLayer].position[index] = drawPos; EditorUtility.SetDirty(level); level.layers[selectedLayer].objectOnPosition[index] = (selectedScriptableObject); EditorUtility.SetDirty(level); break; } } else { level.layers[selectedLayer].position.Add(drawPos); EditorUtility.SetDirty(level); level.layers[selectedLayer].objectOnPosition.Add(selectedScriptableObject); EditorUtility.SetDirty(level); break; } } //if (level.layers[i] == layersPopupField.value) //{ // Drawable temp; // if (ml.drawRects.TryGetValue(drawPos, out temp)) // { // Event e = Event.current; // if (e.modifiers == EventModifiers.Shift) // { // ml.drawRects.Remove(drawPos); // } // else // { // if (!string.IsNullOrEmpty(selectedDrawable.assetPath)) // { // temp.assetPath = selectedDrawable.assetPath; // temp.texCoords = selectedDrawable.texCoords; // if (ml.drawRects[drawPos].Equals(temp)) // { // ml.drawRects.Remove(drawPos); // } // else // { // ml.drawRects[drawPos] = temp; // } // } // } // } // else // { // Event e = Event.current; // if (e.modifiers == EventModifiers.Shift) // { // } // else // { // if (!string.IsNullOrEmpty(selectedDrawable.assetPath)) // { // ml.drawRects.Add(drawPos, selectedDrawable); // } // } // } //} //} } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); MarkDirtyRepaint(); LevelEditorWindow.RepaintWindow(); }
public void Configure(LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView) { editorWindow = _editorWindow; graphView = _graphView; }
public LevelEditorWindowGUI(LevelEditorWindow ownerWindow, LevelEditorData _editor) { window = ownerWindow; editor = _editor; }
private void CheckInput(SceneView view) { Vector3 direction = Vector3.zero; if (Event.current.type == EventType.KeyDown) { switch (Event.current.keyCode) { case KeyCode.Q: LevelEditor.RotateTile(LevelEditor.Direction.Left); break; case KeyCode.E: LevelEditor.RotateTile(LevelEditor.Direction.Right); break; case KeyCode.W: case KeyCode.UpArrow: direction = new Vector3(0, 0, TileMovementOffset); LevelEditor.MoveSelectedObject(direction); return; case KeyCode.S: case KeyCode.DownArrow: direction = new Vector3(0, 0, -TileMovementOffset); LevelEditor.MoveSelectedObject(direction); return; case KeyCode.A: case KeyCode.LeftArrow: direction = new Vector3(-TileMovementOffset, 0, 0); LevelEditor.MoveSelectedObject(direction); return; case KeyCode.D: case KeyCode.RightArrow: direction = new Vector3(TileMovementOffset, 0, 0); LevelEditor.MoveSelectedObject(direction); return; case KeyCode.Return: EditorWindow.GetWindow <LevelEditorWindow>().PlaceTile(); break; case KeyCode.Backspace: LevelEditor.RemoveSelectedTile(); LevelEditorWindow.SelectLatestTileInList(); break; case KeyCode.K: EditorWindow.GetWindow <LevelEditorWindow>().SelectOtherTile(LevelEditorWindow.SelectTile.Previous); TryFocusScene(); break; case KeyCode.L: EditorWindow.GetWindow <LevelEditorWindow>().SelectOtherTile(LevelEditorWindow.SelectTile.Next); TryFocusScene(); break; } } }
private void mapOnGUI() { mapScrollPosition = EditorGUILayout.BeginScrollView(mapScrollPosition, true, true, GUILayout.Width(mapElement.contentRect.width), GUILayout.Width(mapElement.contentRect.height)); //if (textureObjectField.value != null) //{ // Texture imageToDraw = (Texture)textureObjectField.value; // Rect drawRect = new Rect(0, 0, imageToDraw.width, imageToDraw.height); // Rect destRect = // GUI.DrawTextureWithTexCoords(drawRect, imageToDraw, drawRect,true); //} //Rect sizeRect = new Rect(0, 0, rows * cell, cols * cell); EditorGUILayout.LabelField("", GUILayout.Width(cols * cell), GUILayout.Height(rows * cell)); for (int i = 0; i <= rows; i++) { EditorGUI.DrawRect(new Rect(0, i * cell, cols * cell, 2), Color.white); } for (int j = 0; j <= cols; j++) { EditorGUI.DrawRect(new Rect(j * cell, 0, 2, rows * cell), Color.white); } for (int layerindex = 0; layerindex < 4; layerindex++) { for (int i = 0; i < level.layers[layerindex].position.Count; i++) { Rect drawRect = new Rect(cols * tileCell, rows * tileCell, tileCell, tileCell); Texture t; Rect spriteRect; if (layerindex == 0) { Sprite s = ((EnvironmentObject)(level.layers[layerindex].objectOnPosition[i])).sprite.sprite; t = s.texture; spriteRect = s.rect; } else if (layerindex == 1) { Sprite s = ((StaticObject)(level.layers[layerindex].objectOnPosition[i])).sprite.sprite; t = s.texture; spriteRect = s.rect; } else if (layerindex == 2) { Sprite s = ((EnemyObject)(level.layers[layerindex].objectOnPosition[i])).sprite.sprite; t = s.texture; spriteRect = s.rect; } else if (layerindex == 3) { Sprite s = ((PlayerObject)(level.layers[layerindex].objectOnPosition[i])).sprite.sprite; t = s.texture; spriteRect = s.rect; } else { return; } spriteRect.x /= t.width; spriteRect.y /= t.height; spriteRect.y = 1 - spriteRect.y; spriteRect.width /= t.width; spriteRect.height /= t.height; GUI.DrawTextureWithTexCoords(drawRect, t, spriteRect); //GUI.DrawTextureWithTexCoords(drawRect, imageToDraw, drawRect, true); } } MarkDirtyRepaint(); LevelEditorWindow.RepaintWindow(); GUI.EndScrollView(); }
public static void OpenThisWindow(Level level) { LevelEditorWindow myWindow = EditorWindow.GetWindow(typeof(LevelEditorWindow)) as LevelEditorWindow; myWindow.Init(level); }
public LevelEditorWindowGUI(LevelEditorWindow ownerWindow, LevelEditorData _editor) { window = ownerWindow; editor = _editor; }