Exemplo n.º 1
0
    private static void DraggingAndDropping(Rect dropArea, ReactionCollectionEditor editor)
    {
        Event currentEvent = Event.current;

        if (!dropArea.Contains(currentEvent.mousePosition))
        {
            return;
        }
        switch (currentEvent.type)
        {
        case EventType.DragUpdated:
            DragAndDrop.visualMode = IsDragValid() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
            currentEvent.Use();
            break;

        case EventType.DragPerform:

            DragAndDrop.AcceptDrag();

            for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
            {
                MonoScript script       = DragAndDrop.objectReferences[i] as MonoScript;
                Type       reactionType = script.GetClass();
                Reaction   newReaction  = ReactionEditor.CreateReaction(reactionType);
                editor.reactionsProperty.AddToObjectArray(newReaction);
            }
            currentEvent.Use();
            break;
        }
    }
    // tutaj mamy
    // ca³¹ te funkcjê mo¿na sobie wyci¹æ i u¿ywaæ osobno w innych projektach
    // bardzo przydatne do u¿ywania drag&drop w unity
    private static void DraggingAndDropping(Rect dropArea, ReactionCollectionEditor editor)
    {
        Event currentEvent = Event.current; // cashing current event in unity

        // event class records whats going on in unity
        // current event is what the mouse and keyborad are currently doing
        //

        if (!dropArea.Contains(currentEvent.mousePosition))  // obszar, który jest mierzony na ekranie,
        // jezeli to nie zawiera kursora myszki to nie chcemy w tej funkcji nic robic i wychodzimy
        {
            return;
        }

        switch (currentEvent.type)  //
        {
        case EventType.DragUpdated: // to sie odpala kiedy juz wczesniej na cos kliknalem w projekcie w trakcie dzialania
            // i aktualnie to trzymam i przesuwam, to bedzie pierwsza rzecz ktora sie stanie kiedy myszka wejdzie w nasz obszar
            // i teraz musimy zdecydowac jezeli myszka sie znajduje nad obszarem czy to co trzymamy jest mozliwe do upuszczenia
            // w tym miejscu

            DragAndDrop.visualMode = IsDragValid() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
            currentEvent.Use();
            // set the visual mode wheter or not the drag is valid

            break;

        case EventType.DragPerform:     // kiedy przycisk myszki zostaje zwolniony i chcemy upuscic to co trzymalismy

            DragAndDrop.AcceptDrag();   // musimy zaakceptowac ten event
            // to sie moze stac tylko wtedy kiedy wykonal sie updateddrag i nasz visual mode is linked
            // (jeszcze raz)
            // jezeli wiemy ze mozemy to zaakceptowac to teraz chcemy przejsc przez cala petle
            // obiektow ktore sa przeci¹gane i dla kazdego chcemy to
            // rzucic jako monoscript, monoscript to typ z assetow ktory jest utrzymywany dla zwyklych skryptow
            // bo kiedy tworzymy c# skrypt to tworzymy monobehaviour czy cos takiego, ale one wszystkie naleza do assetow
            // a assety do ktorych te skrypty naleza to wlasnie monoscript

            for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
            {
                MonoScript script = DragAndDrop.objectReferences[i] as MonoScript;

                Type reactionType = script.GetClass();                              // potem znajdujemy typ, ten typ bedzie tym cokolwiek ten skrypt przechowuje

                Reaction newReaction = ReactionEditor.CreateReaction(reactionType); // jezeli mamy juz przypisany skrypt
                // to teraz chcemy stworzyc reakcje tego typu
                editor.reactionsProperty.AddToObjectArray(newReaction);
                // dodajemy do wyswietlania to co wlasnie stworzylismy
            }

            currentEvent.Use();     // no i to

            break;
        }
    }
Exemplo n.º 3
0
    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 static void DraggingAndDropping(Rect dropArea, ReactionCollectionEditor editor)
    {
        // Cache the current event.
        Event currentEvent = Event.current;

        // If the drop area doesn't contain the mouse then return.
        if (!dropArea.Contains(currentEvent.mousePosition))
        {
            return;
        }

        switch (currentEvent.type)
        {
        // If the mouse is dragging something...
        case EventType.DragUpdated:

            // ... change whether or not the drag *can* be performed by changing the visual mode of the cursor based on the IsDragValid function.
            DragAndDrop.visualMode = IsDragValid() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;

            // Make sure the event isn't used by anything else.
            currentEvent.Use();

            break;

        // If the mouse was dragging something and has released...
        case EventType.DragPerform:

            // ... accept the drag event.
            DragAndDrop.AcceptDrag();

            // Go through all the objects that were being dragged...
            for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
            {
                // ... and find the script asset that was being dragged...
                MonoScript script = DragAndDrop.objectReferences[i] as MonoScript;

                // ... then find the type of that Reaction...
                Type reactionType = script.GetClass();

                // ... and create a Reaction of that type and add it to the array.
                Reaction newReaction = ReactionEditor.CreateReaction(reactionType);
                editor.reactionsProperty.AddToObjectArray(newReaction);
            }

            // Make sure the event isn't used by anything else.
            currentEvent.Use();

            break;
        }
    }
Exemplo n.º 5
0
    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;
    }
    // Function when Reaction is Dropped on Drag Area
    private static void DraggingAndDropping(Rect dropArea, ReactionCollectionEditor editor)
    {
        // Cache Current Event
        Event currentEvent = Event.current;

        // If the Mouse is Not in DropArea
        if (!dropArea.Contains(currentEvent.mousePosition))
        {
            // End this Function
            return;
        }

        // Switch on the CurrentEventType
        switch (currentEvent.type)
        {
        // If Mouse IS dragging Something
        case EventType.DragUpdated:
            // Display if Drag is Valid (based on IsDragValid-Function)
            DragAndDrop.visualMode = IsDragValid() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
            // Check if Event is Not used Elsewhere
            currentEvent.Use();
            //Break out of Switch
            break;

        // If Mouse WAS Dragging Something
        case EventType.DragPerform:
            // Accept Drag Event
            DragAndDrop.AcceptDrag();
            // Go through all Objects being Dragged
            for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
            {
                // Find ScriptAsset being Dragged
                MonoScript script = DragAndDrop.objectReferences[i] as MonoScript;
                // Find the Reaction Type on that Script
                Type reactionType = script.GetClass();
                // Create Reaction of that Type
                Reaction newReaction = ReactionEditor.CreateReaction(reactionType);
                // Add the newReaction to ReactionCollectionArray
                editor.reactionProperty.AddToObjectArray(newReaction);
            }

            // Check if Envent is Not used Elsewhere
            currentEvent.Use();
            // Break out of Switch
            break;
        }
    }
    private static void DraggingAndDropping(Rect dropArea, ReactionCollectionEditor editor)
    {
        Event currentEvent = Event.current; //Caching the current event (what the mouse/keyboard is currently doing)

        if (!dropArea.Contains(currentEvent.mousePosition))
        {
            return;                 //If the box doesn't contain any mouse interaction, then dont do anything
        }
        switch (currentEvent.type)  //Switch case
        {
        case EventType.DragUpdated: //Already clicked on something in the editor and it is now dragging it on the drop area

            //Is the drag valid?
            DragAndDrop.visualMode = IsDragValid() ?
                                     DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; //If the drag is valid, then visual mode is link, otherwise it is rejected
            currentEvent.Use();                                                                   //Use the event

            break;

        case EventType.DragPerform:     //The mouse button has been released, and now the component we have released it is trying to do something

            DragAndDrop.AcceptDrag();   //Accept the release (it works only if the visual mode is link)

            //Loop through all the objects that have been dragged
            for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
            {
                //And cast them as a monoscript
                MonoScript script = DragAndDrop.objectReferences[i] as MonoScript;

                //Looks for the type of the monoscript class (reaction type, since the drag and drop only accepts reactions)
                Type reactionType = script.GetClass();

                Reaction newReaction = ReactionEditor.CreateReaction(reactionType);      //Creates a new reaction of that type
                editor.reactionsProperty.AddToObjectArray(newReaction);
            }

            currentEvent.Use();

            break;
        }
    }
    // 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;
        }
    }