示例#1
0
            private GridData CreateNewGridData(string name)
            {
                GridData newGridData = GridData.CreateInstance <GridData>();
                string   path        = EditorUtil.ROOT_FOLDER + "/Resources/" + GridManager.GRID_DATA_RESOURCES_PATH + "/" + name + ".asset";

                path = AssetDatabase.GenerateUniqueAssetPath(path);
                AssetDatabase.CreateAsset(newGridData, path);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                return(newGridData);
            }
示例#2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Create Grid Data", EditorStyles.boldLabel);

            worldSize.Clamp(Vector2Int.one, Vector2Int.one * int.MaxValue);
            cellSize.Clamp(Vector2.one, Vector2.one * float.MaxValue);

            worldSize = EditorGUILayout.Vector2IntField("World Size", worldSize);
            cellSize  = EditorGUILayout.Vector2Field("Cell Size", cellSize);

            EditorGUI.BeginDisabledGroup(world.GridDataReference != null);
            if (GUILayout.Button("Create"))
            {
                var gridDataInstance = GridData.CreateInstance(worldSize, cellSize);
                AssetDatabase.CreateAsset(gridDataInstance, $"Assets/GridData-{Guid.NewGuid()}.asset");

                world.LoadGridData(gridDataInstance);
                EditorUtility.SetDirty(world);
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(world.GridDataReference == null);
            if (GUILayout.Button("Load dimensions"))
            {
                worldSize = world.GridDataReference.WorldSize;
                cellSize  = world.GridDataReference.CellSize;
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Re-Initialize"))
            {
                world.GridDataReference.Initialize(world.GridDataReference.WorldSize, world.GridDataReference.CellSize);
                EditorUtility.SetDirty(world.GridDataReference);
                AssetDatabase.SaveAssets();
            }

            if (GUILayout.Button("Force Lazy-Load Data"))
            {
                world.GridDataReference.LazyLoadData();
                EditorUtility.SetDirty(world.GridDataReference);
                AssetDatabase.SaveAssets();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();
        }