private void AddCondition(string description)
    {
        // If there isn't an AllConditions instance yet, put a message in the console and return.
        if (!AllConditions.Instance)
        {
            Debug.LogError("AllConditions has not been created yet.");
            return;
        }

        // Create a condition based on the description.
        Condition newCondition = ConditionEditor.CreateCondition(description);

        // The name is what is displayed by the asset so set that too.
        newCondition.name = description;

        // Record all operations on the newConditions so they can be undone.
        Undo.RecordObject(newCondition, "Created new Condition");

        // Attach the Condition to the AllConditions asset.
        AssetDatabase.AddObjectToAsset(newCondition, AllConditions.Instance);

        // Import the asset so it is recognised as a joined asset.
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newCondition));

        // Add the Condition to the AllConditions array.
        ArrayUtility.Add(ref AllConditions.Instance.conditions, newCondition);

        // Mark the AllConditions asset as dirty so the editor knows to save changes to it when a project save happens.
        EditorUtility.SetDirty(AllConditions.Instance);

        // Recreate the condition description array with the new added Condition.
        SetAllConditionDescriptions();
    }
    // Function to Add a Condition
    private void AddCondition(string description)
    {
        // If no AllConditions instance found
        if (!AllConditions.Instance)
        {
            // Display ErrorMessage
            Debug.Log("AllConditions has not been Created yet.");
            // Stop Function
            return;
        }

        // Otherwise: Create a Condition based on the Description
        Condition newCondition = ConditionEditor.CreateCondition(description);

        // Set the Name of the newCondition
        newCondition.name = description;
        // Record all Operations on newCondition (so they can be Undone)
        Undo.RecordObject(newCondition, "Created new Condition");
        // Attach newCondition to AllCondition Asset
        AssetDatabase.AddObjectToAsset(newCondition, AllConditions.Instance);
        // Import Asset to recognize Joined Asset
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newCondition));
        // Add newCondition to AllConditions Array
        ArrayUtility.Add(ref AllConditions.Instance.conditions, newCondition);
        // Mark AllConditions as Dirty (Editor knows to SaveChanges on ProjectSave)
        EditorUtility.SetDirty(AllConditions.Instance);
        // Recreate ConditionDescriptions Array with newCondition
        SetAllConditionDescriptions();
    }
    public static ConditionCollection CreateConditionCollection(string description, string elementDescription)
    {
        ConditionCollection newConditionCollection = CreateInstance <ConditionCollection>();

        // Give it a default description.
        newConditionCollection.conditionCollectionDescription = description;

        // Give it a single default Condition.
        newConditionCollection.conditionCollection    = new Condition[1];
        newConditionCollection.conditionCollection[0] = ConditionEditor.CreateCondition(elementDescription, typeof(DefaultCondition));
        return(newConditionCollection);
    }
Example #4
0
    private void AddCondition(string description)
    {
        if (!checkInstance())
        {
            return;
        }

        Condition newCondition = ConditionEditor.CreateCondition(description);

        newCondition.name = description;

        Undo.RecordObject(newCondition, "Created new Condition");             //zapisuje operacje wykonywane na instancji zeby dzialalo undo (?)
        AssetDatabase.AddObjectToAsset(newCondition, AllConditions.Instance); //podpiecie pod asset
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newCondition));  //trzeba wykonac import zeby asset byl
        ArrayUtility.Add(ref AllConditions.Instance.conditions, newCondition);
        EditorUtility.SetDirty(AllConditions.Instance);
        CreateConditionsDescriptionsArray();
    }
    //
    private void AddCondition(string description)
    {
        if (!AllConditions.Instance)
        {
            Debug.LogError("AllConditions has not been created yet.");
            return;
        }

        Condition newCondition = ConditionEditor.CreateCondition(description);

        newCondition.name = description;

        Undo.RecordObject(newCondition, "Created new Condition");

        AssetDatabase.AddObjectToAsset(newCondition, AllConditions.Instance);
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newCondition));

        ArrayUtility.Add(ref AllConditions.Instance.conditions, newCondition);

        EditorUtility.SetDirty(AllConditions.Instance);

        SetAllConditionDescriptions();
    }
Example #6
0
    private void AddCondition(string description)
    {
        // If there isn't an AllConditions instance yet, put a message in the console and return.
        if (!AllConditions.Instance)
        {
            Debug.LogError("AllConditions has not been created yet.");
            return;
        }

        // Create a condition based on the description.
        Condition newCondition = ConditionEditor.CreateCondition(description);

        // The name is what is displayed by the asset so set that too.
        newCondition.name = description;

        ScriptableObjectUtility.AddScriptableObject(AllConditions.Instance,
                                                    ref newCondition,
                                                    ref AllConditions.Instance.conditions,
                                                    "Created new Condition"
                                                    );

        // Recreate the condition description array with the new added Condition.
        SetAllConditionDescriptions();
    }
Example #7
0
                public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
                {
                    Condition currentConditional = (Condition)obj;
                    Condition conditional        = ConditionEditor.DrawAddConditionalDropDown("Condition", currentConditional);

                    if (conditional != currentConditional)
                    {
                        dataChanged = true;
                    }

                    int origIndent = EditorGUI.indentLevel;

                    EditorGUI.indentLevel++;

                    if (conditional != null)
                    {
                        conditional = ConditionEditor.DrawToggle(conditional, ref dataChanged);

                        bool editorCollapsed = !EditorGUILayout.Foldout(!conditional._editorCollapsed, "Properties");

                        if (editorCollapsed != conditional._editorCollapsed)
                        {
                            conditional._editorCollapsed = editorCollapsed;
                            dataChanged = true;
                        }

                        if (!editorCollapsed)
                        {
                            EditorGUI.indentLevel++;

                            ConditionSaveDataEnum saveDataEnum = conditional as ConditionSaveDataEnum;

                            if (saveDataEnum != null)
                            {
                                //Save data type (only show enum properties)
                                saveDataEnum._saveData = SerializationEditorGUILayout.ObjectField(saveDataEnum._saveData, GUIContent.none, ref dataChanged);

                                //Possible values
                                Type enumType = saveDataEnum.GetEnumType();

                                if (enumType != null)
                                {
                                    Enum enm = (Enum)Enum.ToObject(enumType, saveDataEnum._value);
                                    EditorGUI.BeginChangeCheck();
                                    saveDataEnum._enumValue = EditorGUILayout.EnumPopup("Value", enm);
                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        saveDataEnum._value = Convert.ToInt32(saveDataEnum._enumValue);
                                        dataChanged         = true;
                                    }
                                }
                                else
                                {
                                    saveDataEnum._enumValue = null;
                                    saveDataEnum._value     = -1;
                                }
                            }
                            else
                            {
                                conditional = (Condition)SerializationEditorGUILayout.RenderObjectMemebers(conditional, conditional.GetType(), ref dataChanged);
                            }

                            EditorGUI.indentLevel--;
                        }
                    }

                    EditorGUI.indentLevel = origIndent;

                    return(conditional);
                }
    // 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;
        }
    }
Example #9
0
 public abstract void AddToEditor(ConditionEditor editor);