示例#1
0
        /// <summary>
        /// A action selector for the global scope.
        /// </summary>
        static public int ActionSelectorGlobal(GUIContent inLabel, int inCurrentId, RSLibrary inLibrary)
        {
            RSEditorUtility.s_ActionElements.Clear();
            inLibrary.GetAllGlobalActions(RSEditorUtility.s_ActionElements);

            return(RSGUILayout.RSElementSelector(inLabel, inCurrentId, RSEditorUtility.s_ActionElements));
        }
示例#2
0
        /// <summary>
        /// A query selector for a unknown entity.
        /// </summary>
        static public int QuerySelectorUnknown(int inCurrentId, bool inbNoParams, RSLibrary inLibrary)
        {
            RSEditorUtility.s_QueryElements.Clear();
            inLibrary.GetAllLocalQueries(RSEditorUtility.s_QueryElements, null, inbNoParams);

            return(RSGUILayout.RSElementSelector(inCurrentId, RSEditorUtility.s_QueryElements));
        }
示例#3
0
        /// <summary>
        /// A action selector for a specific entity.
        /// </summary>
        static public int ActionSelector(int inCurrentId, IRSEntity inEntity, RSLibrary inLibrary)
        {
            RSEditorUtility.s_ActionElements.Clear();
            inLibrary.GetAllActionsForEntity(inEntity, RSEditorUtility.s_ActionElements);

            return(RSGUILayout.RSElementSelector(inCurrentId, RSEditorUtility.s_ActionElements));
        }
示例#4
0
        static private RuleFlags GetRuleFlags(RSResolvableValueData inValueData, RSLibrary inLibrary)
        {
            RuleFlags flags = 0;

            switch (inValueData.Mode)
            {
            case ResolvableValueMode.Query:
            {
                flags |= GetRuleFlags(inValueData.Query.Scope, inLibrary);
                flags |= GetRuleFlags(inLibrary.GetQuery(inValueData.Query.Id));
                if (inValueData.QueryArguments != null)
                {
                    foreach (var arg in inValueData.QueryArguments)
                    {
                        flags |= GetRuleFlags(arg, inLibrary);
                    }
                }
                break;
            }

            case ResolvableValueMode.Register:
            {
                flags |= RuleFlags.UsesRegisters;
                break;
            }
            }

            return(flags);
        }
示例#5
0
        /// <summary>
        /// Generates persistent data from the given runtime entity and its components.
        /// </summary>
        static public RSPersistEntityData Persist(RSLibrary inLibrary, IRSRuntimeEntity inEntity, IReadOnlyList <IRSRuntimeComponent> inComponents, int inFlags)
        {
            RSPersistEntityData data = null;

            Persist(inLibrary, inEntity, inComponents, inFlags, ref data);
            return(data);
        }
示例#6
0
        /// <summary>
        /// A action selector for a unknown entity.
        /// </summary>
        static public int ActionSelectorUnknown(Rect inPosition, int inCurrentId, RSLibrary inLibrary)
        {
            RSEditorUtility.s_ActionElements.Clear();
            inLibrary.GetAllLocalActions(RSEditorUtility.s_ActionElements);

            return(RSGUI.RSElementSelector(inPosition, inCurrentId, RSEditorUtility.s_ActionElements));
        }
示例#7
0
        /// <summary>
        /// Default library for the given entity type.
        /// </summary>
        static public RSLibrary DefaultLibrary(Type inEntityType)
        {
            RSLibrary library;

            if (!s_Libraries.TryGetValue(inEntityType, out library))
            {
                library = new RSLibrary(inEntityType);
                Action <float, string> progressUpdate = (f, s) =>
                {
                    EditorUtility.DisplayProgressBar("Loading RuleScript library for " + inEntityType.Name, s, f);
                };

                try
                {
                    System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
                    library.ScanAssemblies(progressUpdate);
                    stopwatch.Stop();
                    Debug.Log("[RSEditorUtility] Loaded default library for " + inEntityType.Name + " in " + stopwatch.Elapsed.TotalSeconds + " seconds");
                }
                finally
                {
                    s_Libraries.Add(inEntityType, library);
                    EditorUtility.ClearProgressBar();
                }
            }
            return(library);
        }
示例#8
0
        private void RegenContext()
        {
            Scene currentScene = EditorSceneManager.GetActiveScene();

            RSEditorUtility.EditorPlugin.TryGetEntityManager(currentScene, out m_EntityMgr);
            RSEditorUtility.EditorPlugin.TryGetRuleTableManager(currentScene, out m_TableMgr);
            m_Library = RSEditorUtility.EditorPlugin.Library;
        }
 internal RSValidationContext(RSLibrary inLibrary, IRSEntityMgr inManager, IRSEntity inEntity, RSTriggerInfo inTrigger, RSParameterInfo inParameterInfo)
 {
     Library   = inLibrary;
     Manager   = inManager;
     Entity    = inEntity;
     Trigger   = inTrigger;
     Parameter = inParameterInfo;
 }
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            switch (Mode)
            {
            case ResolvableValueMode.Value:
                return(Value.GetPreviewString(inTriggerContext, inLibrary));

            case ResolvableValueMode.Argument:
                return(string.Format("Arg({0})", inTriggerContext?.ParameterType?.Name ?? "TriggerArg"));

            case ResolvableValueMode.Query:
            {
                using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
                {
                    var sb = psb.Builder;

                    sb.Append(Query.GetPreviewStringAsQuery(inTriggerContext, inLibrary));

                    if (QueryArguments != null && QueryArguments.Length > 0)
                    {
                        sb.Append("(");

                        RSQueryInfo queryInfo = inLibrary.GetQuery(Query.Id);
                        for (int i = 0; i < QueryArguments.Length; ++i)
                        {
                            if (i > 0)
                            {
                                sb.Append("; ");
                            }

                            if (queryInfo != null && i < queryInfo.Parameters.Length)
                            {
                                sb.Append(queryInfo.Parameters[i].Name);
                            }
                            else
                            {
                                sb.Append(i);
                            }

                            sb.Append(": ");

                            sb.Append(QueryArguments[i].GetPreviewString(inTriggerContext, inLibrary));
                        }

                        sb.Append(")");
                    }

                    return(sb.ToString());
                }
            }

            case ResolvableValueMode.Register:
                return(string.Format("Register({0})", Register));

            default:
                return("[No Value]");
            }
        }
示例#11
0
        /// <summary>
        /// Generates persistent data from the given runtime entity and its components.
        /// </summary>
        static public bool Persist(RSLibrary inLibrary, IRSRuntimeEntity inEntity, int inFlags, ref RSPersistEntityData outData)
        {
            if (inEntity == null)
            {
                return(false);
            }

            return(Persist(inLibrary, inEntity, inEntity.GetRSComponents(), inFlags, ref outData));
        }
示例#12
0
        /// <summary>
        /// Generates persistent data from the given runtime entity.
        /// </summary>
        static public RSPersistEntityData Persist(RSLibrary inLibrary, IRSRuntimeEntity inEntity, int inFlags)
        {
            if (inEntity == null)
            {
                return(null);
            }

            return(Persist(inLibrary, inEntity, inEntity.GetRSComponents(), inFlags));
        }
示例#13
0
        static private RuleFlags GetRuleFlags(EntityScopeData inScopeData, RSLibrary inLibrary)
        {
            if (inScopeData.Type == EntityScopeType.ObjectInRegister)
            {
                return(RuleFlags.UsesRegisters);
            }

            return(0);
        }
示例#14
0
        /// <summary>
        /// A trigger selector.
        /// </summary>
        static public RSTriggerId TriggerSelector(RSTriggerId inCurrentId, RSLibrary inLibrary)
        {
            RSEditorUtility.s_TriggerElements.Clear();
            inLibrary.GetAllTriggers(RSEditorUtility.s_TriggerElements);

            int trigger = RSGUILayout.RSElementSelector((int)inCurrentId, RSEditorUtility.s_TriggerElements);

            return(new RSTriggerId(trigger));
        }
示例#15
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));
        }
示例#16
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            string preview = GetBasePreviewString(inTriggerContext, inLibrary);

            if (!string.IsNullOrEmpty(m_LinkSearch))
            {
                preview += "." + m_LinkSearch;
                if (m_UseFirstLink)
                {
                    preview += "[0]";
                }
            }
            return(preview);
        }
示例#17
0
 IEnumerable <Type> IRSEntity.GetRSComponentTypes(RSLibrary inLibrary)
 {
     if (Components != null)
     {
         for (int i = 0; i < Components.Length; ++i)
         {
             RSComponentInfo compInfo = inLibrary.GetComponent(Components[i].ComponentType);
             if (compInfo != null)
             {
                 yield return(compInfo.OwnerType);
             }
         }
     }
 }
示例#18
0
        static private RuleFlags GetRuleFlags(RSConditionData inConditionData, RSLibrary inLibrary)
        {
            RuleFlags flags = 0;

            if (inConditionData.Enabled)
            {
                flags |= GetRuleFlags(inConditionData.Query, inLibrary);
                if (inConditionData.Operator.IsBinary())
                {
                    flags |= GetRuleFlags(inConditionData.Target, inLibrary);
                }
            }

            return(flags);
        }
示例#19
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
            {
                var sb = psb.Builder;

                if (!Enabled)
                {
                    sb.Append("[Disabled] ");
                }

                sb.Append(Action.GetPreviewStringAsAction(inTriggerContext, inLibrary));

                if (Arguments != null && Arguments.Length > 0)
                {
                    sb.Append("(");

                    RSActionInfo actionInfo = inLibrary.GetAction(Action.Id);
                    for (int i = 0; i < Arguments.Length; ++i)
                    {
                        if (i > 0)
                        {
                            sb.Append("; ");
                        }

                        if (actionInfo != null && i < actionInfo.Parameters.Length)
                        {
                            sb.Append(actionInfo.Parameters[i].Name);
                        }
                        else
                        {
                            sb.Append(i);
                        }

                        sb.Append(": ");

                        sb.Append(Arguments[i].GetPreviewString(inTriggerContext, inLibrary));
                    }

                    sb.Append(")");
                }

                return(sb.ToString());
            }
        }
示例#20
0
        public RSEnvironment(RSLibrary inDatabase, IRSRuntimeEntityMgr inEntityMgr, IRSRuleTableMgr inTableMgr, IRSDebugLogger inLogger)
        {
            Library  = inDatabase;
            Entities = inEntityMgr;
            Tables   = inTableMgr;
            Logger   = inLogger;

            if (Entities != null)
            {
                Entities.Context = this;
            }

            m_StaticScope = new ExecutionScope(this, ExecutionScope.Type.Registers);
            m_StaticScope.Initialize(null, RSValue.Null);

            m_LocalScopePool    = new List <ExecutionScope>();
            m_RegisterScopePool = new List <ExecutionScope>();
        }
        public RSTypeInfo TypeInfo(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            switch (Mode)
            {
            case ResolvableValueMode.Value:
                return(RSInterop.RSTypeFor(Value, inLibrary.TypeAssembly));

            case ResolvableValueMode.Query:
                return(inLibrary.GetQuery(Query.Id)?.ReturnType);

            case ResolvableValueMode.Argument:
                return(inTriggerContext?.ParameterType?.Type);

            case ResolvableValueMode.Register:
                return(RSBuiltInTypes.Any);

            default:
                throw new InvalidOperationException("Unknown ResolvableValueMode " + Mode);
            }
        }
示例#22
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            switch (m_Mode)
            {
            case ResolvableValueMode.Value:
                return(m_Value.GetPreviewString(inTriggerContext, inLibrary));

            case ResolvableValueMode.Argument:
                return(string.Format("Arg({0})", inTriggerContext?.ParameterType?.Name ?? "TriggerArg"));

            case ResolvableValueMode.Query:
                return(m_Query.GetPreviewStringAsQuery(inTriggerContext, inLibrary));

            case ResolvableValueMode.Register:
                return(string.Format("Register({0})", m_Register));

            default:
                return("[No Value]");
            }
        }
示例#23
0
        static private RuleFlags GetRuleFlags(RSActionData inActionData, RSLibrary inLibrary)
        {
            RuleFlags flags = 0;

            if (inActionData.Enabled)
            {
                flags |= GetRuleFlags(inActionData.Action.Scope, inLibrary);
                flags |= GetRuleFlags(inLibrary.GetAction(inActionData.Action.Id));

                if (inActionData.Arguments != null)
                {
                    foreach (var arg in inActionData.Arguments)
                    {
                        flags |= GetRuleFlags(arg, inLibrary);
                    }
                }
            }

            return(flags);
        }
示例#24
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
            {
                var sb = psb.Builder;

                if (!Enabled)
                {
                    sb.Append("[Disabled] ");
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    sb.Append(Name).Append(" :: ");
                }

                sb.Append(TriggerId.ToString(inLibrary));

                return(sb.ToString());
            }
        }
示例#25
0
        static private RuleFlags GetRuleFlags(NestedValue inValueData, RSLibrary inLibrary)
        {
            RuleFlags flags = 0;

            switch (inValueData.Mode)
            {
            case ResolvableValueMode.Query:
            {
                flags |= GetRuleFlags(inValueData.Query.Scope, inLibrary);
                flags |= GetRuleFlags(inLibrary.GetQuery(inValueData.Query.Id));
                break;
            }

            case ResolvableValueMode.Register:
            {
                flags |= RuleFlags.UsesRegisters;
                break;
            }
            }

            return(flags);
        }
示例#26
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
            {
                var sb = psb.Builder;

                if (!Enabled)
                {
                    sb.Append("[Disabled] ");
                }

                sb.Append(Query.GetPreviewString(inTriggerContext, inLibrary));

                sb.Append(" ").Append(Operator.Symbol());

                if (Operator.IsBinary())
                {
                    sb.Append(" ").Append(Target.GetPreviewString(inTriggerContext, inLibrary));
                }

                return(sb.ToString());
            }
        }
示例#27
0
        /// <summary>
        /// Outputs all flags for the given rule.
        /// </summary>
        static public RuleFlags GetRuleFlags(RSRuleData inRuleData, RSLibrary inLibrary)
        {
            Assert.True(inRuleData != null, "Cannot read from null rule");

            RuleFlags flags = 0;

            if (inRuleData.Conditions != null)
            {
                foreach (var condition in inRuleData.Conditions)
                {
                    flags |= GetRuleFlags(condition, inLibrary);
                }
            }

            if (inRuleData.Actions != null)
            {
                foreach (var action in inRuleData.Actions)
                {
                    flags |= GetRuleFlags(action, inLibrary);
                }
            }

            return(flags);
        }
示例#28
0
        public string ToString(RSLibrary inLibrary)
        {
            string realName = inLibrary?.GetTrigger(m_Value)?.Name;

            return(realName ?? ToString());
        }
示例#29
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            switch (m_Type)
            {
            case InnerType.String:
                return(string.Format("\"{0}\"", m_StringValue));

            case InnerType.Color:
                return(ColorValue.ToString());

            case InnerType.Bool:
                return(BoolValue ? "true" : "false");

            case InnerType.Float:
                return(FloatValue.ToString());

            case InnerType.Int32:
                return(IntValue.ToString());

            case InnerType.Null:
                return("null");

            case InnerType.Vector2:
                return(AsVector2.ToString());

            case InnerType.Vector3:
                return(AsVector3.ToString());

            case InnerType.Vector4:
                return(AsVector4.ToString());

            case InnerType.EntityScope:
                return(EntityValue.GetPreviewString(inTriggerContext, inLibrary));

            case InnerType.GroupId:
                return(GroupIdValue.ToString(inLibrary));

            case InnerType.TriggerId:
                return(TriggerIdValue.ToString(inLibrary));

            case InnerType.Enum:
            {
                Type enumType = Type.GetType(m_StringValue);
                if (enumType == null)
                {
                    Debug.LogErrorFormat("Enum type {0} no longer exists", m_StringValue);
                    return(m_IntValue.ToString());
                }

                try
                {
                    return(Enum.ToObject(enumType, m_IntValue).ToString());
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    Debug.LogErrorFormat("Enum {0} cannot be represented as type {1}", m_IntValue, enumType);
                    return(m_IntValue.ToString());
                }
            }

            case InnerType.Invalid:
                return("INVALID");

            default:
                ThrowInvalidCastException(m_Type, typeof(string));
                return(null);
            }
        }
示例#30
0
        public string GetPreviewStringAsQuery(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            string queryId = inLibrary.GetQuery(m_Id)?.Name ?? "null";

            return(string.Format("{0}:{1}", m_Scope.GetPreviewString(inTriggerContext, inLibrary), queryId));
        }