Browse Source

Fungus prefabs now spawn in centre of scene view

master
chrisgregan 10 years ago
parent
commit
671acdc600
  1. 12
      Assets/Fungus/Camera/Editor/CameraMenuItems.cs
  2. 25
      Assets/Fungus/Dialog/Editor/DialogMenuItems.cs
  3. 28
      Assets/Fungus/FungusScript/Editor/FungusScriptMenuItems.cs
  4. 21
      Assets/Fungus/Sprite/Editor/SpriteMenuItems.cs

12
Assets/Fungus/Camera/Editor/CameraMenuItems.cs

@ -10,17 +10,7 @@ namespace Fungus
[MenuItem("GameObject/Fungus/Camera/View")]
static void CreateBackground()
{
InstantiatePrefab("View");
}
static void InstantiatePrefab(string prefabName)
{
GameObject prefab = Resources.LoadAssetAtPath("Assets/Fungus/Camera/Prefabs/" + prefabName + ".prefab", typeof(GameObject)) as GameObject;
if (prefab != null)
{
GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
go.name = prefabName;
}
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Camera/Prefabs/View.prefab");
}
}

25
Assets/Fungus/Dialog/Editor/DialogMenuItems.cs

@ -8,46 +8,29 @@ namespace Fungus
public class DialogMenuItems
{
[MenuItem("GameObject/Fungus/Dialog/Background")]
static void CreateBackground()
{
InstantiatePrefab("Background");
}
[MenuItem("GameObject/Fungus/Dialog/Character")]
static void CreateCharacter()
{
InstantiatePrefab("Character");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/Character.prefab");
}
[MenuItem("GameObject/Fungus/Dialog/NarratorDialog")]
static void CreateNarratorDialog()
{
InstantiatePrefab("NarratorDialog");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/NarratorDialog.prefab");
}
[MenuItem("GameObject/Fungus/Dialog/SayDialog")]
static void CreateSayDialog()
{
InstantiatePrefab("SayDialog");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/SayDialog.prefab");
}
[MenuItem("GameObject/Fungus/Dialog/ChooseDialog")]
static void CreateChooseDialog()
{
InstantiatePrefab("ChooseDialog");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/ChooseDialog.prefab");
}
static void InstantiatePrefab(string prefabName)
{
GameObject prefab = Resources.LoadAssetAtPath("Assets/Fungus/Dialog/Prefabs/" + prefabName + ".prefab", typeof(GameObject)) as GameObject;
if (prefab != null)
{
GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
go.name = prefabName;
}
}
}
}

28
Assets/Fungus/FungusScript/Editor/FungusScriptMenuItems.cs

@ -1,5 +1,6 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
namespace Fungus
@ -20,6 +21,33 @@ namespace Fungus
fungusScript.scrollPos = Vector2.zero;
Undo.RegisterCreatedObjectUndo(newFungusScriptGO, "Create Fungus Script");
}
public static GameObject SpawnPrefab(string prefabFile)
{
string prefabName = Path.GetFileNameWithoutExtension(prefabFile);
// This will only succeed if Fungus is located in the root folder of the project
GameObject prefab = Resources.LoadAssetAtPath(prefabFile, typeof(GameObject)) as GameObject;
if (prefab == null)
{
return null;
}
GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
go.name = prefabName;
Camera sceneCam = SceneView.currentDrawingSceneView.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;
}
}
}

21
Assets/Fungus/Sprite/Editor/SpriteMenuItems.cs

@ -10,39 +10,26 @@ namespace Fungus
[MenuItem("GameObject/Fungus/Sprite/ClickableSprite")]
static void CreateClickableSprite()
{
InstantiatePrefab("ClickableSprite");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/ClickableSprite.prefab");
}
[MenuItem("GameObject/Fungus/Sprite/DraggableSprite")]
static void CreateDraggableSprite()
{
InstantiatePrefab("DraggableSprite");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/DraggableSprite.prefab");
}
[MenuItem("GameObject/Fungus/Sprite/DragTargetSprite")]
static void CreateDragTargetSprite()
{
InstantiatePrefab("DragTargetSprite");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/DragTargetSprite.prefab");
}
[MenuItem("GameObject/Fungus/Sprite/ParallaxSprite")]
static void CreateParallaxSprite()
{
InstantiatePrefab("ParallaxSprite");
FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/ParallaxSprite.prefab");
}
static void InstantiatePrefab(string prefabName)
{
GameObject prefab = Resources.LoadAssetAtPath("Assets/Fungus/Sprite/Prefabs/" + prefabName + ".prefab", typeof(GameObject)) as GameObject;
if (prefab != null)
{
GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
go.name = prefabName;
Undo.RegisterCreatedObjectUndo(go, go.name);
Selection.activeGameObject = go;
}
}
}
}
Loading…
Cancel
Save