Exemplo n.º 1
0
        public void Save()
        {
            using (MemoryStream stream = new MemoryStream()) {
                using (BinaryWriter writer = new BinaryWriter(stream)) {
                    writer.Write(rules.Count);

                    for (int i = 0; i < rules.Count; i++)
                    {
                        DeterministicRule rule = rules[i];
                        writer.Write(rule.Name);
                        writer.Write(rule.StartValue);
                        if (string.IsNullOrEmpty(rule.Description))
                        {
                            writer.Write(String.Empty);
                        }
                        else
                        {
                            writer.Write(rule.Description);
                        }
                    }
                }

                serialized = stream.ToArray();
            }
        }
        public void ChangeRuleValue(string strKey, bool bNewValue)
        {
            Debug.Log($"Changed rule {strKey} to {bNewValue}");
            DeterministicRule rule = rulesAsset.GetRuleByName(strKey);

            rule.Value      = bNewValue;
            rule.DayEnabled = rulesAsset.nCurrentDay;
        }
        public void Start()
        {
            if (rulesAsset.LoadedFirstDay)
            {
                ExecuteEvent();
                return;
            }

            rulesAsset.SetLoadFirstDay();
            rulesAsset.Load();

            for (int i = 0; i < rulesAsset.rules.Count; i++)
            {
                DeterministicRule rule = rulesAsset.rules[i];
                rule.Value = rule.StartValue;
            }

            ExecuteEvent();
        }
Exemplo n.º 4
0
        public void Load()
        {
            if (serialized == null)
            {
                return;
            }

            bLoaded = true;
            using (MemoryStream stream = new MemoryStream(serialized)) {
                using (BinaryReader reader = new BinaryReader(stream)) {
                    int ruleCount = reader.ReadInt32();
                    rules = new List <DeterministicRule>(ruleCount);

                    for (int i = 0; i < ruleCount; i++)
                    {
                        DeterministicRule rule = new DeterministicRule();
                        rule.Name        = reader.ReadString();
                        rule.StartValue  = reader.ReadBoolean();
                        rule.Description = reader.ReadString();
                        rules.Add(rule);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            if (this.targets != null && this.targets.Length <= 1)
            {
                DeterminismRules det = (DeterminismRules)target;

                if (!det.bLoaded || det.rules == null)
                {
                    det.Load();
                    if (det.rules == null)
                    {
                        det.rules = new List <DeterministicRule>();
                    }
                }

                if (GUILayout.Button("Save"))
                {
                    det.Save();
                    EditorUtility.SetDirty(det);
                }

                if (GUILayout.Button("Load"))
                {
                    det.Load();
                }

                if (GUILayout.Button("Reset Day"))
                {
                    det.nCurrentDay = 1;
                }
                det.nCurrentDay = EditorGUILayout.IntField("Current Day", det.nCurrentDay);

                if (GUILayout.Button("Add Rule"))
                {
                    det.rules.Add(new DeterministicRule());
                }

                for (int i = 0; i < det.rules.Count; i++)
                {
                    DeterministicRule rule = det.rules[i];

                    if (string.IsNullOrEmpty(rule.Name))
                    {
                        rule.Name = $"Rule {(i + 1)}";
                    }

                    rule.IsEditorOpen = EditorGUILayout.Foldout(rule.IsEditorOpen, rule.Name);
                    if (rule.IsEditorOpen)
                    {
                        rule.Name        = EditorGUILayout.TextField("Key", rule.Name);
                        rule.Description = EditorGUILayout.TextField("Description", rule.Description);

                        rule.StartValue = GUILayout.Toggle(rule.StartValue, "Start Value");

                        if (GUILayout.Button("Delete"))
                        {
                            det.rules.RemoveAt(i--);
                        }
                    }
                }
            }
        }