Exemplo n.º 1
0
 /// <summary>
 /// Renders a layout editor for an RSValue.
 /// </summary>
 static public RSValue RSValueField(RSValue inValue, RSTypeInfo inExpectedType, RSValidationFlags inFlags, RSValidationContext inContext)
 {
     using (new RSGUI.LabelWidthScope(0))
     {
         return(DoRSValueField(GUIContent.none, inValue, inExpectedType, inFlags, inContext));
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        internal ExecutionScope CreateScope(IRSRuntimeEntity inEntity, RSValue inArgument, RuleFlags inFlags)
        {
            List <ExecutionScope> pool;

            if ((inFlags & RuleFlags.UsesRegisters) != 0)
            {
                pool = m_RegisterScopePool;
            }
            else
            {
                pool = m_LocalScopePool;
            }

            ExecutionScope scope;
            int            count = pool.Count;

            if (count > 0)
            {
                scope = pool[count - 1];
                pool.RemoveAt(count - 1);
            }
            else
            {
                scope = ConstructScope(inFlags);
            }

            scope.Initialize(inEntity, inArgument);
            return(scope);
        }
Exemplo n.º 4
0
 internal void Broadcast(RSTriggerId inTriggerId, RSValue inArgument, bool inbForce)
 {
     foreach (var entity in Entities.EntitiesForTrigger(inTriggerId))
     {
         TriggerRS(entity, inTriggerId, inArgument, inbForce);
     }
 }
Exemplo n.º 5
0
 internal RSTypeInfo(Type inType, string inFriendlyName, RSValue inDefault, TypeFlags inFlags = 0)
 {
     SystemType   = inType;
     FriendlyName = inFriendlyName ?? inType.Name;
     DefaultValue = inDefault;
     Flags        = inFlags | GetFlags(inType);
 }
Exemplo n.º 6
0
        internal void Persist(IRSRuntimeComponent inComponent, int inFlags, ref RSPersistComponentData outData)
        {
            if (outData == null)
            {
                outData = new RSPersistComponentData();
            }

            outData.ComponentType = IdHash;

            if (m_PersistFields != null)
            {
                Array.Resize(ref outData.NamedValues, m_PersistFields.Count);

                int idx = 0;
                foreach (var persistField in m_PersistFields.Values)
                {
                    string  name  = persistField.Name;
                    RSValue value = persistField.Persist(inComponent);
                    outData.NamedValues[idx++] = new RSNamedValue(name, value);
                }
            }

            if (m_UseCustomDataField)
            {
                ((IRSCustomPersistDataProvider)inComponent).GetCustomPersistData(ref outData.CustomData, inFlags);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Evaluates a condition.
        /// </summary>
        public bool EvaluateCondition(RSConditionData inCondition)
        {
            Assert.True(!inCondition.Target.IsMultiValue(), "Multi-target queries cannot be right-hand values for conditions");

            MultiReturn <RSValue> query = ResolveValue(inCondition.Query);
            RSValue         target      = ResolveValue(inCondition.Target).ForceSingle();
            CompareOperator op          = inCondition.Operator;

            if (query.Set != null)
            {
                Subset subset = inCondition.MultiQuerySubset;
                foreach (var check in query.Set)
                {
                    bool bPass = Evaluate(op, check, target);
                    switch (subset)
                    {
                    case Subset.All:
                    {
                        if (!bPass)
                        {
                            return(false);
                        }
                        break;
                    }

                    case Subset.Any:
                    {
                        if (bPass)
                        {
                            return(true);
                        }
                        break;
                    }

                    case Subset.None:
                    {
                        if (bPass)
                        {
                            return(false);
                        }
                        break;
                    }
                    }
                }

                switch (subset)
                {
                case Subset.All:
                case Subset.None:
                    return(true);

                default:
                    return(false);
                }
            }

            return(Evaluate(op, query.Single, target));
        }
Exemplo n.º 8
0
 static internal RSValue[] Convert(params object[] inValues)
 {
     RSValue[] converted = new RSValue[inValues.Length];
     for (int i = 0; i < inValues.Length; ++i)
     {
         converted[i] = RSInterop.ToRSValue(inValues[i]);
     }
     return(converted);
 }
Exemplo n.º 9
0
        internal override void Link(RSTypeAssembly inAssembly)
        {
            m_MethodSettings.Configure(m_MethodInfo, m_Parameters, true);
            OwnerType = m_MethodSettings.BoundType;

            ReturnType     = RSInterop.RSTypeFor(m_MethodInfo.ReturnType, inAssembly);
            m_DefaultValue = m_DefaultSystemValue != null?RSInterop.ToRSValue(m_DefaultSystemValue) : ReturnType.DefaultValue;

            GenerateParameters(inAssembly);
        }
Exemplo n.º 10
0
        private bool TryCreateMeta(Type inType, out RSTypeInfo outMetadata)
        {
            if (inType.IsEnum)
            {
                Enum defaultVal = (Enum)Enum.ToObject(inType, 0);
                outMetadata = new RSTypeInfo(inType, null, RSValue.FromEnum(defaultVal));
                outMetadata.InitializeEnum();
                return(true);
            }

            outMetadata = null;
            return(false);
        }
Exemplo n.º 11
0
        public void Reset()
        {
            m_Self     = null;
            m_Argument = RSValue.Null;

            if (m_Registers != null)
            {
                for (int i = 0; i < RSRegisters.MaxRegisters; ++i)
                {
                    m_Registers[i] = default(RSValue);
                }
            }
        }
Exemplo n.º 12
0
        internal void TriggerRS(IRSRuntimeEntity inEntity, RSTriggerId inTriggerId, RSValue inArgument, bool inbForce)
        {
            if (!inbForce && inEntity.IsLocked())
            {
                return;
            }

            ExecutionScope scope = CreateScope(inEntity, inArgument, 0);

            using (new SharedRef <ExecutionScope>(scope))
            {
                inEntity?.RuleTable?.EvaluateTrigger(inTriggerId, scope);
            }
        }
Exemplo n.º 13
0
        public bool Evaluate(CompareOperator inComparison, RSValue inCheck, RSValue inValue)
        {
            switch (inCheck.GetInnerType())
            {
            case RSValue.InnerType.Null:
                return(ComparisonExtensions.Evaluate(inComparison, false, inCheck.GetInnerType() != RSValue.InnerType.Null));

            case RSValue.InnerType.Int32:
                return(ComparisonExtensions.Evaluate(inComparison, inCheck.AsInt, inValue.AsInt));

            case RSValue.InnerType.Bool:
                return(ComparisonExtensions.Evaluate(inComparison, inCheck.AsBool, inValue.AsBool));

            case RSValue.InnerType.Color:
                return(ComparisonExtensions.EvaluateEquatable(inComparison, inCheck.AsColor, inValue.AsColor));

            case RSValue.InnerType.Float:
                return(ComparisonExtensions.Evaluate(inComparison, inCheck.AsFloat, inValue.AsFloat));

            case RSValue.InnerType.Vector2:
                return(ComparisonExtensions.EvaluateEquatable(inComparison, inCheck.AsVector2, inValue.AsVector2));

            case RSValue.InnerType.Vector3:
                return(ComparisonExtensions.EvaluateEquatable(inComparison, inCheck.AsVector3, inValue.AsVector3));

            case RSValue.InnerType.Vector4:
                return(ComparisonExtensions.EvaluateEquatable(inComparison, inCheck.AsVector4, inValue.AsVector4));

            case RSValue.InnerType.String:
                return(ComparisonExtensions.Evaluate(inComparison, inCheck.AsString, inValue.AsString));

            case RSValue.InnerType.Enum:
                return(ComparisonExtensions.Evaluate(inComparison, inCheck.AsInt, inValue.AsInt));

            case RSValue.InnerType.EntityScope:
                return(ComparisonExtensions.EvaluateReferenceEquals(inComparison, ResolveEntity(inCheck.AsEntity).ForceSingle(), ResolveEntity(inValue.AsEntity).ForceSingle()));

            default:
                throw new ArgumentException("Invalid value type " + inCheck.GetInnerType(), "inCheck");
            }
        }
Exemplo n.º 14
0
        internal void Restore(IRSRuntimeComponent inComponent, RSPersistComponentData inData, RSEnvironment inEnvironment, int inFlags)
        {
            if (inData.NamedValues != null)
            {
                for (int i = 0; i < inData.NamedValues.Length; ++i)
                {
                    string  name  = inData.NamedValues[i].Name;
                    RSValue value = inData.NamedValues[i].Value;

                    RSPersistFieldInfo fieldInfo;
                    m_PersistFields.TryGetValue(name, out fieldInfo);
                    if (fieldInfo != null)
                    {
                        fieldInfo.Restore(inComponent, value, inEnvironment);
                    }
                }
            }

            if (m_UseCustomDataField)
            {
                ((IRSCustomPersistDataProvider)inComponent).RestoreCustomPersistData(inData.CustomData, inFlags, inEnvironment);
            }
        }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
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));
            }
        }
Exemplo n.º 17
0
 public void LoadRegister(RegisterIndex inRegister, RSValue inValue)
 {
     Assert.True(m_Registers != null, "Execution Scope has no registers available");
     m_Registers[(int)inRegister] = inValue;
 }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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));
 }
Exemplo n.º 20
0
 public void Initialize(IRSRuntimeEntity inSelf, RSValue inArgument)
 {
     m_Self     = inSelf;
     m_Argument = inArgument;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Retrieves the type metadata for the given value.
 /// </summary>
 static public RSTypeInfo RSTypeFor(RSValue inValue, RSTypeAssembly inAssembly)
 {
     return(RSTypeFor(inValue.GetInteropType(), inAssembly));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Converts an RSValue to the given C# type.
        /// </summary>
        static public object ToObject(Type inType, RSValue inValue, ExecutionScope inContext)
        {
            if (inType == null || inType == typeof(void))
            {
                return(null);
            }

            if (inType == typeof(object))
            {
                return(inValue);
            }

            if (inType == typeof(RSValue))
            {
                return(inValue);
            }

            if (inType.IsEnum)
            {
                return(inValue.AsEnum(inType));
            }

            switch (Type.GetTypeCode(inType))
            {
            case TypeCode.Boolean:
                return(inValue.AsBool);

            case TypeCode.Byte:
                return((byte)inValue.AsInt);

            case TypeCode.Char:
                return((char)inValue.AsInt);

            case TypeCode.Double:
                return((double)inValue.AsFloat);

            case TypeCode.Int16:
                return((Int16)inValue.AsInt);

            case TypeCode.Int32:
                return(inValue.AsInt);

            case TypeCode.Int64:
                return((Int64)inValue.AsInt);

            case TypeCode.SByte:
                return((sbyte)inValue.AsInt);

            case TypeCode.Single:
                return(inValue.AsFloat);

            case TypeCode.String:
                return(inValue.AsString);

            case TypeCode.UInt16:
                return((UInt16)inValue.AsInt);

            case TypeCode.UInt32:
                return((UInt32)inValue.AsInt);

            case TypeCode.UInt64:
                return((UInt64)inValue.AsInt);

            case TypeCode.Object:
            {
                if (inType == typeof(Color))
                {
                    return(inValue.AsColor);;
                }
                if (inType == typeof(Vector2))
                {
                    return(inValue.AsVector2);
                }
                if (inType == typeof(Vector3))
                {
                    return(inValue.AsVector3);
                }
                if (inType == typeof(Vector4))
                {
                    return(inValue.AsVector4);
                }
                if (inType == typeof(RSGroupId))
                {
                    return(inValue.AsGroupId);
                }
                if (inType == typeof(RSTriggerId))
                {
                    return(inValue.AsTriggerId);
                }
                if (typeof(IRSEntity).IsAssignableFrom(inType))
                {
                    return(inContext.ResolveEntity(inValue.AsEntity).ForceSingle());
                }
                break;
            }
            }

            throw new ArgumentException(string.Format("Unable to convert RSValue {0} to object of type {1}", inValue, inType), "inValue");
        }
Exemplo n.º 23
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();
        }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Converts a C# object to an RSValue.
        /// </summary>
        static public RSValue ToRSValue(object inObject)
        {
            if (inObject == null)
            {
                return(RSValue.Null);
            }

            Type objType = inObject.GetType();

            if (objType == typeof(RSValue))
            {
                return((RSValue)inObject);
            }

            if (objType.IsEnum)
            {
                return(RSValue.FromEnum((Enum)inObject));
            }

            switch (Type.GetTypeCode(objType))
            {
            case TypeCode.Boolean:
                return(RSValue.FromBool((bool)inObject));

            case TypeCode.Byte:
                return(RSValue.FromInt((byte)inObject));

            case TypeCode.Char:
                return(RSValue.FromInt((char)inObject));

            case TypeCode.Double:
                Log.Warn("[RSInterop] Truncation from Double to Single");
                return(RSValue.FromFloat((float)(double)inObject));

            case TypeCode.Int16:
                return(RSValue.FromInt((Int16)inObject));

            case TypeCode.Int32:
                return(RSValue.FromInt((Int32)inObject));

            case TypeCode.SByte:
                return(RSValue.FromInt((sbyte)inObject));

            case TypeCode.Single:
                return(RSValue.FromFloat((float)inObject));

            case TypeCode.String:
                return(RSValue.FromString((string)inObject));

            case TypeCode.UInt16:
                return(RSValue.FromInt((UInt16)inObject));

            case TypeCode.UInt32:
                Log.Warn("[RSInterop] Truncation from UInt32 to Int32");
                return(RSValue.FromInt((int)(UInt32)inObject));

            case TypeCode.UInt64:
                Log.Warn("[RSInterop] Truncation from UInt64 to Int32");
                return(RSValue.FromInt((int)(UInt64)inObject));

            case TypeCode.Object:
            {
                if (objType == typeof(Color))
                {
                    return(RSValue.FromColor((Color)inObject));
                }
                if (objType == typeof(Vector2))
                {
                    return(RSValue.FromVector2((Vector2)inObject));
                }
                if (objType == typeof(Vector3))
                {
                    return(RSValue.FromVector3((Vector3)inObject));
                }
                if (objType == typeof(Vector4))
                {
                    return(RSValue.FromVector4((Vector4)inObject));
                }
                if (objType == typeof(RSGroupId))
                {
                    return(RSValue.FromGroupId((RSGroupId)inObject));
                }
                if (objType == typeof(RSTriggerId))
                {
                    return(RSValue.FromTriggerId((RSTriggerId)inObject));
                }
                if (typeof(IRSEntity).IsAssignableFrom(objType))
                {
                    IRSEntity       entity = (IRSEntity)inObject;
                    EntityScopeData scope  = EntityScopeData.Entity(entity.Id);
                    return(RSValue.FromEntity(scope));
                }
                break;
            }
            }

            throw new ArgumentException(string.Format("Unable to convert object of type {0} to RSValue", objType.Name), "inObject");
        }
Exemplo n.º 26
0
 static private void LoadRegister(IScriptContext inContext, [RSParameter("Register")] RegisterIndex inRegister, [RSParameter("Value")] RSValue inValue)
 {
     inContext?.Logger?.Log("Loading register {0} with value {1}", inRegister, inValue);
     inContext.LoadRegister(inRegister, inValue);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Converts an RSValue to the given C# type.
 /// </summary>
 static public T ToObject <T>(RSValue inValue, ExecutionScope inContext)
 {
     return((T)ToObject(typeof(T), inValue, inContext));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Converts an RSValue to its closest mapped C# type.
 /// </summary>
 static public object ToObject(RSValue inValue, ExecutionScope inContext)
 {
     return(ToObject(inValue.GetInteropType(), inValue, inContext));
 }
Exemplo n.º 29
0
        internal void Restore(IRSRuntimeComponent inComponent, RSValue inValue, RSEnvironment inEnvironment)
        {
            object restoreValue = RSInterop.ToObject(m_FieldType, inValue, inEnvironment.StaticScope);

            m_FieldInfo.SetValue(inComponent, restoreValue);
        }