public static ReactionCollection CreateReactionCollection(string description, string elementDescription) { ReactionCollection newReactionCollection = CreateInstance <ReactionCollection>(); newReactionCollection.reactionCollectionDescription = description; newReactionCollection.reactionCollection = new Reaction[1]; newReactionCollection.reactionCollection[0] = ReactionEditor.CreateReaction(elementDescription, typeof(DefaultReaction)); return(newReactionCollection); }
// 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; } }