desktop-maesty/steve
7 years ago
9 changed files with 173 additions and 120 deletions
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b99cf5f1ea08b914c94ee372bc4d76a7 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,125 @@
|
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
using UnityEditor; |
||||
using System.Linq; |
||||
|
||||
namespace Fungus.EditorUtils |
||||
{ |
||||
public class VariableSelectPopupWindowContent : BasePopupWindowContent |
||||
{ |
||||
static readonly int POPUP_WIDTH = 200, POPUP_HEIGHT = 200; |
||||
static List<System.Type> types; |
||||
|
||||
static void CacheVariableTypes() |
||||
{ |
||||
var derivedType = typeof(Variable); |
||||
types = EditorExtensions.FindDerivedTypes(derivedType) |
||||
.Where(x => !x.IsAbstract && derivedType.IsAssignableFrom(x)) |
||||
.ToList(); |
||||
} |
||||
|
||||
[UnityEditor.Callbacks.DidReloadScripts] |
||||
private static void OnScriptsReloaded() |
||||
{ |
||||
CacheVariableTypes(); |
||||
} |
||||
|
||||
protected override void PrepareAllItems() |
||||
{ |
||||
if(types == null || types.Count == 0) |
||||
{ |
||||
CacheVariableTypes(); |
||||
} |
||||
|
||||
int i = 0; |
||||
foreach (var item in types) |
||||
{ |
||||
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(item); |
||||
if (variableInfo != null) |
||||
{ |
||||
allItems.Add(new FilteredListItem(i, (variableInfo.Category.Length > 0 ? variableInfo.Category + CATEGORY_CHAR : "") + variableInfo.VariableType)); |
||||
} |
||||
|
||||
i++; |
||||
} |
||||
} |
||||
|
||||
protected override void SelectByOrigIndex(int index) |
||||
{ |
||||
AddVariable(types[index]); |
||||
} |
||||
|
||||
static public void DoAddVariable(Rect position, string currentHandlerName, Flowchart flowchart) |
||||
{ |
||||
curFlowchart = flowchart; |
||||
//new method |
||||
VariableSelectPopupWindowContent win = new VariableSelectPopupWindowContent(currentHandlerName, POPUP_WIDTH, POPUP_HEIGHT); |
||||
PopupWindow.Show(position, win); |
||||
|
||||
//old method |
||||
DoOlderMenu(flowchart); |
||||
} |
||||
|
||||
static protected void DoOlderMenu(Flowchart flowchart) |
||||
{ |
||||
GenericMenu menu = new GenericMenu(); |
||||
|
||||
// Add variable types without a category |
||||
foreach (var type in types) |
||||
{ |
||||
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type); |
||||
if (variableInfo == null || |
||||
variableInfo.Category != "") |
||||
{ |
||||
continue; |
||||
} |
||||
|
||||
GUIContent typeName = new GUIContent(variableInfo.VariableType); |
||||
|
||||
menu.AddItem(typeName, false, AddVariable, type); |
||||
} |
||||
|
||||
// Add types with a category |
||||
foreach (var type in types) |
||||
{ |
||||
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type); |
||||
if (variableInfo == null || |
||||
variableInfo.Category == "") |
||||
{ |
||||
continue; |
||||
} |
||||
|
||||
GUIContent typeName = new GUIContent(variableInfo.Category + CATEGORY_CHAR + variableInfo.VariableType); |
||||
|
||||
menu.AddItem(typeName, false, AddVariable, type); |
||||
} |
||||
|
||||
menu.ShowAsContext(); |
||||
} |
||||
|
||||
private static Flowchart curFlowchart; |
||||
|
||||
public VariableSelectPopupWindowContent(string currentHandlerName, int width, int height) |
||||
: base(currentHandlerName, width, height) |
||||
{ |
||||
} |
||||
|
||||
protected static void AddVariable(object obj) |
||||
{ |
||||
System.Type t = obj as System.Type; |
||||
if (t == null) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
Undo.RecordObject(curFlowchart, "Add Variable"); |
||||
Variable newVariable = curFlowchart.gameObject.AddComponent(t) as Variable; |
||||
newVariable.Key = curFlowchart.GetUniqueVariableKey(""); |
||||
curFlowchart.Variables.Add(newVariable); |
||||
|
||||
// Because this is an async call, we need to force prefab instances to record changes |
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(curFlowchart); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 933b6fc31e5eac04ea3b2a1fa9a3b418 |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue