Browse Source

Added reorderable list of global and local variables

master
chrisgregan 10 years ago
parent
commit
40537cb019
  1. 84
      Assets/Fungus/Editor/SequenceControllerEditor.cs
  2. 32
      Assets/Fungus/Scripts/Variables.cs
  3. BIN
      Assets/Fungus/Tests/Sequence/SequenceTest.unity
  4. 5
      Assets/Fungus/Thirdparty.meta
  5. 5
      Assets/Fungus/Thirdparty/Reorderable List Field.meta
  6. 5
      Assets/Fungus/Thirdparty/Reorderable List Field/Editor.meta
  7. BIN
      Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.dll
  8. 7
      Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.dll.meta
  9. 1277
      Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.xml
  10. 4
      Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.xml.meta
  11. 26
      Assets/Fungus/Thirdparty/Reorderable List Field/LICENSE.txt
  12. 4
      Assets/Fungus/Thirdparty/Reorderable List Field/LICENSE.txt.meta
  13. 141
      Assets/Fungus/Thirdparty/Reorderable List Field/README.txt
  14. 4
      Assets/Fungus/Thirdparty/Reorderable List Field/README.txt.meta
  15. 19
      Assets/Fungus/VisualScripting/SequenceController.cs

84
Assets/Fungus/Editor/SequenceControllerEditor.cs

@ -3,34 +3,67 @@ using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Fungus;
using Rotorz.ReorderableList;
using System.Linq;
[CustomPropertyDrawer (typeof(SequenceController.Variable))]
public class VariableDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty keyProp = property.FindPropertyRelative("key");
SerializedProperty typeProp = property.FindPropertyRelative("type");
// Draw the text field control GUI.
EditorGUI.BeginChangeCheck();
Rect keyRect = position;
keyRect.width *= 0.5f;
Rect typeRect = position;
typeRect.x += keyRect.width;
typeRect.width -= keyRect.width;
string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue);
int selectedEnum = (int)(SequenceController.VariableType)EditorGUI.EnumPopup(typeRect, (SequenceController.VariableType)typeProp.enumValueIndex);
if (EditorGUI.EndChangeCheck ())
{
char[] arr = keyValue.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray();
keyValue = new string(arr);
keyProp.stringValue = keyValue;
typeProp.enumValueIndex = selectedEnum;
}
}
}
[CustomEditor (typeof(SequenceController))]
public class SequenceControllerEditor : Editor
{
SerializedProperty globalVariablesProperty;
SerializedProperty localVariablesProperty;
void OnEnable()
{
globalVariablesProperty = serializedObject.FindProperty("globalVariables");
localVariablesProperty = serializedObject.FindProperty("localVariables");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
SequenceController t = target as SequenceController;
GUIContent stepTimeLabel = new GUIContent("Step Time", "Minimum time to execute each step");
t.stepTime = EditorGUILayout.FloatField(stepTimeLabel, t.stepTime);
GUIContent startSequenceLabel = new GUIContent("Start Sequence", "Sequence to be executed when controller starts.");
t.startSequence = SequenceEditor.SequenceField(startSequenceLabel, t, t.startSequence);
if (t.startSequence == null)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
}
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Open Fungus Editor"))
{
EditorWindow.GetWindow(typeof(FungusEditorWindow), false, "Fungus Editor");
}
if (GUILayout.Button("New Sequence"))
{
GameObject go = new GameObject("Sequence");
@ -42,8 +75,29 @@ public class SequenceControllerEditor : Editor
Undo.RegisterCreatedObjectUndo(go, "Sequence");
Selection.activeGameObject = go;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUIContent stepTimeLabel = new GUIContent("Step Time", "Minimum time to execute each step");
t.stepTime = EditorGUILayout.FloatField(stepTimeLabel, t.stepTime);
GUIContent startSequenceLabel = new GUIContent("Start Sequence", "Sequence to be executed when controller starts.");
t.startSequence = SequenceEditor.SequenceField(startSequenceLabel, t, t.startSequence);
if (t.startSequence == null)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
}
ReorderableListGUI.Title("Local Variables");
ReorderableListGUI.ListField(localVariablesProperty);
ReorderableListGUI.Title("Global Variables");
ReorderableListGUI.ListField(globalVariablesProperty);
serializedObject.ApplyModifiedProperties();
}
}

32
Assets/Fungus/Scripts/Variables.cs

@ -178,6 +178,14 @@ namespace Fungus
*/
public static void SetFloat(string key, float value)
{
if (stringDict.ContainsKey(key) ||
intDict.ContainsKey(key) ||
boolDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, integer or boolean variable");
return;
}
floatDict[key] = value;
}
@ -186,6 +194,14 @@ namespace Fungus
*/
public static void SetInteger(string key, int value)
{
if (stringDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
boolDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, float or boolean variable");
return;
}
intDict[key] = value;
}
@ -194,6 +210,14 @@ namespace Fungus
*/
public static void SetBoolean(string key, bool value)
{
if (stringDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
intDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, float or integer variable");
return;
}
boolDict[key] = value;
}
@ -202,6 +226,14 @@ namespace Fungus
*/
public static void SetString(string key, string value)
{
if (boolDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
intDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a boolean, float or integer variable");
return;
}
stringDict[key] = value;
}

BIN
Assets/Fungus/Tests/Sequence/SequenceTest.unity

Binary file not shown.

5
Assets/Fungus/Thirdparty.meta

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 480b070201a224941aa71ed609c4a6b6
folderAsset: yes
DefaultImporter:
userData:

5
Assets/Fungus/Thirdparty/Reorderable List Field.meta vendored

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 97161408484da49bc8a4fb5f4b4c2f5a
folderAsset: yes
DefaultImporter:
userData:

5
Assets/Fungus/Thirdparty/Reorderable List Field/Editor.meta vendored

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 1351e3cf05fcef04cbafc172b277cd32
folderAsset: yes
DefaultImporter:
userData:

BIN
Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.dll vendored

Binary file not shown.

7
Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.dll.meta vendored

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 21d076cb9a4ec214a8cb820e69657bc3
MonoAssemblyImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
userData:

1277
Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.xml vendored

File diff suppressed because it is too large Load Diff

4
Assets/Fungus/Thirdparty/Reorderable List Field/Editor/Editor.ReorderableList.xml.meta vendored

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 087430efbff5ee54a8c8273aee1508fc
TextScriptImporter:
userData:

26
Assets/Fungus/Thirdparty/Reorderable List Field/LICENSE.txt vendored

@ -0,0 +1,26 @@
Copyright (c) 2013, Rotorz Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

4
Assets/Fungus/Thirdparty/Reorderable List Field/LICENSE.txt.meta vendored

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 8fc66c8c3ee484548a40e9b4cb50f206
TextScriptImporter:
userData:

141
Assets/Fungus/Thirdparty/Reorderable List Field/README.txt vendored

@ -0,0 +1,141 @@
README
======
List control for Unity allowing editor developers to add reorderable list controls to
their GUIs. Supports generic lists and serialized property arrays, though additional
collection types can be supported by implementing `Rotorz.ReorderableList.IReorderableListAdaptor`.
Use of this source code is governed by a BSD-style license that can be found in
the LICENSE file. DO NOT contribute to this project unless you accept the terms of the
contribution agreement.
![screenshot](https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity/raw/master/screenshot.png)
Features
--------
- Drag and drop reordering!
- Easily customized using flags.
- Adaptors for `IList<T>` and `SerializedProperty`.
- Subscribe to add/remove item events.
- Supports mixed item heights.
- Disable drag and/or removal on per-item basis.
- Styles can be overriden on per-list basis if desired.
- Subclass list control to override context menu.
- User guide (Asset Path/Support/User Guide.pdf).
- API reference documentation (Asset Path/Support/API Reference.chm).
Installing scripts
------------------
This control can be added to your project by importing the Unity package which
contains a compiled class library (DLL). This can be used by C# and UnityScript
developers.
[Download RotorzReorderableList_v0.2.4 Package (requires Unity 4.2.1+)](<https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity/downloads/RotorzReorderableList_v0.2.4.unitypackage>)
If you would prefer to use the non-compiled source code version in your project,
copy the contents of this repository somewhere into your project.
**Note to UnityScript (*.js) developers:**
UnityScript will not work with the source code version of this project unless
the contents of this repository is placed at the path "Assets/Plugins/ReorderableList"
due to compilation ordering.
Example 1: Serialized array of strings (C#)
-------------------------------------------
:::csharp
SerializedProperty _wishlistProperty;
SerializedProperty _pointsProperty;
void OnEnable() {
_wishlistProperty = serializedObject.FindProperty("wishlist");
_pointsProperty = serializedObject.FindProperty("points");
}
public override void OnInspectorGUI() {
serializedObject.Update();
ReorderableListGUI.Title("Wishlist");
ReorderableListGUI.ListField(_wishlistProperty);
ReorderableListGUI.Title("Points");
ReorderableListGUI.ListField(_pointsProperty, ReorderableListFlags.ShowIndices);
serializedObject.ApplyModifiedProperties();
}
Example 2: List of strings (UnityScript)
----------------------------------------
:::javascript
var yourList:List.<String> = new List.<String>();
function OnGUI() {
ReorderableListGUI.ListField(yourList, CustomListItem, DrawEmpty);
}
function CustomListItem(position:Rect, itemValue:String):String {
// Text fields do not like null values!
if (itemValue == null)
itemValue = '';
return EditorGUI.TextField(position, itemValue);
}
function DrawEmpty() {
GUILayout.Label('No items in list.', EditorStyles.miniLabel);
}
Refer to API reference for further examples!
Submission to the Unity Asset Store
-----------------------------------
If you wish to include this asset as part of a package for the asset store, please
include the latest package version as-is to avoid conflict issues in user projects.
It is important that license and documentation files are included and remain intact.
**To include a modified version within your package:**
- Ensure that license and documentation files are included and remain intact. It should
be clear that these relate to the reorderable list field library.
- Copyright and license information must remain intact in source files.
- Change the namespace `Rotorz.ReorderableList` to something unique and DO NOT use the
name "Rotorz". For example, `YourName.ReorderableList` or `YourName.Internal.ReorderableList`.
- Place files somewhere within your own asset folder to avoid causing conflicts with
other assets which make use of this project.
Useful links
------------
- [Rotorz Website](<http://rotorz.com>)
Contribution Agreement
----------------------
This project is licensed under the BSD license (see LICENSE). To be in the best
position to enforce these licenses the copyright status of this project needs to
be as simple as possible. To achieve this the following terms and conditions
must be met:
- All contributed content (including but not limited to source code, text,
image, videos, bug reports, suggestions, ideas, etc.) must be the
contributors own work.
- The contributor disclaims all copyright and accepts that their contributed
content will be released to the [public domain](<http://en.wikipedia.org/wiki/Public_domain>).
- The act of submitting a contribution indicates that the contributor agrees
with this agreement. This includes (but is not limited to) pull requests, issues,
tickets, e-mails, newsgroups, blogs, forums, etc.
### Disclaimer
External content linked in the above text are for convienence purposes only and
do not contribute to the agreement in any way. Linked content should be digested
under the readers discretion.

4
Assets/Fungus/Thirdparty/Reorderable List Field/README.txt.meta vendored

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: d5735c08f13f43a44be11da81110e424
TextScriptImporter:
userData:

19
Assets/Fungus/VisualScripting/SequenceController.cs

@ -4,6 +4,7 @@ using UnityEditor;
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Fungus;
public class SequenceController : MonoBehaviour
@ -15,6 +16,24 @@ public class SequenceController : MonoBehaviour
[System.NonSerialized]
public Sequence activeSequence;
public enum VariableType
{
String,
Integer,
Float,
Boolean
};
[Serializable]
public class Variable
{
public string key;
public VariableType type;
}
public List<Variable> localVariables = new List<Variable>();
public List<Variable> globalVariables = new List<Variable>();
public void Execute()
{
if (startSequence == null)

Loading…
Cancel
Save