Пример #1
0
        private void ActionInfoGUI()
        {
            if (m_SelectionState.Action == null)
            {
                return;
            }

            m_ScrollState.ElementInspectorScroll = GUILayout.BeginScrollView(m_ScrollState.ElementInspectorScroll, false, false);
            {
                RSValidationContext context = m_Context.WithTrigger(GetCurrentTrigger());
                RuleGUILayout.ActionData(m_TargetState.UndoTarget, m_SelectionState.Action, GetBaseFlags(), context);
            }
            GUILayout.EndScrollView();
        }
Пример #2
0
        private bool TryEdit(UnityEngine.Object inObject)
        {
            IRSRuleTableSource ruleTableSource;
            bool bFoundTable = RSEditorUtility.EditorPlugin.TryGetRuleTable(inObject, out ruleTableSource);

            if (!bFoundTable || ruleTableSource.TableData == null)
            {
                return(false);
            }

            m_TargetState.Select(inObject);

            m_SelectionState.ClearAll();
            m_SelectionState.Source = ruleTableSource;
            m_SelectionState.Table  = ruleTableSource.TableData;

            if (m_SelectionState.Table.Rules == null)
            {
                m_TargetState.UndoTarget.MarkDirty("Initialized Rules");
                m_SelectionState.Table.Rules = new RSRuleData[0];
            }

            bool bCleanUpChanged = TableUtils.CleanUp(m_SelectionState.Table);

            if (bCleanUpChanged)
            {
                m_TargetState.UndoTarget.MarkDirtyWithoutUndo("Cleaned up Rule Table data");
            }

            ConfigureRuleList(m_SelectionState.Table, ref m_RuleList);

            m_Context = new RSValidationContext(RSEditorUtility.EditorPlugin.Library);
            RegenContext(true);
            ScanForIssues();

            UnityEditor.Selection.activeObject = inObject;
            return(true);
        }
Пример #3
0
        static private EntityScopedIdentifier DoActionField(GUIContent inLabel, EntityScopedIdentifier inIdentifier, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EntityScopeData scope    = inIdentifier.Scope;
            int             actionId = inIdentifier.Id;

            using (new EditorGUILayout.VerticalScope())
            {
                scope = EntityScopeField(inLabel, scope, inFlags.ForMethodScope(), inContext);
                using (new EditorGUI.IndentLevelScope())
                {
                    switch (scope.Type)
                    {
                    case EntityScopeType.Global:
                        actionId = LibraryGUILayout.ActionSelectorGlobal(Content.ActionIdLabel, actionId, inContext.Library);
                        break;

                    case EntityScopeType.Null:
                        EditorGUILayout.HelpBox("Cannot perform action on null entity", MessageType.Error);
                        break;

                    case EntityScopeType.Invalid:
                        EditorGUILayout.HelpBox("Cannot perform action on missing entity", MessageType.Error);
                        break;

                    case EntityScopeType.Self:
                    {
                        if (inFlags.Has(RSValidationFlags.FilterSelection) && !scope.HasLinks() && inContext.Entity != null)
                        {
                            actionId = LibraryGUILayout.ActionSelector(Content.ActionIdLabel, actionId, inContext.Entity, inContext.Library);
                        }
                        else
                        {
                            actionId = LibraryGUILayout.ActionSelectorUnknown(Content.ActionIdLabel, actionId, inContext.Library);
                        }
                        break;
                    }

                    case EntityScopeType.ObjectById:
                    {
                        RSEntityId entityId = scope.IdArg;
                        IRSEntity  entity   = null;
                        if (inFlags.Has(RSValidationFlags.FilterSelection) && entityId != RSEntityId.Null && !scope.HasLinks() && inContext.Manager != null && (entity = inContext.Manager.Lookup.EntityWithId(entityId)) != null)
                        {
                            actionId = LibraryGUILayout.ActionSelector(Content.ActionIdLabel, actionId, entity, inContext.Library);
                        }
                        else
                        {
                            actionId = LibraryGUILayout.ActionSelectorUnknown(Content.ActionIdLabel, actionId, inContext.Library);
                        }
                        break;
                    }

                    default:
                        actionId = LibraryGUILayout.ActionSelectorUnknown(Content.ActionIdLabel, actionId, inContext.Library);
                        break;
                    }

                    if (actionId == 0)
                    {
                        EditorGUILayout.HelpBox("Cannot perform null action", MessageType.Error);
                    }
                }
            }

            return(new EntityScopedIdentifier(scope, actionId));
        }
Пример #4
0
 /// <summary>
 /// Renders a layout editor for a scoped action identifier.
 /// </summary>
 static public EntityScopedIdentifier ActionField(EntityScopedIdentifier inIdentifier, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoActionField(GUIContent.none, inIdentifier, inFlags, inContext));
     }
 }
Пример #5
0
        private void PerformTableSearch(TableParams inTableParams)
        {
            m_LineRefs.Clear();

            if (m_TableMgr == null)
            {
                Debug.LogError("No rule table manager found");
                return;
            }

            AbstractTableRefVisitor visitor = null;

            switch (inTableParams.Mode)
            {
            case TableMode.Action:
            {
                visitor = new TableUtils.ActionIdRefVisitor(inTableParams.ElementSearchId);
                break;
            }

            case TableMode.Query:
            {
                visitor = new TableUtils.QueryIdRefVisitor(inTableParams.ElementSearchId);
                break;
            }

            case TableMode.Trigger:
            {
                visitor = new TableUtils.TriggerIdRefVisitor(new RSTriggerId(inTableParams.ElementSearchId));
                break;
            }

            case TableMode.Entity:
            {
                visitor = new TableUtils.EntityIdRefVisitor(inTableParams.EntitySearch);
                break;
            }

            case TableMode.String:
            {
                visitor = new TableUtils.StringRefVisitor(inTableParams.StringSearch);
                break;
            }

            case TableMode.Issues:
            {
                var validationContext = new RSValidationContext(RSEditorUtility.EditorPlugin.Library);
                validationContext = validationContext.WithManager(m_EntityMgr);
                foreach (var table in m_TableMgr.AllTableSources())
                {
                    var validationState = RSValidator.Validate(table.TableData, validationContext);
                    if (validationState.IssueCount > 0)
                    {
                        m_LineRefs.Add(TableLineRef.FromTable(table).WithDescriptor("{0} errors, {1} warnings", validationState.ErrorCount, validationState.WarningCount));
                    }
                }
                break;
            }
            }

            if (visitor != null)
            {
                foreach (var table in m_TableMgr.AllTableSources())
                {
                    visitor.Visit(table);
                }
                m_LineRefs.AddRange(visitor.CollectedRefs);
            }
        }
Пример #6
0
        /// <summary>
        /// Renders editor for rule info. Does not include conditions or actions.
        /// </summary>
        static public void RuleData(UndoTarget inUndo, RSRuleData ioRule, RSRuleTableData ioTable, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            string preview = ioRule.GetPreviewString(null, inContext.Library);

            GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle);

            EditorGUILayout.Space();

            string newName = EditorGUILayout.TextField(Content.RuleNameLabel, ioRule.Name);

            if (newName != ioRule.Name)
            {
                inUndo.MarkDirty("Changed Rule Name");
                ioRule.Name = newName;
            }

            RSTriggerId newTriggerId;

            if (inFlags.Has(RSValidationFlags.FilterSelection) && inContext.Entity != null)
            {
                newTriggerId = LibraryGUILayout.TriggerSelector(Content.RuleTriggerLabel, ioRule.TriggerId, inContext.Entity, inContext.Library);
            }
            else
            {
                newTriggerId = LibraryGUILayout.TriggerSelector(Content.RuleTriggerLabel, ioRule.TriggerId, inContext.Library);
            }

            if (newTriggerId != ioRule.TriggerId)
            {
                inUndo.MarkDirty("Changed Rule Trigger", true);
                ioRule.TriggerId = newTriggerId;

                TableUtils.UpdateUniqueRuleTriggers(ioTable);
            }

            if (newTriggerId != RSTriggerId.Null)
            {
                RSTriggerInfo info = inContext.Library.GetTrigger(newTriggerId);
                if (info != null && info.ParameterType != null)
                {
                    using (new EditorGUI.IndentLevelScope())
                    {
                        EditorGUILayout.LabelField(Content.RuleParameterLabel, EditorGUIUtility.TrTextContent(info.ParameterType.ToStringWithoutDefault(), info.ParameterType.Tooltip));
                    }
                }
            }

            EditorGUILayout.Space();

            // Enabled
            bool bEnabled = EditorGUILayout.Toggle(Content.RuleEnabledLabel, ioRule.Enabled);

            if (bEnabled != ioRule.Enabled)
            {
                inUndo.MarkDirty("Changed Rule Enabled");
                ioRule.Enabled = bEnabled;
            }

            bool bOnlyOnce = EditorGUILayout.Toggle(Content.RuleOnlyOnceLabel, ioRule.OnlyOnce);

            if (bOnlyOnce != ioRule.OnlyOnce)
            {
                inUndo.MarkDirty("Changed Rule OnlyOnce");
                ioRule.OnlyOnce = bOnlyOnce;
            }

            bool bDontInterrupt = EditorGUILayout.Toggle(Content.RuleDontInterruptLabel, ioRule.DontInterrupt);

            if (bDontInterrupt != ioRule.DontInterrupt)
            {
                inUndo.MarkDirty("Changed Rule DontInterrupt");
                ioRule.DontInterrupt = bDontInterrupt;
            }

            EditorGUILayout.Space();

            string newGroup = EditorGUILayout.TextField(Content.RuleGroupLabel, ioRule.RoutineGroup);

            if (newGroup != ioRule.RoutineGroup)
            {
                inUndo.MarkDirty("Changed Rule Group");
                ioRule.RoutineGroup = newGroup;
            }
        }
Пример #7
0
 /// <summary>
 /// Renders a layout editor for a ResolvableValue.
 /// </summary>
 static public void ResolvableValueData(UndoTarget inUndo, GUIContent inLabel, RSResolvableValueData ioValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     DoResolvableValueData(inUndo, inLabel, ioValue, inExpectedType, inDefaultValue, inFlags, inContext);
 }
Пример #8
0
        /// <summary>
        /// Renders editor for Action info.
        /// </summary>
        static public void ActionData(UndoTarget inUndo, RSActionData ioAction, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            string preview = ioAction.GetPreviewString(inContext.Trigger, inContext.Library);

            GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle);

            EditorGUILayout.Space();

            // Enabled
            bool bEnabled = EditorGUILayout.Toggle("Enabled", ioAction.Enabled);

            if (bEnabled != ioAction.Enabled)
            {
                inUndo.MarkDirty("Changed Action Enabled");
                ioAction.Enabled = bEnabled;
            }

            EditorGUILayout.Space();

            using (new EditorGUI.DisabledGroupScope(!bEnabled))
            {
                EntityScopedIdentifier action     = ValueGUILayout.ActionField(EditorGUIUtility.TrTempContent("Action"), ioAction.Action, inFlags, inContext);
                RSActionInfo           actionInfo = inContext.Library.GetAction(action.Id);

                if (action != ioAction.Action)
                {
                    bool bChangedId = ioAction.Action.Id != action.Id;

                    inUndo.MarkDirty("Changed Action", true);
                    ioAction.Action = action;

                    if (bChangedId)
                    {
                        if (actionInfo != null)
                        {
                            actionInfo.PopulateDefaultArguments(ioAction);
                        }
                        else
                        {
                            ioAction.Arguments = null;
                        }
                    }
                }

                if (actionInfo != null && ioAction.Arguments != null && ioAction.Arguments.Length > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Arguments", RSGUIStyles.SubHeaderStyle);

                    for (int i = 0; i < ioAction.Arguments.Length; ++i)
                    {
                        ParameterData(inUndo, actionInfo.Parameters[i], ioAction.Arguments[i], inFlags, inContext);
                    }
                }
            }
        }
Пример #9
0
        static internal NamedItemList <ResolvableValueMode> GetResolvableValueModes(RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));
            bool bDisallowRegister    = inFlags.Has(RSValidationFlags.DisallowRegisters);

            if (bDisallowDirectValue)
            {
                if (bDisallowDirectValue)
                {
                    return(s_ResolvableValueModesNoValueOrRegister);
                }
                return(s_ResolvableValueModesNoRegister);
            }
            if (bDisallowRegister)
            {
                return(s_ResolvableValueModesNoRegister);
            }
            return(s_ResolvableValueModes);
        }
Пример #10
0
        static private NestedValue DoNestedValueField(GUIContent inLabel, NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EditorGUILayout.BeginVertical();
            ResolvableValueMode nextType = ListGUILayout.Popup(inLabel, inValue.Mode, RSEditorUtility.GetResolvableValueModes(inExpectedType, inFlags, inContext));

            RSValue value = inDefaultValue;
            EntityScopedIdentifier query    = new EntityScopedIdentifier(EntityScopeData.Self(), 0);
            RegisterIndex          register = RegisterIndex.Register0;

            using (new EditorGUI.IndentLevelScope())
            {
                switch (inValue.Mode)
                {
                case ResolvableValueMode.Argument:
                {
                    if (inContext.Trigger == null)
                    {
                        EditorGUILayout.HelpBox("No parameter available: No Trigger", MessageType.Error);
                    }
                    else if (inContext.Trigger.ParameterType == null)
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has no parameter", inContext.Trigger.Name), MessageType.Error);
                    }
                    else if (inExpectedType != null && !inContext.Trigger.ParameterType.Type.CanConvert(inExpectedType))
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has incompatible parameter type {1}, which cannot convert to {2}", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type, inExpectedType), MessageType.Error);
                    }
                    break;
                }

                case ResolvableValueMode.Value:
                {
                    if (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue))
                    {
                        EditorGUILayout.HelpBox("Cannot specify a value in this context", MessageType.Error);
                    }
                    else
                    {
                        value = RSValueField(EditorGUIUtility.TrTempContent(inExpectedType.FriendlyName), inValue.Value, inExpectedType, inFlags, inContext);
                    }
                    break;
                }

                case ResolvableValueMode.Query:
                {
                    query = ValueGUILayout.QueryField(RuleGUILayout.Content.ResolvableValueQueryLabel, inValue.Query, inExpectedType, inFlags.ForMethod(false), inContext);
                    break;
                }

                case ResolvableValueMode.Register:
                {
                    register = (RegisterIndex)EnumGUILayout.EnumField(RuleGUILayout.Content.ResolvableValueRegisterLabel, inValue.Register);
                    break;
                }
                }
            }

            EditorGUILayout.EndVertical();

            switch (nextType)
            {
            case ResolvableValueMode.Argument:
                return(NestedValue.FromArgument());

            case ResolvableValueMode.Query:
                return(NestedValue.FromQuery(query));

            case ResolvableValueMode.Register:
                return(NestedValue.FromRegister(register));

            case ResolvableValueMode.Value:
            default:
                return(NestedValue.FromValue(value));
            }
        }
Пример #11
0
 /// <summary>
 /// Renders a layout editor for a NestedValue.
 /// </summary>
 static public NestedValue NestedValueField(NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoNestedValueField(GUIContent.none, inValue, inExpectedType, inDefaultValue, inFlags, inContext));
     }
 }
Пример #12
0
 /// <summary>
 /// Renders a layout editor for a NestedValue.
 /// </summary>
 static public NestedValue NestedValueField(GUIContent inLabel, NestedValue inValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoNestedValueField(inLabel, inValue, inExpectedType, inDefaultValue, inFlags, inContext));
 }
Пример #13
0
        static private RSValue DoRSValueField(GUIContent inLabel, RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            Type systemType = inExpectedType.SystemType;

            if (systemType.IsEnum)
            {
                Enum currentValue;
                try
                {
                    currentValue = inValue.AsEnum();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    currentValue = inExpectedType.DefaultValue.AsEnum();
                }
                Enum nextValue = EnumGUILayout.EnumField(inLabel, currentValue);
                return(RSValue.FromEnum(nextValue));
            }

            if (inExpectedType == RSBuiltInTypes.Int)
            {
                int currentValue = inValue.AsInt;
                int nextValue    = EditorGUILayout.DelayedIntField(inLabel, currentValue);
                return(RSValue.FromInt(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Float)
            {
                float currentValue = inValue.AsFloat;
                float nextValue    = EditorGUILayout.DelayedFloatField(inLabel, currentValue);
                return(RSValue.FromFloat(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Bool)
            {
                bool currentValue = inValue.AsBool;
                bool nextValue    = EditorGUILayout.Toggle(inLabel, currentValue);
                return(RSValue.FromBool(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Color)
            {
                Color currentValue = inValue.AsColor;
                Color nextValue    = EditorGUILayout.ColorField(inLabel, currentValue);
                return(RSValue.FromColor(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.String)
            {
                string currentValue = inValue.AsString;
                string nextValue    = EditorGUILayout.TextField(inLabel, currentValue);
                return(RSValue.FromString(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector2)
            {
                Vector2 currentValue = inValue.AsVector2;
                Vector2 nextValue    = EditorGUILayout.Vector2Field(inLabel, currentValue);
                return(RSValue.FromVector2(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector3)
            {
                Vector3 currentValue = inValue.AsVector3;
                Vector3 nextValue    = EditorGUILayout.Vector3Field(inLabel, currentValue);
                return(RSValue.FromVector3(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Vector4)
            {
                Vector4 currentValue = inValue.AsVector4;
                Vector4 nextValue    = EditorGUILayout.Vector4Field(inLabel, currentValue);
                return(RSValue.FromVector4(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.Entity)
            {
                EntityScopeData currentValue = inValue.AsEntity;
                EntityScopeData nextValue    = EntityScopeField(inLabel, currentValue, inFlags.ForEntityValue(), inContext);
                return(RSValue.FromEntity(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.GroupId)
            {
                RSGroupId currentValue = inValue.AsGroupId;
                RSGroupId nextValue    = LibraryGUILayout.GroupSelector(inLabel, currentValue, inContext.Library);
                return(RSValue.FromGroupId(nextValue));
            }
            else if (inExpectedType == RSBuiltInTypes.TriggerId)
            {
                RSTriggerId currentValue        = inValue.AsTriggerId;
                RSTypeInfo  restrictTriggerType = inContext.Parameter?.TriggerParameterType;
                RSTriggerId nextValue;
                if (restrictTriggerType != null)
                {
                    nextValue = LibraryGUILayout.TriggerSelector(inLabel, currentValue, restrictTriggerType, inContext.Library);
                }
                else
                {
                    nextValue = LibraryGUILayout.TriggerSelector(inLabel, currentValue, inContext.Library);
                }
                return(RSValue.FromTriggerId(nextValue));
            }
            else
            {
                EditorGUILayout.HelpBox(string.Format("Unable to display editor for type {0}", inExpectedType), MessageType.Error);
            }

            return(inValue);
        }
Пример #14
0
 /// <summary>
 /// Renders a layout editor for an RSValue.
 /// </summary>
 static public RSValue RSValueField(GUIContent inLabel, RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoRSValueField(inLabel, inValue, inExpectedType, inFlags, inContext));
 }
Пример #15
0
        static private EntityScopeData DoEntityScopeField(GUIContent inLabel, EntityScopeData inScope, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            bool bForceFirst = inFlags.Has(RSValidationFlags.RequireSingleEntity);

            EditorGUILayout.BeginVertical();

            EntityScopeType currentType = inScope.Type;
            EntityScopeType nextType    = ListGUILayout.Popup(inLabel, inScope.Type, RSEditorUtility.s_EntityScopeTypes);

            RSEntityId    entityId      = RSEntityId.Null;
            RSGroupId     groupId       = RSGroupId.Null;
            string        search        = string.Empty;
            bool          useFirst      = bForceFirst;
            string        links         = string.Empty;
            bool          useFirstLinks = bForceFirst;
            RegisterIndex register      = RegisterIndex.Register0;

            using (new EditorGUI.IndentLevelScope())
            {
                switch (currentType)
                {
                case EntityScopeType.ObjectById:
                {
                    entityId = RSEditorUtility.EditorPlugin.EntityIdGUIField(Content.EntityScopeEntityIdLabel, inScope.IdArg, inContext.Manager);
                    if (entityId == RSEntityId.Null && !inFlags.Has(RSValidationFlags.AllowNullEntity))
                    {
                        EditorGUILayout.HelpBox("Null entity not allowed in this context", MessageType.Error);
                    }
                    break;
                }

                case EntityScopeType.ObjectInRegister:
                {
                    if (inFlags.Has(RSValidationFlags.DisallowRegisters))
                    {
                        EditorGUILayout.HelpBox("Local vars not allowed in this context", MessageType.Error);
                    }
                    else
                    {
                        register = inScope.RegisterArg;
                        register = (RegisterIndex)EnumGUILayout.EnumField(Content.EntityScopeRegisterLabel, register);
                    }
                    break;
                }

                case EntityScopeType.ObjectsWithGroup:
                {
                    groupId  = inScope.GroupArg;
                    useFirst = bForceFirst || inScope.UseFirst;

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        groupId = LibraryGUILayout.GroupSelector(Content.EntityScopeGroupLabel, groupId, inContext.Library);
                        using (new EditorGUI.DisabledScope(bForceFirst))
                            using (new RSGUI.LabelWidthScope(100))
                            {
                                useFirst = EditorGUILayout.Toggle(Content.EntityScopeGroupLabel, useFirst, GUILayout.Width(120));
                            }
                    }
                    break;
                }

                case EntityScopeType.ObjectsWithName:
                case EntityScopeType.ObjectsWithPrefab:
                {
                    search   = inScope.SearchArg;
                    useFirst = bForceFirst || inScope.UseFirst;

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        search = EditorGUILayout.TextField(currentType == EntityScopeType.ObjectsWithName ? Content.EntityScopeNameLabel : Content.EntityScopePrefabLabel, search);
                        using (new EditorGUI.DisabledScope(bForceFirst))
                            using (new RSGUI.LabelWidthScope(100))
                            {
                                useFirst = EditorGUILayout.Toggle(Content.EntityScopeUseFirstLabel, useFirst, GUILayout.Width(120));
                            }
                    }
                    break;
                }

                case EntityScopeType.Null:
                {
                    if (!inFlags.Has(RSValidationFlags.AllowNullEntity))
                    {
                        EditorGUILayout.HelpBox("Null entity not allowed in this context", MessageType.Error);
                    }
                    break;
                }

                case EntityScopeType.Invalid:
                {
                    EditorGUILayout.HelpBox("Missing entity not allowed", MessageType.Error);
                    break;
                }

                case EntityScopeType.Global:
                {
                    if (!inFlags.Has(RSValidationFlags.AllowGlobalEntity))
                    {
                        EditorGUILayout.HelpBox("Global entity not allowed in this context", MessageType.Error);
                    }
                    break;
                }

                case EntityScopeType.Argument:
                {
                    if (inContext.Trigger == null)
                    {
                        EditorGUILayout.HelpBox("No argument available: No Trigger", MessageType.Error);
                    }
                    else if (inContext.Trigger.ParameterType == null)
                    {
                        EditorGUILayout.HelpBox(string.Format("No argument available: Trigger {0} has no argument", inContext.Trigger.Name), MessageType.Error);
                    }
                    else if (!inContext.Trigger.ParameterType.Type.CanConvert(RSBuiltInTypes.Entity))
                    {
                        EditorGUILayout.HelpBox(string.Format("No argument available: Trigger {0} has incompatible argument type {1}, which cannot convert to an Entity", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type), MessageType.Error);
                    }
                    break;
                }
                }

                if (inScope.SupportsLinks())
                {
                    links         = inScope.LinksArg;
                    useFirstLinks = bForceFirst || inScope.UseFirstLink;

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        links = EditorGUILayout.TextField(Content.EntityScopeLinksLabel, links);
                        using (new EditorGUI.DisabledScope(bForceFirst))
                            using (new RSGUI.LabelWidthScope(100))
                            {
                                useFirstLinks = EditorGUILayout.Toggle(Content.EntityScopeUseFirstLinkLabel, useFirstLinks, GUILayout.Width(120));
                            }
                    }
                }
            }

            EditorGUILayout.EndVertical();

            switch (nextType)
            {
            case EntityScopeType.Self:
                return(EntityScopeData.Self().WithLinks(links, useFirstLinks));

            case EntityScopeType.Argument:
                return(EntityScopeData.Argument().WithLinks(links, useFirstLinks));

            case EntityScopeType.Global:
                return(EntityScopeData.Global());

            case EntityScopeType.ObjectById:
                return(EntityScopeData.Entity(entityId).WithLinks(links, useFirstLinks));

            case EntityScopeType.ObjectInRegister:
                return(EntityScopeData.Register(register).WithLinks(links, useFirstLinks));

            case EntityScopeType.ObjectsWithGroup:
                return(EntityScopeData.WithGroup(groupId, useFirst).WithLinks(links, useFirstLinks));

            case EntityScopeType.ObjectsWithName:
                return(EntityScopeData.WithName(search, useFirst).WithLinks(links, useFirstLinks));

            case EntityScopeType.ObjectsWithPrefab:
                return(EntityScopeData.WithPrefab(search, useFirst).WithLinks(links, useFirstLinks));

            case EntityScopeType.Invalid:
                return(EntityScopeData.Invalid());

            case EntityScopeType.Null:
            default:
                return(EntityScopeData.Null());
            }
        }
Пример #16
0
        /// <summary>
        /// Renders a layout editor for a NestedValue linked to a parameter.
        /// </summary>
        static public NestedValue NestedParameterField(RSParameterInfo inParameterInfo, NestedValue inValue, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            RSValidationFlags flags = inFlags.ForParameter(inParameterInfo);

            if (!inParameterInfo.NotNull)
            {
                flags |= RSValidationFlags.AllowNullEntity;
            }
            return(NestedValueField(EditorGUIUtility.TrTextContent(inParameterInfo.Name, inParameterInfo.Tooltip), inValue, inParameterInfo.Type, inParameterInfo.Default, flags, inContext.WithParameter(inParameterInfo)));
        }
Пример #17
0
 /// <summary>
 /// Renders a layout editor for an EntityScopeData.
 /// </summary>
 static public EntityScopeData EntityScopeField(GUIContent inLabel, EntityScopeData inScope, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoEntityScopeField(inLabel, inScope, inFlags, inContext));
 }
Пример #18
0
        /// <summary>
        /// Renders editor for condition info.
        /// </summary>
        static public void ConditionData(UndoTarget inUndo, RSConditionData ioCondition, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            string preview = ioCondition.GetPreviewString(inContext.Trigger, inContext.Library);

            GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle);

            EditorGUILayout.Space();

            // Enabled
            bool bEnabled = EditorGUILayout.Toggle(Content.ConditionEnabledLabel, ioCondition.Enabled);

            if (bEnabled != ioCondition.Enabled)
            {
                inUndo.MarkDirty("Changed Condition Enabled");
                ioCondition.Enabled = bEnabled;
            }

            EditorGUILayout.Space();

            using (new EditorGUI.DisabledGroupScope(!bEnabled))
            {
                RSTypeInfo prevQueryType = ioCondition.Query.TypeInfo(inContext.Trigger, inContext.Library);

                // Query
                ResolvableValueData(inUndo, Content.ConditionValueLabel, ioCondition.Query, null, inFlags.ForConditionQuery(), inContext);

                // comparison
                RSTypeInfo queryTypeInfo = ioCondition.Query.TypeInfo(inContext.Trigger, inContext.Library);
                if (ioCondition.Query.Mode != ResolvableValueMode.Value && queryTypeInfo != null)
                {
                    EditorGUILayout.Space();

                    RSEditorUtility.s_ComparisonOperators.Clear();
                    foreach (var comparison in queryTypeInfo.AllowedOperators())
                    {
                        RSEditorUtility.s_ComparisonOperators.Add(comparison, comparison.Name(), (int)comparison);
                    }

                    CompareOperator nextOperator = ioCondition.Operator;
                    if (!RSEditorUtility.s_ComparisonOperators.Contains(nextOperator))
                    {
                        nextOperator = RSEditorUtility.s_ComparisonOperators.Get(0);
                    }

                    nextOperator = ListGUILayout.Popup(Content.ConditionComparisonLabel, nextOperator, RSEditorUtility.s_ComparisonOperators);
                    if (nextOperator != ioCondition.Operator)
                    {
                        inUndo.MarkDirty("Changed Condition Operator");
                        ioCondition.Operator = nextOperator;
                    }

                    if (nextOperator.IsBinary())
                    {
                        EditorGUILayout.Space();

                        if (prevQueryType != queryTypeInfo)
                        {
                            inUndo.MarkDirty("Changed Condition Query Type");
                            RSResolvableValueData.SetAsValue(ref ioCondition.Target, queryTypeInfo.DefaultValue);
                        }

                        ResolvableValueData(inUndo, Content.ConditionTargetLabel, ioCondition.Target, queryTypeInfo, inFlags.ForConditionTarget(), inContext);
                    }
                    else
                    {
                        if (ioCondition.Target != null)
                        {
                            inUndo.MarkDirty("Removed Condition Comparison Target");
                            ioCondition.Target = null;
                        }
                    }

                    if (ioCondition.Query.IsMultiValue())
                    {
                        EditorGUILayout.Space();
                        Subset subset = (Subset)EditorGUILayout.EnumPopup(Content.ConditionSubsetLabel, ioCondition.MultiQuerySubset);
                        if (subset != ioCondition.MultiQuerySubset)
                        {
                            inUndo.MarkDirty("Changed Condition MultiQuerySubset");
                            ioCondition.MultiQuerySubset = subset;
                        }
                    }
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Renders a layout editor for a scoped query identifier.
 /// </summary>
 static public EntityScopedIdentifier QueryField(GUIContent inLabel, EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoQueryField(inLabel, inIdentifier, inExpectedType, inFlags, inContext));
 }
Пример #20
0
 /// <summary>
 /// Renders a layout editor for a ResolvableValue linked to a parameter.
 /// </summary>
 static public void ParameterData(UndoTarget inUndo, RSParameterInfo inParameterInfo, RSResolvableValueData ioValue, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     inFlags = inFlags.ForParameter(inParameterInfo);
     ResolvableValueData(inUndo, EditorGUIUtility.TrTextContent(inParameterInfo.Name, inParameterInfo.Tooltip), ioValue, inParameterInfo.Type, inParameterInfo.Default, inFlags, inContext.WithParameter(inParameterInfo));
 }
Пример #21
0
 /// <summary>
 /// Renders a layout editor for a scoped query identifier.
 /// </summary>
 static public EntityScopedIdentifier QueryField(EntityScopedIdentifier inIdentifier, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoQueryField(GUIContent.none, inIdentifier, inExpectedType, inFlags, inContext));
     }
 }
Пример #22
0
        static private void DoResolvableValueData(UndoTarget inUndo, GUIContent inLabel, RSResolvableValueData ioValue, RSTypeInfo inExpectedType, RSValue inDefaultValue, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            EditorGUILayout.BeginVertical();

            bool bDisallowDirectValue = (inExpectedType == null || inExpectedType == RSBuiltInTypes.Any || inFlags.Has(RSValidationFlags.DisallowDirectValue));

            ResolvableValueMode nextMode = ListGUILayout.Popup(inLabel, ioValue.Mode, RSEditorUtility.GetResolvableValueModes(inExpectedType, inFlags, inContext));

            if (nextMode != ioValue.Mode)
            {
                inUndo.MarkDirty("Changed Resolvable Value Mode");
                ioValue.Mode = nextMode;

                switch (nextMode)
                {
                case ResolvableValueMode.Argument:
                    RSResolvableValueData.SetAsArgument(ref ioValue);
                    break;

                case ResolvableValueMode.Query:
                    RSResolvableValueData.SetAsQuery(ref ioValue, new EntityScopedIdentifier(EntityScopeData.Self(), 0));
                    break;

                case ResolvableValueMode.Value:
                    RSResolvableValueData.SetAsValue(ref ioValue, inDefaultValue);
                    break;

                case ResolvableValueMode.Register:
                    RSResolvableValueData.SetAsRegister(ref ioValue, RegisterIndex.Register0);
                    break;
                }
            }

            using (new EditorGUI.IndentLevelScope())
            {
                switch (ioValue.Mode)
                {
                case ResolvableValueMode.Argument:
                {
                    if (inContext.Trigger == null)
                    {
                        EditorGUILayout.HelpBox("No parameter available: No Trigger", MessageType.Error);
                    }
                    else if (inContext.Trigger.ParameterType == null)
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has no parameter", inContext.Trigger.Name), MessageType.Error);
                    }
                    else if (inExpectedType != null && !inContext.Trigger.ParameterType.Type.CanConvert(inExpectedType))
                    {
                        EditorGUILayout.HelpBox(string.Format("No parameter available - Trigger {0} has incompatible parameter type {1}, which cannot convert to {2}", inContext.Trigger.Name, inContext.Trigger.ParameterType.Type, inExpectedType), MessageType.Error);
                    }
                    break;
                }

                case ResolvableValueMode.Value:
                {
                    if (bDisallowDirectValue)
                    {
                        EditorGUILayout.HelpBox("Cannot specify a value in this context", MessageType.Error);
                    }
                    else
                    {
                        RSValue nextValue = ValueGUILayout.RSValueField(EditorGUIUtility.TrTempContent(inExpectedType.FriendlyName), ioValue.Value, inExpectedType, inFlags, inContext);
                        if (nextValue != ioValue.Value)
                        {
                            inUndo.MarkDirty("Changed Resolvable Value Value");
                            ioValue.Value = nextValue;
                        }
                    }
                    break;
                }

                case ResolvableValueMode.Register:
                {
                    RegisterIndex nextRegister = (RegisterIndex)EnumGUILayout.EnumField(Content.ResolvableValueRegisterLabel, ioValue.Register);
                    if (nextRegister != ioValue.Register)
                    {
                        inUndo.MarkDirty("Changed Resolvable Value Register");
                        ioValue.Register = nextRegister;
                    }
                    break;
                }

                case ResolvableValueMode.Query:
                {
                    EntityScopedIdentifier query     = ValueGUILayout.QueryField(Content.ResolvableValueQueryLabel, ioValue.Query, inExpectedType, inFlags.ForMethod(true), inContext);
                    RSQueryInfo            queryInfo = inContext.Library.GetQuery(query.Id);
                    if (query != ioValue.Query)
                    {
                        bool bChangedId = query.Id != ioValue.Query.Id;
                        inUndo.MarkDirty("Changed Resolvable Value Query", true);
                        ioValue.Query = query;

                        if (bChangedId)
                        {
                            if (queryInfo == null)
                            {
                                ioValue.QueryArguments = null;
                            }
                            else
                            {
                                queryInfo.PopulateDefaultArguments(ioValue);
                            }
                        }
                    }

                    int currentArgsLength = 0;
                    if (ioValue.QueryArguments != null)
                    {
                        currentArgsLength = ioValue.QueryArguments.Length;
                    }
                    int desiredArgsLength = 0;
                    if (queryInfo != null && queryInfo.Parameters != null)
                    {
                        desiredArgsLength = queryInfo.Parameters.Length;
                    }

                    if (desiredArgsLength == 0 && ioValue.QueryArguments != null)
                    {
                        inUndo.MarkDirtyWithoutUndo("Resizing Arguments", true);
                        ioValue.QueryArguments = null;
                    }
                    else if (desiredArgsLength > 0 && currentArgsLength != desiredArgsLength)
                    {
                        inUndo.MarkDirtyWithoutUndo("Resizing Arguments", true);
                        queryInfo.PopulateDefaultArguments(ioValue, currentArgsLength);
                    }

                    if (ioValue.QueryArguments != null && ioValue.QueryArguments.Length > 0)
                    {
                        using (new EditorGUI.IndentLevelScope())
                        {
                            EditorGUILayout.Space();
                            EditorGUILayout.LabelField(Content.ResolvableValueQueryArgsLabel, RSGUIStyles.SubHeaderStyle);
                            for (int i = 0; i < ioValue.QueryArguments.Length && i < queryInfo.Parameters.Length; ++i)
                            {
                                NestedValue nextValue = ValueGUILayout.NestedParameterField(queryInfo.Parameters[i], ioValue.QueryArguments[i], inFlags, inContext);
                                if (nextValue != ioValue.QueryArguments[i])
                                {
                                    inUndo.MarkDirty("Changed Resolvable Value Query Argument");
                                    ioValue.QueryArguments[i] = nextValue;
                                }
                            }
                        }
                    }

                    break;
                }
                }
            }

            EditorGUILayout.EndVertical();
        }
Пример #23
0
 /// <summary>
 /// Renders a layout editor for an EntityScopeData.
 /// </summary>
 static public EntityScopeData EntityScopeField(EntityScopeData inScope, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoEntityScopeField(GUIContent.none, inScope, inFlags, inContext));
     }
 }
Пример #24
0
 /// <summary>
 /// Renders a layout editor for a scoped action identifier.
 /// </summary>
 static public EntityScopedIdentifier ActionField(GUIContent inLabel, EntityScopedIdentifier inIdentifier, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     return(DoActionField(inLabel, inIdentifier, inFlags, inContext));
 }
Пример #25
0
        private void RegenContext(bool inbForce = false)
        {
            if (!inbForce && Event.current.type != EventType.Layout)
            {
                return;
            }

            m_SelfUndoTarget = new UndoTarget(this, "RuleTableEditor");
            m_TargetState.Refresh();

            if (m_TargetState.SelectedObject == null)
            {
                m_TargetState.Clear();
                m_SelectionState.ClearAll();
                return;
            }

            if (m_TargetState.SelectedObject != null && m_SelectionState.Source == null)
            {
                IRSRuleTableSource tableSource;
                if (!RSEditorUtility.EditorPlugin.TryGetRuleTable(m_TargetState.SelectedObject, out tableSource))
                {
                    m_TargetState.Clear();
                    m_SelectionState.ClearAll();
                    return;
                }

                if (tableSource.TableData == null)
                {
                    m_TargetState.Clear();
                    m_SelectionState.ClearAll();
                    return;
                }

                m_SelectionState.Source = tableSource;
                m_SelectionState.Table  = tableSource.TableData;

                bool bCleanUpChanged = TableUtils.CleanUp(tableSource.TableData);
                if (bCleanUpChanged)
                {
                    m_TargetState.UndoTarget.MarkDirtyWithoutUndo("Cleaned up Rule Table data");
                }
            }

            m_SelectionState.Refresh();

            m_Context = m_Context.WithLibrary(RSEditorUtility.EditorPlugin.Library);

            IRSEntity entity = null;

            if (m_TargetState.SelectedObject)
            {
                RSEditorUtility.EditorPlugin.TryGetEntity(m_TargetState.SelectedObject, out entity);
            }

            m_Context = m_Context.WithEntity(entity);

            IRSEntityMgr manager = null;

            if (manager == null || m_TargetState.SelectedObject)
            {
                RSEditorUtility.EditorPlugin.TryGetEntityManager(m_TargetState.SelectedObject, out manager);
            }

            m_Context = m_Context.WithManager(manager);
        }