Пример #1
0
        static private void ValidateValue(RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            Type systemType = inExpectedType.SystemType;

            if (systemType.IsEnum)
            {
                try
                {
                    Enum currentValue = inValue.AsEnum();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    ioState.Error("Enum {0} cannot be represented as type {1}", inValue, inExpectedType);
                }
                return;
            }

            if (inExpectedType == RSBuiltInTypes.Entity)
            {
                EntityScopeData scope = inValue.AsEntity;
                ValidateEntityScope(scope, inFlags.ForEntityValue(), ioState, inContext);
            }
            else if (inExpectedType == RSBuiltInTypes.GroupId)
            {
                RSGroupId group = inValue.AsGroupId;
                ValidateGroupId(group, inFlags, ioState, inContext);
            }
            else if (inExpectedType == RSBuiltInTypes.TriggerId)
            {
                RSTriggerId triggerId = inValue.AsTriggerId;
                ValidateTriggerId(triggerId, inFlags, ioState, inContext);
            }
        }
Пример #2
0
        /// <summary>
        /// A group selector.
        /// </summary>
        static public RSGroupId GroupSelector(Rect inPosition, GUIContent inLabel, RSGroupId inCurrentGroup, RSLibrary inLibrary)
        {
            RSEditorUtility.s_GroupElements.Clear();
            inLibrary.GetAllGroups(RSEditorUtility.s_GroupElements);

            int group = RSGUI.RSElementSelector(inPosition, inLabel, (int)inCurrentGroup, RSEditorUtility.s_GroupElements);

            return(new RSGroupId(group));
        }
Пример #3
0
        /// <summary>
        /// A group selector.
        /// </summary>
        static public RSGroupId GroupSelector(RSGroupId inCurrentGroup, RSLibrary inLibrary)
        {
            RSEditorUtility.s_GroupElements.Clear();
            inLibrary.GetAllGroups(RSEditorUtility.s_GroupElements);

            int group = RSGUILayout.RSElementSelector((int)inCurrentGroup, RSEditorUtility.s_GroupElements);

            return(new RSGroupId(group));
        }
Пример #4
0
        public bool RemoveFromGroup(T inEntity, RSGroupId inGroup)
        {
            HashSet <T> groupSet;

            if (m_GroupMap.TryGetValue(inGroup, out groupSet))
            {
                return(groupSet.Remove(inEntity));
            }
            return(false);
        }
Пример #5
0
        public bool AddToGroup(T inEntity, RSGroupId inGroup)
        {
            HashSet <T> groupSet;

            if (!m_GroupMap.TryGetValue(inGroup, out groupSet))
            {
                groupSet = new HashSet <T>();
                m_GroupMap.Add(inGroup, groupSet);
            }
            return(groupSet.Add(inEntity));
        }
Пример #6
0
        public IEnumerable <T> EntitiesWithGroup(RSGroupId inGroup)
        {
            HashSet <T> groupMap;

            if (m_GroupMap.TryGetValue(inGroup, out groupMap))
            {
                foreach (var entity in groupMap)
                {
                    yield return(entity);
                }
            }
        }
Пример #7
0
        public T EntityWithGroup(RSGroupId inGroup)
        {
            HashSet <T> groupSet;

            if (m_GroupMap.TryGetValue(inGroup, out groupSet))
            {
                var enumerator = groupSet.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    return(enumerator.Current);
                }
            }

            return(null);
        }
Пример #8
0
        /// <summary>
        /// Finds the group metadata associated with the given id.
        /// </summary>
        public RSGroupInfo GetGroup(RSGroupId inId)
        {
            if (inId == RSGroupId.Null)
            {
                return(null);
            }

            RSGroupInfo meta;

            if (!m_Groups.TryGetValue((int)inId, out meta))
            {
                Log.Error("[RSMetaDatabase] No group with id {0} registered", inId);
            }
            return(meta);
        }
Пример #9
0
        static private RSGroupInfo ValidateGroupId(RSGroupId inGroupId, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            if (inGroupId != RSGroupId.Null)
            {
                RSGroupInfo groupInfo = inContext.Library.GetGroup(inGroupId);
                if (groupInfo == null)
                {
                    ioState.Error("Group {0} does not exist", inGroupId);
                }

                return(groupInfo);
            }
            else
            {
                return(null);
            }
        }
Пример #10
0
        public RSGroupInfo(RSGroupAttribute inAttribute, FieldInfo inFieldInfo)
        {
            Id      = inAttribute.Id;
            IdHash  = ScriptUtils.Hash(Id);
            GroupId = new RSGroupId(IdHash);

            Name        = inAttribute.Name ?? inFieldInfo.Name;
            Description = inAttribute.Description ?? string.Empty;
            Icon        = inAttribute.Icon ?? string.Empty;

            using (var psb = PooledStringBuilder.Alloc())
            {
                psb.Builder.Append(Name);
                if (!string.IsNullOrEmpty(Description))
                {
                    psb.Builder.Append("\n - ").Append(Description);
                }
                Tooltip = psb.Builder.ToString();
            }
        }
Пример #11
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());
            }
        }
Пример #12
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);
        }
Пример #13
0
 static public RSValue FromGroupId(RSGroupId inGroupId)
 {
     return(new RSValue(inGroupId));
 }
Пример #14
0
        void ISerializedObject.Serialize(Serializer ioSerializer)
        {
            ioSerializer.Enum("type", ref m_Type, InnerType.Null, FieldOptions.PreferAttribute);
            switch (m_Type)
            {
            case InnerType.Bool:
            {
                bool bValue = ioSerializer.IsWriting ? BoolValue : false;
                ioSerializer.Serialize("value", ref bValue);
                if (ioSerializer.IsReading)
                {
                    BoolValue = bValue;
                }
                break;
            }

            case InnerType.Color:
            {
                Color value = ioSerializer.IsWriting ? ColorValue : default(Color);
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    ColorValue = value;
                }
                break;
            }

            case InnerType.Float:
            {
                float value = ioSerializer.IsWriting ? FloatValue : 0;
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    FloatValue = value;
                }
                break;
            }

            case InnerType.Int32:
            {
                int value = ioSerializer.IsWriting ? IntValue : 0;
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    IntValue = value;
                }
                break;
            }

            case InnerType.String:
            {
                string value = ioSerializer.IsWriting ? StringValue : null;
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    StringValue = value;
                }
                break;
            }

            case InnerType.Vector2:
            {
                Vector2 value = ioSerializer.IsWriting ? Vector2Value : default(Vector2);
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    Vector2Value = value;
                }
                break;
            }

            case InnerType.Vector3:
            {
                Vector3 value = ioSerializer.IsWriting ? Vector3Value : default(Vector3);
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    Vector3Value = value;
                }
                break;
            }

            case InnerType.Vector4:
            {
                Vector4 value = ioSerializer.IsWriting ? Vector4Value : default(Vector4);
                ioSerializer.Serialize("value", ref value);
                if (ioSerializer.IsReading)
                {
                    Vector4Value = value;
                }
                break;
            }

            case InnerType.Enum:
            {
                ioSerializer.Serialize("value", ref m_IntValue);
                ioSerializer.Serialize("enumType", ref m_StringValue);
                break;
            }

            case InnerType.EntityScope:
            {
                EntityScopeData value = ioSerializer.IsWriting ? EntityValue : default(EntityScopeData);
                ioSerializer.Object("value", ref value);
                if (ioSerializer.IsReading)
                {
                    EntityValue = value;
                }
                break;
            }

            case InnerType.GroupId:
            {
                RSGroupId value = ioSerializer.IsWriting ? GroupIdValue : default(RSGroupId);
                ioSerializer.Int32Proxy("value", ref value);
                if (ioSerializer.IsReading)
                {
                    GroupIdValue = value;
                }
                break;
            }

            case InnerType.TriggerId:
            {
                RSTriggerId value = ioSerializer.IsWriting ? TriggerIdValue : default(RSTriggerId);
                ioSerializer.Int32Proxy("value", ref value);
                if (ioSerializer.IsReading)
                {
                    TriggerIdValue = value;
                }
                break;
            }
            }
        }
Пример #15
0
 private RSValue(RSGroupId inGroup) : this(InnerType.GroupId, (int)inGroup)
 {
 }
Пример #16
0
 static public EntityScopeData WithGroup(RSGroupId inGroup, bool inbUseFirst = false)
 {
     return(new EntityScopeData(EntityScopeType.ObjectsWithGroup, (int)inGroup, null, inbUseFirst));
 }
Пример #17
0
        static public int CountEntitiesWithGroup <T>(this IRSEntityLookup <T> inEntityLookup, RSGroupId inGroup) where T : class, IRSEntity
        {
            int count = 0;

            foreach (var entity in inEntityLookup.EntitiesWithGroup(inGroup))
            {
                ++count;
            }
            return(count);
        }
Пример #18
0
 static public int EntityCountWithGroup(IScriptContext inContext,
                                        [RSParameter("Group Filter", "Entity group")] RSGroupId inGroup)
 {
     return(inContext.Entities.Lookup.CountEntitiesWithGroup(inGroup));
 }