Example #1
0
    protected virtual void Validate()
    {
        int accumulatedChildIndex = 0;
        var serializedFieldInfos  =
            SerializationUtility.GetSerializedFieldsOfType <ViewModelProperty>(viewModel.GetType());

        foreach (var fieldInfo in serializedFieldInfos)
        {
            string            displayName = UnityEditor.ObjectNames.NicifyVariableName(fieldInfo.Name);
            ViewModelProperty property    = fieldInfo.GetValue(viewModel) as ViewModelProperty;
            if (property == null)
            {
                GameObject propertyGO = GetOrCreatePropertyGameObject(displayName, fieldInfo.FieldType);
                property = propertyGO.GetComponent <ViewModelProperty>();
                fieldInfo.SetValue(viewModel, property);
            }
            if (property.gameObject != targetGameObject)
            {
                property.gameObject.name = displayName;
                property.transform.SetSiblingIndex(accumulatedChildIndex);
                accumulatedChildIndex += 1;
            }
        }
    }