Exemplo n.º 1
0
        /// <summary>
        /// Save function that repacks Rule into <see cref=" SerializedProperty"/> and updates Obj.
        /// </summary>
        private void SaveRule(bool inSet)
        {
            deserializedRule.MandatoryId      = rootNode.MandatoryID;
            deserializedRule.QualityId        = rootNode.QualityID;
            deserializedRule.RootGridPosition = rootNode.Rect.position;
            deserializedRule.MyDecisions      = ruleDecisions.ToArray();
            deserializedRule.MyAction         = rootNode.Action;
            if (actionNode != null)
            {
                deserializedRule.ActionGridPosition = actionNode.Rect.position;
            }
            if (inSet)
            {
                string setName   = SubjectRule.propertyPath.Remove(SubjectRule.propertyPath.IndexOf(".Array")).Replace("Profile.", "");
                int    ruleIndex = int.Parse(SubjectRule.propertyPath.Substring(SubjectRule.propertyPath.IndexOf("[") + 1).Replace("]", ""));
                RuleSystemUtil.SerializeRule(deserializedRule, SubjectRule, setName, ruleIndex);
            }

            SubjectRule.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws layout for selected rule tab.
        /// </summary>
        /// <param name="rule">Selected rule property. </param>
        /// <param name="data"><see cref="SessionData"/> refrence of an editorwindow.</param>
        /// <param name="OnOpenRule">Action-Event handle for opening <see cref="RuleWindow2"/>.</param>
        /// <param name="skin"><see cref="GUISkin"/> of area layout.</param>
        /// <returns></returns>
        private static SerializedProperty EditRuleData(SerializedProperty rule, ref SessionData data, Action <SerializedProperty> OnOpenRule, GUISkin skin)
        {
            string[] parentPath = rule.propertyPath.Remove(rule.propertyPath.IndexOf("Array") - 1).Split('.');
            int      index      = int.Parse(rule.propertyPath.Substring(rule.propertyPath.IndexOf('[') + 1).Replace("]", ""));

            GUILayout.Label("Rule Info:");
            GUILayout.Label("", skin.GetStyle("HorizontalDivider"));
            GUILayout.Space(10);
            GUILayout.BeginHorizontal(GUILayout.Height(20));
            GUILayout.Label("RuleName: ");
            rule.FindPropertyRelative("RuleName").stringValue = GUILayout.TextField(rule.FindPropertyRelative("RuleName").stringValue);
            GUILayout.EndHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Description:");
            rule.FindPropertyRelative("Description").stringValue = GUILayout.TextArea(rule.FindPropertyRelative("Description").stringValue, GUILayout.Height(60));
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.Label("Edit Options");
            GUILayout.Label("", skin.GetStyle("HorizontalDivider"));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Open Rule"))
            {
                //OpenRuleWIndow
                OnOpenRule.Invoke(rule);
            }
            if (GUI.changed)
            {
                data.RuleEditUnsaved = true;
            }
            if (data.RuleEditUnsaved)
            {
                if (GUILayout.Button("Save Rule"))
                {
                    rule.serializedObject.ApplyModifiedProperties();
                    data.RuleEditUnsaved = false;
                }
            }
            if (GUILayout.Button("Remove Rule"))
            {
                if (EditorUtility.DisplayDialog("Removing this Rule", "Are You shure you want to remove this rule? Changes can't be undone u know.", "Remove Rule"))
                {
                    SerializedProperty ruleArray = rule.serializedObject.FindProperty(parentPath[0]).FindPropertyRelative(parentPath[1]);
                    ruleArray.DeleteArrayElementAtIndex(index);
                    rule.serializedObject.ApplyModifiedProperties();
                    return(null);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            string absolute = Application.dataPath.Replace("Assets", "");

            if (GUILayout.Button("Save as Preset"))
            {
                // Save Rule
                rule.serializedObject.ApplyModifiedProperties();
                data.RuleEditUnsaved = false;
                // json

                var filePath = EditorUtility.SaveFilePanel("Save rule as preset", absolute + WindowUtils.RulePresetFolder, rule.displayName, "RulePreset");
                WindowUtils.RulePresetFolder = filePath.Replace(rule.displayName + ".json", "");
                string jsonRule = JsonUtility.ToJson(RuleSystemUtil.DeserializeRule(rule, parentPath[1], index));
                File.WriteAllText(filePath, jsonRule);
            }
            if (GUILayout.Button("Load from Preset"))
            {
                //fromjson
                var    filepath = EditorUtility.OpenFilePanel("Load rule from preset", absolute + WindowUtils.RulePresetFolder, "RulePreset");
                string jsonRule = File.ReadAllText(filepath);
                Rule   myRule   = JsonUtility.FromJson <Rule>(jsonRule);
                RuleSystemUtil.SerializeRule(myRule, rule, parentPath[1], index);
                rule.serializedObject.ApplyModifiedProperties();
                rule.serializedObject.Update();
            }
            GUILayout.EndHorizontal();
            return(rule);
        }