Browse Source

Spawn Object can use variables

master
chrisgregan 9 years ago
parent
commit
d6f71ab4e5
  1. 65
      Assets/Fungus/Flowchart/Scripts/Commands/SpawnObject.cs
  2. 34
      Assets/UpdatePropTest.unity

65
Assets/Fungus/Flowchart/Scripts/Commands/SpawnObject.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
namespace Fungus
@ -10,54 +11,92 @@ namespace Fungus
"Spawn Object",
"Spawns a new object based on a reference to a scene or prefab game object.")]
[AddComponentMenu("")]
public class SpawnObject : Command
public class SpawnObject : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("sourceObject")] public GameObject sourceObjectOLD;
[HideInInspector] [FormerlySerializedAs("parentTransform")] public Transform parentTransformOLD;
[HideInInspector] [FormerlySerializedAs("spawnPosition")] public Vector3 spawnPositionOLD;
[HideInInspector] [FormerlySerializedAs("spawnRotation")] public Vector3 spawnRotationOLD;
#endregion
[Tooltip("Game object to copy when spawning. Can be a scene object or a prefab.")]
public GameObject sourceObject;
public GameObjectData _sourceObject;
[Tooltip("Transform to use for position of newly spawned object.")]
public Transform parentTransform;
public TransformData _parentTransform;
[Tooltip("Local position of newly spawned object.")]
public Vector3 spawnPosition;
public Vector3Data _spawnPosition;
[Tooltip("Local rotation of newly spawned object.")]
public Vector3 spawnRotation;
public Vector3Data _spawnRotation;
public override void OnEnter()
{
if (sourceObject == null)
if (_sourceObject.Value == null)
{
Continue();
return;
}
GameObject newObject = GameObject.Instantiate(sourceObject);
if (parentTransform != null)
GameObject newObject = GameObject.Instantiate(_sourceObject.Value);
if (_parentTransform.Value != null)
{
newObject.transform.parent = parentTransform;
newObject.transform.parent = _parentTransform.Value;
}
newObject.transform.localPosition = spawnPosition;
newObject.transform.localRotation = Quaternion.Euler(spawnRotation);
newObject.transform.localPosition = _spawnPosition.Value;
newObject.transform.localRotation = Quaternion.Euler(_spawnRotation.Value);
Continue();
}
public override string GetSummary()
{
if (sourceObject == null)
if (_sourceObject.Value == null)
{
return "Error: No source GameObject specified";
}
return sourceObject.name;
return _sourceObject.Value.name;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public virtual void OnBeforeSerialize()
{}
public virtual void OnAfterDeserialize()
{
if (sourceObjectOLD != null)
{
_sourceObject.Value = sourceObjectOLD;
sourceObjectOLD = null;
}
if (parentTransformOLD != null)
{
_parentTransform.Value = parentTransformOLD;
parentTransformOLD = null;
}
if (spawnPositionOLD != default(Vector3))
{
_spawnPosition.Value = spawnPositionOLD;
spawnPositionOLD = default(Vector3);
}
if (spawnRotationOLD != default(Vector3))
{
_spawnRotation.Value = spawnRotationOLD;
spawnRotationOLD = default(Vector3);
}
}
}
}

34
Assets/UpdatePropTest.unity

@ -309,6 +309,7 @@ GameObject:
- 114: {fileID: 979963255}
- 114: {fileID: 979963254}
- 114: {fileID: 979963253}
- 114: {fileID: 979963256}
m_Layer: 0
m_Name: Flowchart
m_TagString: Untagged
@ -342,7 +343,7 @@ MonoBehaviour:
height: 859
selectedBlock: {fileID: 979963241}
selectedCommands:
- {fileID: 979963253}
- {fileID: 979963256}
variables:
- {fileID: 979963244}
- {fileID: 979963252}
@ -412,6 +413,7 @@ MonoBehaviour:
- {fileID: 979963251}
- {fileID: 979963254}
- {fileID: 979963253}
- {fileID: 979963256}
--- !u!114 &979963242
MonoBehaviour:
m_ObjectHideFlags: 2
@ -673,6 +675,36 @@ MonoBehaviour:
stringRef: {fileID: 0}
stringVal:
loadingImage: {fileID: 0}
--- !u!114 &979963256
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 979963238}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb3e86f556e074b84af1cc7eb8f8e5e7, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 12
errorMessage:
indentLevel: 0
sourceObjectOLD: {fileID: 0}
parentTransformOLD: {fileID: 0}
spawnPositionOLD: {x: 0, y: 0, z: 0}
spawnRotationOLD: {x: 0, y: 0, z: 0}
_sourceObject:
gameObjectRef: {fileID: 0}
gameObjectVal: {fileID: 1197120973}
_parentTransform:
transformRef: {fileID: 0}
transformVal: {fileID: 837453088}
_spawnPosition:
vector3Ref: {fileID: 0}
vector3Val: {x: 5, y: 2, z: 1}
_spawnRotation:
vector3Ref: {fileID: 0}
vector3Val: {x: 3, y: 2, z: 4}
--- !u!1 &1197120973
GameObject:
m_ObjectHideFlags: 0

Loading…
Cancel
Save