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. 30
      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")] [MenuItem("GameObject/Fungus/Camera/View")]
static void CreateBackground() static void CreateBackground()
{ {
InstantiatePrefab("View"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Camera/Prefabs/View.prefab");
}
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;
}
} }
} }

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

@ -8,46 +8,29 @@ namespace Fungus
public class DialogMenuItems public class DialogMenuItems
{ {
[MenuItem("GameObject/Fungus/Dialog/Background")]
static void CreateBackground()
{
InstantiatePrefab("Background");
}
[MenuItem("GameObject/Fungus/Dialog/Character")] [MenuItem("GameObject/Fungus/Dialog/Character")]
static void CreateCharacter() static void CreateCharacter()
{ {
InstantiatePrefab("Character"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/Character.prefab");
} }
[MenuItem("GameObject/Fungus/Dialog/NarratorDialog")] [MenuItem("GameObject/Fungus/Dialog/NarratorDialog")]
static void CreateNarratorDialog() static void CreateNarratorDialog()
{ {
InstantiatePrefab("NarratorDialog"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/NarratorDialog.prefab");
} }
[MenuItem("GameObject/Fungus/Dialog/SayDialog")] [MenuItem("GameObject/Fungus/Dialog/SayDialog")]
static void CreateSayDialog() static void CreateSayDialog()
{ {
InstantiatePrefab("SayDialog"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Dialog/Prefabs/SayDialog.prefab");
} }
[MenuItem("GameObject/Fungus/Dialog/ChooseDialog")] [MenuItem("GameObject/Fungus/Dialog/ChooseDialog")]
static void CreateChooseDialog() 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;
}
}
} }
} }

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

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using System.IO;
using System.Collections; using System.Collections;
namespace Fungus namespace Fungus
@ -19,7 +20,34 @@ namespace Fungus
fungusScript.selectedSequence = sequence; fungusScript.selectedSequence = sequence;
fungusScript.scrollPos = Vector2.zero; fungusScript.scrollPos = Vector2.zero;
Undo.RegisterCreatedObjectUndo(newFungusScriptGO, "Create Fungus Script"); 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")] [MenuItem("GameObject/Fungus/Sprite/ClickableSprite")]
static void CreateClickableSprite() static void CreateClickableSprite()
{ {
InstantiatePrefab("ClickableSprite"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/ClickableSprite.prefab");
} }
[MenuItem("GameObject/Fungus/Sprite/DraggableSprite")] [MenuItem("GameObject/Fungus/Sprite/DraggableSprite")]
static void CreateDraggableSprite() static void CreateDraggableSprite()
{ {
InstantiatePrefab("DraggableSprite"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/DraggableSprite.prefab");
} }
[MenuItem("GameObject/Fungus/Sprite/DragTargetSprite")] [MenuItem("GameObject/Fungus/Sprite/DragTargetSprite")]
static void CreateDragTargetSprite() static void CreateDragTargetSprite()
{ {
InstantiatePrefab("DragTargetSprite"); FungusScriptMenuItems.SpawnPrefab("Assets/Fungus/Sprite/Prefabs/DragTargetSprite.prefab");
} }
[MenuItem("GameObject/Fungus/Sprite/ParallaxSprite")] [MenuItem("GameObject/Fungus/Sprite/ParallaxSprite")]
static void CreateParallaxSprite() 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