public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        EditorGUILayout.Space();

        definitions = (ConfigurationDefinitions)EditorGUILayout.ObjectField("Definitions", definitions, typeof(ConfigurationDefinitions), true);

        if (definitions != null)
        {
            if (GUILayout.Button("Initialize"))
            {
                if (types == null)
                {
                    types = new List <GameObject>();
                }
                else
                {
                    types.ForEach(g => DestroyImmediate(g));
                    types.Clear();
                }

                //Indice tipo
                int i = 0;
                foreach (var t in definitions.GetAllTypes())
                {
                    GameObject currentType = new GameObject();
                    currentType.transform.SetParent(Target.transform);
                    currentType.name = t;
                    types.Add(currentType);

                    //Indice valore
                    int j = 0;
                    foreach (var v in definitions.GetAllValues(t))
                    {
                        GameObject currentValue = new GameObject();
                        currentValue.transform.SetParent(currentType.transform);
                        currentValue.name = v;

                        var configID = currentValue.AddComponent <ConfigurationID>();
                        configID.UpdateConfigs(definitions);

                        currentValue.AddComponent <Configuration>();

                        //k tipo del configValues
                        for (int k = 0; k < configID.configValues.Count; k++)
                        {
                            configID.configValues[k].ValueIndex = i == k ? j : ConfigValue.UNDEFINED_VALUE;
                        }
                        j++;
                    }
                    i++;
                }
            }
            Target.configurations = FindObjectsOfType <Configuration>()
                                    .Where(c => c.Id.GetType() == typeof(ConfigurationID)).ToList();
            EditorUtility.SetDirty(Target.gameObject);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Configurator definition and references controls.
    /// </summary>
    private void DefinitionInitControls()
    {
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        ShowAllDefinitions();

        if (definitions != null)
        {
            EditorGUILayout.LabelField("Update Configuration References Conditions");
            EditorGUI.indentLevel++;
            indexConfigReferences          = EditorGUILayout.Popup("Hierarchy", indexConfigReferences, new string[] { "In children", "Global" });
            sameDefinitionConfigReferences = EditorGUILayout.Toggle("Same definition", sameDefinitionConfigReferences);
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Initialize", EditorStyles.miniButtonLeft))
            {
                if (types == null)
                {
                    types = new List <GameObject>();
                }
                else
                {
                    types.ForEach(g => DestroyImmediate(g));
                    types.Clear();
                }

                Target.GetComponent <ConfigurationID>().definition = definitions;

                //Indice tipo
                int i = 0;
                foreach (var t in definitions.GetAllTypes())
                {
                    GameObject currentType = new GameObject();
                    currentType.transform.SetParent(Target.transform);
                    currentType.name = t;
                    types.Add(currentType);

                    //Indice valore
                    int j = 0;
                    foreach (var v in definitions.GetAllValues(t))
                    {
                        GameObject currentValue = new GameObject();
                        currentValue.transform.SetParent(currentType.transform);
                        currentValue.name = v;

                        var configID = currentValue.AddComponent <ConfigurationID>();
                        configID.UpdateConfigs(definitions);

                        currentValue.AddComponent <Configuration>();

                        //k tipo del configValues
                        for (int k = 0; k < configID.configValues.Count; k++)
                        {
                            configID.configValues[k].ValueIndex = i == k ? j : ConfigValue.UNDEFINED_VALUE;
                        }
                        j++;
                    }
                    i++;
                }

                Target.configurations = FindObjectsOfType <Configuration>()
                                        .Where(c => c.Id != null && c.Id.GetType() == typeof(ConfigurationID)).ToList();
            }

            if (GUILayout.Button("Update", EditorStyles.miniButtonRight))
            {
                UpdateConfigurationReferences(indexConfigReferences == 1, sameDefinitionConfigReferences);
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            EditorUtility.SetDirty(Target.gameObject);
        }
        EditorGUILayout.EndVertical();
    }