Exemplo n.º 1
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.º 2
0
        /// <summary>
        /// Renders editor for rule info. Does not include conditions or actions.
        /// </summary>
        static public void RuleData(UndoTarget inUndo, RSRuleData ioRule, RSRuleTableData ioTable, RSValidationFlags inFlags, RSValidationContext inContext)
        {
            string preview = ioRule.GetPreviewString(null, inContext.Library);

            GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle);

            EditorGUILayout.Space();

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

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

            RSTriggerId newTriggerId;

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

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

                TableUtils.UpdateUniqueRuleTriggers(ioTable);
            }

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

            EditorGUILayout.Space();

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

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

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

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

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

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

            EditorGUILayout.Space();

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

            if (newGroup != ioRule.RoutineGroup)
            {
                inUndo.MarkDirty("Changed Rule Group");
                ioRule.RoutineGroup = newGroup;
            }
        }
Exemplo n.º 3
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;
            }
            }
        }