Beispiel #1
0
        /// <summary>
        /// Make this configuration complaint to <paramref name="definitions"/>.
        /// </summary>
        /// <param name="definitions"></param>
        public void UpdateConfigs(ConfigurationDefinitions definitions)
        {
            this.definition = definitions;
            if (definitions == null || definitions.definitions == null || definitions.definitions.Count() == 0)
            {
                //if no definition is available
                configValues.Clear();

                return;
            }

            //Rimozione configValues di troppo
            int diff = configValues.Count - definition.GetAllTypes().Count();

            if (diff > 0)
            {
                configValues.RemoveRange(definition.GetAllTypes().Count() - 1, diff);
            }

            //Aggiunta di nuovi configValue se necessario
            //Clamp dei ValueIndex dei configValue
            int i = 0;

            foreach (var type in definition.GetAllTypes())
            {
                if (i >= configValues.Count)
                {
                    configValues.Add(new ConfigValue());
                }

                configValues[i].typeIndex  = i;
                configValues[i].ValueIndex = Mathf.Clamp(configValues[i].ValueIndex, 0, definition.GetAllValues(i).Count());
                i++;
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            ShowAllDefinitions();
            ConfigurationDefinitions def = TargetConfig.definition;

            if (TargetConfig.definition == null)
            {
                EditorGUILayout.HelpBox("Definition is NULL", MessageType.Error);
                base.OnInspectorGUI();
                EditorGUI.EndChangeCheck();
                return;
            }

            //Rimuovi i superflui
            int diff = TargetConfig.configValues.Count() - def.GetAllTypes().Count();

            if (diff > 0)
            {
                TargetConfig.configValues.RemoveRange(def.GetAllTypes().Count(), diff);
            }

            int i = 0;

            foreach (var type in def.GetAllTypes())
            {
                //Aggiungi se necessario
                if (i >= TargetConfig.configValues.Count)
                {
                    TargetConfig.configValues.Add(new ConfigValue());
                }
                TargetConfig.configValues[i].typeIndex = i;

                //Aggiungi valore Undefined
                var values = def.GetAllValues(i).ToList();
                values.Insert(0, "UNDEFINED");

                TargetConfig.configValues[i].valueIndexForEditor = EditorGUILayout.Popup(type, TargetConfig.configValues[i].valueIndexForEditor, values.ToArray());
                i++;
            }

            serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                isValid = TargetConfig.CheckValidity();
            }

            if (!isValid)
            {
                EditorGUILayout.HelpBox(string.Format("Configuration violates restriction rule #{0}.", TargetConfig.GetFirstIndexRestrictionViolated()), MessageType.Error);
            }
        }
Beispiel #3
0
 private void Reset()
 {
     //Find the first ConfigurationDefinition in scene
     configValues = new List <ConfigValue>();
     definition   = FindObjectOfType <ConfigurationDefinitions>();
 }
 private void Reset()
 {
     //Find the first ConfigurationDefinition in scene
     configValues = new List <ConfigValue>();
     definition   = Resources.LoadAll <ConfigurationDefinitions>("").FirstOrDefault();
 }