An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEditor;
namespace Fungus.EditorUtils
{
public class FlowchartMenuItems
{
[MenuItem("Tools/Fungus/Create/Flowchart", false, 0)]
static void CreateFlowchart()
{
GameObject go = SpawnPrefab("Flowchart");
go.transform.position = Vector3.zero;
// This is the latest version of Flowchart, so no need to update.
var flowchart = go.GetComponent<Flowchart>();
if (flowchart != null)
{
flowchart.Version = FungusConstants.CurrentVersion;
}
// Only the first created Flowchart in the scene should have a default GameStarted block
if (GameObject.FindObjectsOfType<Flowchart>().Length > 1)
{
var block = go.GetComponent<Block>();
GameObject.DestroyImmediate(block._EventHandler);
block._EventHandler = null;
}
}
[MenuItem("Tools/Fungus/Create/Fungus Logo", false, 1000)]
static void CreateFungusLogo()
{
SpawnPrefab("FungusLogo");
}
[MenuItem("Tools/Fungus/Utilities/Export Fungus Package")]
static void ExportFungusPackageFull()
{
ExportFungusPackage( new string[] {"Assets/Fungus", "Assets/FungusExamples" });
}
[MenuItem("Tools/Fungus/Utilities/Export Fungus Package - Lite")]
static void ExportFungusPackageLite()
{
ExportFungusPackage(new string[] { "Assets/Fungus" });
}
static void ExportFungusPackage(string[] folders)
{
string path = EditorUtility.SaveFilePanel("Export Fungus Package", "", "Fungus", "unitypackage");
if (path.Length == 0)
{
return;
}
AssetDatabase.ExportPackage(folders, path, ExportPackageOptions.Recurse);
}
public static GameObject SpawnPrefab(string prefabName)
{
GameObject prefab = Resources.Load<GameObject>("Prefabs/" + prefabName);
if (prefab == null)
{
return null;
}
GameObject go = GameObject.Instantiate(prefab) as GameObject;
go.name = prefab.name;
SceneView view = SceneView.lastActiveSceneView;
if (view != null)
{
Camera sceneCam = view.camera;
Vector3 pos = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
pos.z = 0f;
go.transform.position = pos;
}
Selection.activeGameObject = go;
Undo.RegisterCreatedObjectUndo(go, "Create Object");
return go;
}
}
}