Esempio n. 1
0
 public void Clear()
 {
     StringSearch    = string.Empty;
     EntityIdSearch  = 0;
     EntityRefSearch = RSEntityId.Null;
     RuleTableSearch = null;
 }
Esempio n. 2
0
        public RSEntityId ComponentGUIField(Rect inPosition, GUIContent inLabel, RSEntityId inValue, IRSEntityMgr inManager, System.Type inRequiredType)
        {
            int currentId = (int)inValue;
            int nextId    = EditorGUI.DelayedIntField(inPosition, inLabel, currentId);

            return(new RSEntityId(nextId));
        }
Esempio n. 3
0
        public RSEntityId ComponentGUIField(GUIContent inLabel, RSEntityId inValue, IRSEntityMgr inManager, System.Type inRequiredType, params GUILayoutOption[] inOptions)
        {
            int currentId = (int)inValue;
            int nextId    = EditorGUILayout.DelayedIntField(inLabel, currentId, inOptions);

            return(new RSEntityId(nextId));
        }
Esempio n. 4
0
        public RSEntityId EntityIdGUIField(Rect inPosition, GUIContent inLabel, RSEntityId inValue, IRSEntityMgr inManager)
        {
            int currentId = (int)inValue;
            int nextId    = EditorGUI.DelayedIntField(inPosition, inLabel, currentId);

            return(new RSEntityId(nextId));
        }
Esempio n. 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            IRSEntityMgr manager = null;

            RSEditorUtility.EditorPlugin.TryGetEntityManager(property.serializedObject.targetObject, out manager);

            label = EditorGUI.BeginProperty(position, label, property);
            {
                SerializedProperty value = property.FindPropertyRelative("m_Value");
                RSEntityId         newId = RSEditorUtility.EditorPlugin.EntityIdGUIField(position, label, new RSEntityId(value.intValue), manager);
                value.intValue = (int)newId;
            }
            EditorGUI.EndProperty();
        }
Esempio n. 6
0
 static private void ValidateEntityId(RSEntityId inEntityId, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
 {
     if (inEntityId == RSEntityId.Null && !inFlags.Has(RSValidationFlags.AllowNullEntity))
     {
         ioState.Error("Null entity not allowed in this context");
     }
     else if (inEntityId != RSEntityId.Null)
     {
         if (inContext.Manager != null)
         {
             var entity = inContext.Manager.Lookup.EntityWithId(inEntityId);
             if (entity == null)
             {
                 ioState.Error("No entity with id {0} found in entity manager", inEntityId);
             }
         }
         else
         {
             ioState.Warn("No entity manager found - unable to verify that entity with id {0} exists", inEntityId);
         }
     }
 }
Esempio n. 7
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());
            }
        }
Esempio n. 8
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));
        }
Esempio n. 9
0
        static private void ValidateEntityScope(EntityScopeData inScope, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            bool bForceFirst = inFlags.Has(RSValidationFlags.RequireSingleEntity);

            switch (inScope.Type)
            {
            case EntityScopeType.ObjectById:
            {
                RSEntityId entityId = inScope.IdArg;
                ValidateEntityId(entityId, inFlags, ioState, inContext);
                break;
            }

            case EntityScopeType.ObjectsWithGroup:
            {
                if (bForceFirst && !inScope.UseFirst)
                {
                    ioState.Error("Potentially multiple return values in context where only one value is accepted");
                }

                ValidateGroupId(inScope.GroupArg, inFlags, ioState, inContext);
                break;
            }

            case EntityScopeType.ObjectsWithName:
            case EntityScopeType.ObjectsWithPrefab:
            {
                if (bForceFirst && !inScope.UseFirst)
                {
                    ioState.Error("Potentially multiple return values in context where only one value is accepted");
                }

                string name = inScope.SearchArg;
                if (string.IsNullOrEmpty(name))
                {
                    ioState.Warn("Empty search string");
                }
                break;
            }

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

            case EntityScopeType.Invalid:
            {
                ioState.Error("Missing entity");
                break;
            }

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

            case EntityScopeType.Argument:
            {
                ValidateTriggerArgument(RSBuiltInTypes.Entity, inFlags, ioState, inContext);
                break;
            }
            }
        }
Esempio n. 10
0
 public void Clear()
 {
     StringSearch    = string.Empty;
     EntitySearch    = RSEntityId.Null;
     ElementSearchId = 0;
 }
Esempio n. 11
0
        private void TableParamsGUI()
        {
            {
                TableMode nextMode = (TableMode)EnumGUILayout.EnumField("Search Type", m_Params.TableParams.Mode);
                if (nextMode != m_Params.TableParams.Mode)
                {
                    m_SelfUndoTarget.MarkDirty("Switched entity search mode");
                    m_Params.TableParams.Mode = nextMode;
                    m_Params.TableParams.Clear();
                    m_SearchQueued = true;
                }
            }

            switch (m_Params.TableParams.Mode)
            {
            case TableMode.Action:
            {
                int nextAction = LibraryGUILayout.ActionSelector(s_ActionLabel, m_Params.TableParams.ElementSearchId, m_Library);
                if (nextAction != m_Params.TableParams.ElementSearchId)
                {
                    m_SelfUndoTarget.MarkDirty("Changed action id");
                    m_Params.TableParams.ElementSearchId = nextAction;
                    m_SearchQueued = true;
                }
                break;
            }

            case TableMode.Query:
            {
                int nextQuery = LibraryGUILayout.QuerySelector(s_QueryLabel, m_Params.TableParams.ElementSearchId, false, m_Library);
                if (nextQuery != m_Params.TableParams.ElementSearchId)
                {
                    m_SelfUndoTarget.MarkDirty("Changed query id");
                    m_Params.TableParams.ElementSearchId = nextQuery;
                    m_SearchQueued = true;
                }
                break;
            }

            case TableMode.Trigger:
            {
                int nextTrigger = (int)LibraryGUILayout.TriggerSelector(s_TriggerLabel, new RSTriggerId(m_Params.TableParams.ElementSearchId), m_Library);
                if (nextTrigger != m_Params.TableParams.ElementSearchId)
                {
                    m_SelfUndoTarget.MarkDirty("Changed trigger id");
                    m_Params.TableParams.ElementSearchId = nextTrigger;
                    m_SearchQueued = true;
                }
                break;
            }

            case TableMode.Entity:
            {
                RSEntityId entityId = RSEditorUtility.EditorPlugin.EntityIdGUIField(s_EntityLabel, m_Params.TableParams.EntitySearch, m_EntityMgr);
                if (entityId != m_Params.TableParams.EntitySearch)
                {
                    m_SelfUndoTarget.MarkDirty("Changed entity search");
                    m_Params.TableParams.EntitySearch = entityId;
                    m_SearchQueued = true;
                }
                break;
            }

            case TableMode.String:
            {
                string nextString = EditorGUILayout.TextField("Search", m_Params.TableParams.StringSearch);
                if (nextString != m_Params.TableParams.StringSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Changed string search");
                    m_Params.TableParams.StringSearch = nextString;
                    m_SearchQueued = true;
                }
                break;
            }
            }
        }
Esempio n. 12
0
        private void EntityParamsGUI()
        {
            {
                EntityMode nextMode = (EntityMode)EnumGUILayout.EnumField("Search Type", m_Params.EntityParams.Mode);
                if (nextMode != m_Params.EntityParams.Mode)
                {
                    m_SelfUndoTarget.MarkDirty("Switched entity search mode");
                    m_Params.EntityParams.Mode = nextMode;
                    m_Params.EntityParams.Clear();
                    m_SearchQueued = true;
                }
            }

            switch (m_Params.EntityParams.Mode)
            {
            case EntityMode.Id:
            {
                int nextId = EditorGUILayout.IntField("Entity Id", m_Params.EntityParams.EntityIdSearch);
                if (nextId != m_Params.EntityParams.EntityIdSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Switched entity id search");
                    m_Params.EntityParams.EntityIdSearch = nextId;
                    m_SearchQueued = true;
                }
                break;
            }

            case EntityMode.LinkId:
            {
                string nextLink = EditorGUILayout.TextField("Link Id", m_Params.EntityParams.StringSearch);
                if (nextLink != m_Params.EntityParams.StringSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Switched link search");
                    m_Params.EntityParams.StringSearch = nextLink;
                    m_SearchQueued = true;
                }
                break;
            }

            case EntityMode.LinkEntity:
            {
                RSEntityId entityId = RSEditorUtility.EditorPlugin.EntityIdGUIField(s_EntityLabel, m_Params.EntityParams.EntityRefSearch, m_EntityMgr);
                if (entityId != m_Params.EntityParams.EntityRefSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Changed entity search");
                    m_Params.EntityParams.EntityRefSearch = entityId;
                    m_SearchQueued = true;
                }
                break;
            }

            case EntityMode.Name:
            {
                string nextName = EditorGUILayout.TextField("Name", m_Params.EntityParams.StringSearch);
                if (nextName != m_Params.EntityParams.StringSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Switched name search");
                    m_Params.EntityParams.StringSearch = nextName;
                    m_SearchQueued = true;
                }
                break;
            }

            case EntityMode.PrefabName:
            {
                string nextPrefab = EditorGUILayout.TextField("Prefab Name", m_Params.EntityParams.StringSearch);
                if (nextPrefab != m_Params.EntityParams.StringSearch)
                {
                    m_SelfUndoTarget.MarkDirty("Switched prefab name search");
                    m_Params.EntityParams.StringSearch = nextPrefab;
                    m_SearchQueued = true;
                }
                break;
            }

            case EntityMode.Table:
            {
                EditorGUILayout.HelpBox("Not yet implemented", MessageType.Warning);
                break;
            }
            }
        }