protected override void DrawReaction() { serializedObject.Update(); CheckAndCreateSubEditors(interactableCallback.conditionCollections); for (int i = 0; i < subEditors.Length; i++) { subEditors[i].OnInspectorGUI(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add Collection", GUILayout.Width(collectionButtonWidth))) { ConditionCollection newCollection = ConditionCollectionEditor.CreateConditionCollection(); collectionsProperty.AddToObjectArray(newCollection); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(defaultReactionCollectionProperty); serializedObject.ApplyModifiedProperties(); }
public static ConditionReactionCollection CreateConditionReactionCollection() { ConditionReactionCollection newConditionReactionCollection = CreateInstance <ConditionReactionCollection>(); newConditionReactionCollection.conditionCollection = ConditionCollectionEditor.CreateConditionCollection("Default_Condtion_Collection", "Default_Condition"); newConditionReactionCollection.reactionCollection = ReactionCollectionEditor.CreateReactionCollection("Default_Reaction_Collection", "Default_Reaction"); return(newConditionReactionCollection); }
private void OnEnable() { currentObject = (ConditionReactionCollection)target; conditionCollectionProperty = serializedObject.FindProperty("conditionCollection"); reactionCollectionProperty = serializedObject.FindProperty("reactionCollection"); if (currentObject.conditionCollection == null) { ConditionReactionCollection newConditionReactionCollection = CreateConditionReactionCollection(); currentObject.conditionCollection = newConditionReactionCollection.conditionCollection; currentObject.reactionCollection = newConditionReactionCollection.reactionCollection; } conditionCollectionEditor = CreateEditor(currentObject.conditionCollection) as ConditionCollectionEditor; reactionCollectionEditor = CreateEditor(currentObject.reactionCollection) as ReactionCollectionEditor; }
// DraggingAndDropping 用来对拖拽进来的 ScriptableObject(Script) 进行实例化 // 并将其添加到相应的 Collection 中 private static void DraggingAndDropping <T>(Rect dropArea, T editor) where T : Editor { // Cache the current event. Event currentEvent = Event.current; Type editorType = editor.GetType(); // Default type is Condition Type allowedScriptType = CheckEditorTargetType(editor); // If the drop area doesn't contain the mouse then return. if (!dropArea.Contains(currentEvent.mousePosition)) { return; } switch (currentEvent.type) { case EventType.DragUpdated: DragAndDrop.visualMode = IsDragValid(allowedScriptType) ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; currentEvent.Use(); break; // If the mouse was dragging something and has released... case EventType.DragPerform: DragAndDrop.AcceptDrag(); // Go through all the objects that were being dragged... for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) { MonoScript script = DragAndDrop.objectReferences[i] as MonoScript; // ... then find the type of that Reaction... Type scriptType = script.GetClass(); // ... and create a Reaction of that type and add it to the array. if (editorType.Equals(typeof(ReactionCollectionEditor))) { Reaction newReaction = ReactionEditor.CreateReaction("Default_Reaction", scriptType); ReactionCollectionEditor castedEditor = (ReactionCollectionEditor)(Editor)editor; castedEditor.reactionCollectionProperty.AddElementToProperty(newReaction); } else if (editorType.Equals(typeof(ConditionCollectionEditor))) { Condition newCondition = ConditionEditor.CreateCondition("Default_Condition", scriptType); ConditionCollectionEditor castedEditor = (ConditionCollectionEditor)(Editor)editor; castedEditor.conditionCollectionProperty.AddElementToProperty(newCondition); } else if (editorType.Equals(typeof(AllConditionEditor))) { Condition newCondition = ConditionEditor.CreateCondition("Default_Condition", scriptType); AllConditionEditor castedEditor = (AllConditionEditor)(Editor)editor; castedEditor.allConditionProperty.AddElementToProperty(newCondition); } } // Make sure the event isn't used by anything else. currentEvent.Use(); break; } }
void SubEditorSetup(ConditionCollectionEditor editor) { editor.collectionsProperty = collectionsProperty; }