Browse Source

Fixed ObjectField() performance issues.

master
chrisgregan 10 years ago
parent
commit
eae9119db3
  1. 6
      Assets/Fungus/Dialog/Editor/ChooseEditor.cs
  2. 6
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  3. 17
      Assets/Fungus/Dialog/Scripts/Character.cs
  4. 16
      Assets/Fungus/Dialog/Scripts/ChooseDialog.cs
  5. 17
      Assets/Fungus/Dialog/Scripts/SayDialog.cs
  6. 11
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  7. BIN
      Assets/Shuttle/ShuttleGame.unity

6
Assets/Fungus/Dialog/Editor/ChooseEditor.cs

@ -39,11 +39,13 @@ namespace Fungus.Script
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
t.character);
t.character,
Character.activeCharacters);
ChooseDialog dialog = FungusCommandEditor.ObjectField<ChooseDialog>(new GUIContent("Choose Dialog", "Dialog to use when displaying choices"),
new GUIContent("<Default>"),
t.dialog);
t.dialog,
ChooseDialog.activeDialogs);
AudioClip voiceOverClip = EditorGUILayout.ObjectField(new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed"),
t.voiceOverClip,

6
Assets/Fungus/Dialog/Editor/SayEditor.cs

@ -79,11 +79,13 @@ namespace Fungus.Script
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
t.character);
t.character,
Character.activeCharacters);
SayDialog dialog = FungusCommandEditor.ObjectField<SayDialog>(new GUIContent("Say Dialog", "Dialog to use when displaying Say command story text"),
new GUIContent("<Default>"),
t.dialog);
t.dialog,
SayDialog.activeDialogs);
AudioClip voiceOverClip = EditorGUILayout.ObjectField(new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"),
t.voiceOverClip,

17
Assets/Fungus/Dialog/Scripts/Character.cs

@ -1,15 +1,32 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[ExecuteInEditMode]
public class Character : MonoBehaviour
{
public string characterName;
public Sprite characterImage;
public SayDialog.DialogSide dialogSide;
public Color characterColor;
static public List<Character> activeCharacters = new List<Character>();
void OnEnable()
{
if (!activeCharacters.Contains(this))
{
activeCharacters.Add(this);
}
}
void OnDisable()
{
activeCharacters.Remove(this);
}
}
}

16
Assets/Fungus/Dialog/Scripts/ChooseDialog.cs

@ -8,6 +8,7 @@ using System.Collections.Generic;
namespace Fungus.Script
{
[ExecuteInEditMode]
public class ChooseDialog : Dialog
{
public Slider slider;
@ -20,6 +21,21 @@ namespace Fungus.Script
public List<UnityEngine.UI.Button> optionButtons = new List<UnityEngine.UI.Button>();
static public List<ChooseDialog> activeDialogs = new List<ChooseDialog>();
void OnEnable()
{
if (!activeDialogs.Contains(this))
{
activeDialogs.Add(this);
}
}
void OnDisable()
{
activeDialogs.Remove(this);
}
public void Choose(string text, List<Option> options, float timeoutDuration, Action onTimeout)
{
Clear();

17
Assets/Fungus/Dialog/Scripts/SayDialog.cs

@ -2,14 +2,31 @@
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[ExecuteInEditMode]
public class SayDialog : Dialog
{
public Image continueImage;
static public List<SayDialog> activeDialogs = new List<SayDialog>();
void OnEnable()
{
if (!activeDialogs.Contains(this))
{
activeDialogs.Add(this);
}
}
void OnDisable()
{
activeDialogs.Remove(this);
}
public void Say(string text, Action onComplete)
{
Clear();

11
Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs

@ -170,18 +170,17 @@ namespace Fungus.Script
return copy as T;
}
static public T ObjectField<T>(GUIContent label, GUIContent nullLabel, T selectedObject) where T : MonoBehaviour
static public T ObjectField<T>(GUIContent label, GUIContent nullLabel, T selectedObject, List<T> objectList) where T : MonoBehaviour
{
List<GUIContent> objectNames = new List<GUIContent>();
int selectedIndex = 0;
objectNames.Add(nullLabel);
T[] objects = GameObject.FindObjectsOfType<T>();
for (int i = 0; i < objects.Length; ++i)
for (int i = 0; i < objectList.Count; ++i)
{
objectNames.Add(new GUIContent(objects[i].name));
objectNames.Add(new GUIContent(objectList[i].name));
if (selectedObject == objects[i])
if (selectedObject == objectList[i])
{
selectedIndex = i + 1;
}
@ -196,7 +195,7 @@ namespace Fungus.Script
}
else
{
result = objects[selectedIndex - 1];
result = objectList[selectedIndex - 1];
}
return result;

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save