Пример #1
0
        /// <summary>
        /// Load function that unpacks <see cref="Rule"/> from corresponding <see cref="SerializedProperty"/>.
        /// </summary>
        private void LoadRule(bool inSet)
        {
            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("]", ""));

                deserializedRule = RuleSystemUtil.DeserializeRule(SubjectRule, setName, ruleIndex);
            }
            else
            {
                deserializedRule = RuleSystemUtil.DeserializeRule(SubjectRule);
            }
            rootNode = RuleCreator.CreateRoot(deserializedRule.RootGridPosition, OnNodePortContact, OnUpdateRootRequest, OnRemoveAThread, deserializedRule.MandatoryId, deserializedRule.QualityId, deserializedRule.MyAction, NodeSkin);
            if (deserializedRule.MyAction != null)
            {
                actionNode = RuleCreator.CreateActionNode(deserializedRule.ActionGridPosition, OnNodePortContact, OnUpdateActionRequest, OnRemoveNode, OnRemoveAThread, deserializedRule.MyAction, NodeSkin);
            }
            foreach (Decision decision in deserializedRule.MyDecisions)
            {
                ruleDecisions.Add(decision);
                NodeShell rawNode = RuleCreator.CreateNewDecisionNode(decision.identifier, decision.Operator, OnUpdateRuleRequest, OnNodePortContact, OnRemoveNode, OnRemoveAThread, NodeSkin);
                rawNode.Container = new NodeShell.Data
                {
                    FloatValue = decision.FlatValue
                };
                rawNode.Inputs        = decision.inputID;
                rawNode.Rect.position = decision.GridPosition;
                rawNode.activated     = true;
                ruleNodes.Add(rawNode);
            }
        }
Пример #2
0
 private void OnEnable()
 {
     // catch refrences
     appliedSeachFilters = new EditorFilters();
     MyData = new SessionData();
     // Reload Profiles
     capturedControllerObj = RuleSystemUtil.CollectRuleSytemObjects();
 }
Пример #3
0
 private void Initialize(bool inSet)
 {
     // catching refrences
     myData = new SessionData();
     // Collect Statements
     capturedStatements = RuleSystemUtil.CollectDecisionsByType();
     // Collect Actions
     capturedActions = RuleSystemUtil.CollectActionsByType();
     // Load Rule
     LoadRule(inSet);
     LoadThreads();
     isInitialized = true;
 }
Пример #4
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();
        }
Пример #5
0
        private void OnGUI()
        {
            // Update Profiles
            UpdateCapturedObjs();
            // DrawOBJ w/ controllers
            var potentialOpenedProfile = LibraryLayoutUtil.DrawControllerLayout(capturedControllerObj, WindowUtils.ControlLayout, ref MyData, ref appliedSeachFilters, AdelicSkin);

            if (potentialOpenedProfile != null)
            {
                selectedControllerObj     = potentialOpenedProfile;
                MyData.selectedController = selectedControllerObj;
            }
            // If open Profile > DrawOpenProfile
            if (selectedControllerObj != null)
            {
                var potentialOpenedRule = LibraryLayoutUtil.DrawProfileLayout(selectedControllerObj, WindowUtils.ProfileLayout, ref MyData, AdelicSkin);
                if (potentialOpenedRule != null)
                {
                    selectedRuleObj     = potentialOpenedRule;
                    MyData.selectedRule = selectedRuleObj;
                }
                selectedRuleObj = LibraryLayoutUtil.DrawPropertyInfoLayout(selectedControllerObj, selectedRuleObj, WindowUtils.PropertyLayout, RuleWindow2.RequestRuleWindow, ref MyData, AdelicSkin);
            }
            else
            {
                GUILayout.BeginArea(WindowUtils.ProfileLayout);
                GUILayout.Label("No Profile Selected...");
                GUILayout.EndArea();
            }

            // Handle Events > open profile, Copy profile

            if (GUI.changed)
            {
                // Reload Profiles.
                capturedControllerObj = RuleSystemUtil.CollectRuleSytemObjects();
                // save Apply moddified Changes
                ApplyModificationCapturedObjs();
            }
        }
Пример #6
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);
        }